From 2404341a2284aa1143e07fcfcb8d279586e6a761 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Tue, 10 Oct 2023 15:53:09 -0400 Subject: [PATCH] Update specs to initialize session as HashWithIndifferentAccess changelog: Internal, Automated Testing, Improve accuracy of session stubbing in tests --- .../idv/personal_key_controller_spec.rb | 8 ++++---- .../controllers/idv/review_controller_spec.rb | 3 --- spec/support/controller_helper.rb | 19 +++---------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/spec/controllers/idv/personal_key_controller_spec.rb b/spec/controllers/idv/personal_key_controller_spec.rb index a10b2ce458a..fef9bfa662f 100644 --- a/spec/controllers/idv/personal_key_controller_spec.rb +++ b/spec/controllers/idv/personal_key_controller_spec.rb @@ -205,7 +205,7 @@ def index expect(@analytics).to have_logged_event( 'IdV: personal key submitted', - address_verification_method: nil, + address_verification_method: 'phone', fraud_review_pending: false, fraud_rejection: false, in_person_verification_pending: false, @@ -249,7 +249,7 @@ def index expect(@analytics).to have_logged_event( 'IdV: personal key submitted', - address_verification_method: nil, + address_verification_method: 'phone', fraud_review_pending: false, fraud_rejection: false, deactivation_reason: nil, @@ -277,7 +277,7 @@ def index expect(@analytics).to have_logged_event( 'IdV: personal key submitted', - address_verification_method: nil, + address_verification_method: 'phone', fraud_review_pending: false, fraud_rejection: false, in_person_verification_pending: false, @@ -306,7 +306,7 @@ def index 'IdV: personal key submitted', fraud_review_pending: true, fraud_rejection: false, - address_verification_method: nil, + address_verification_method: 'phone', in_person_verification_pending: false, deactivation_reason: nil, proofing_components: nil, diff --git a/spec/controllers/idv/review_controller_spec.rb b/spec/controllers/idv/review_controller_spec.rb index b63de98cbdd..cc8521fbaf4 100644 --- a/spec/controllers/idv/review_controller_spec.rb +++ b/spec/controllers/idv/review_controller_spec.rb @@ -620,9 +620,6 @@ def show let(:applicant) do Idp::Constants::MOCK_IDV_APPLICANT_WITH_PHONE end - let(:stub_idv_session) do - stub_user_with_applicant_data(user, applicant) - end before do allow(IdentityConfig.store).to receive(:proofing_device_profiling). diff --git a/spec/support/controller_helper.rb b/spec/support/controller_helper.rb index e5cb0c4ad8b..19937fa3bb4 100644 --- a/spec/support/controller_helper.rb +++ b/spec/support/controller_helper.rb @@ -16,7 +16,8 @@ def sign_in_before_2fa(user = create(:user, :fully_registered)) def stub_sign_in(user = build(:user, password: VALID_PASSWORD)) allow(request.env['warden']).to receive(:authenticate!).and_return(user) allow(request.env['warden']).to receive(:session).and_return(user: {}) - allow(controller).to receive(:user_session).and_return(authn_at: Time.zone.now) + allow(controller).to receive(:user_session). + and_return({ authn_at: Time.zone.now }.with_indifferent_access) controller.user_session[:auth_method] ||= TwoFactorAuthenticatable::AuthMethod::SMS allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:confirm_two_factor_authenticated).and_return(true) @@ -54,7 +55,7 @@ def stub_idv_steps_before_verify_step(user) end def stub_verify_steps_one_and_two(user) - user_session = {} + user_session = ActiveSupport::HashWithIndifferentAccess.new stub_sign_in(user) idv_session = Idv::Session.new( user_session: user_session, current_user: user, @@ -73,20 +74,6 @@ def stub_verify_steps_one_and_two(user) allow(subject).to receive(:user_session).and_return(user_session) end - def stub_user_with_applicant_data(user, applicant) - user_session = {} - stub_sign_in(user) - idv_session = Idv::Session.new( - user_session: user_session, current_user: user, - service_provider: nil - ) - idv_session.applicant = applicant.with_indifferent_access - idv_session.resolution_successful = true - allow(subject).to receive(:confirm_idv_applicant_created).and_return(true) - allow(subject).to receive(:idv_session).and_return(idv_session) - allow(subject).to receive(:user_session).and_return(user_session) - end - def stub_user_with_pending_profile(user) allow(user).to receive(:pending_profile).and_return(pending_profile) allow(user).to receive(:gpo_verification_pending_profile?).