Skip to content

Commit

Permalink
feature spec for DfE Sign In
Browse files Browse the repository at this point in the history
  • Loading branch information
alkesh committed Nov 20, 2024
1 parent cd7bb53 commit 16c5f7c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions spec/features/journeys/sad_paths/dfe_sign_in_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require "rails_helper"

RSpec.feature "DfE sign in", type: :feature do
include Helpers::JourneyAssertionHelper

let(:user) { User.find_by(email: "user@example.com") }

context "when there is an existing user with no DfE Identity UID" do
include_context "Stub Get An Identity Omniauth Responses"

before { create(:user, email: "user@example.com", full_name: "previous name", provider: nil, uid: nil) }

scenario "the user should be updated with DfE Identity attributes" do
navigate_to_page(path: "/", submit_form: false, axe_check: false) do
page.click_button("Start now")
end

expect_page_to_have(path: "/registration/course-start-date", submit_form: true)
expect(user.uid).to be_present
expect(user.provider).to eq "tra_openid_connect"
expect(user.full_name).to eq "John Doe"
end
end

context "when there is another account that matches the DfE Identity email but it doesn't have a DfE Identity UID" do
include_context "Stub Get An Identity Omniauth Responses" do
let(:user_email) { "user@example.com" }
let(:user_uid) { other_account_with_dfe_id.uid }
end

let!(:user_without_dfe_id) do
create(:user, email: "user@example.com", full_name: "previous name", provider: nil, uid: nil)
end
let!(:other_account_with_dfe_id) { create(:user, email: "old@example.com", provider: "tra_openid_connect", uid: SecureRandom.uuid, trn: user_without_dfe_id.trn) }

scenario "starting the journey" do
navigate_to_page(path: "/", submit_form: false, axe_check: false) do
page.click_button("Start now")
end

expect(page).to have_current_path("/registration/start") # current erroneous behaviour

# temporary fix - remove DfE Identity UID from new account, so old account is used
other_account_with_dfe_id.update!(uid: nil, provider: nil)

navigate_to_page(path: "/", submit_form: false, axe_check: false) do
page.click_button("Start now")
end
expect_page_to_have(path: "/registration/course-start-date", submit_form: true)
expect(user_without_dfe_id.reload.uid).to be_present
expect(user_without_dfe_id.provider).to eq "tra_openid_connect"
expect(user_without_dfe_id.full_name).to eq "John Doe"
end
end
end

0 comments on commit 16c5f7c

Please sign in to comment.