From 4535ce5b95851e36b28e9f569c95e6f4828e6c8c Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 10:56:55 -0400 Subject: [PATCH 1/8] Always stub ApplicationController#analytics --- spec/features/idv/doc_auth/verify_step_spec.rb | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index 06f90a92b7a..931037253d7 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -9,6 +9,7 @@ let(:fake_analytics) { FakeAnalytics.new } let(:user) { create(:user, :signed_up) } before do + allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) unless skip_step_completion sign_in_and_2fa_user(user) complete_doc_auth_steps_before_verify_step @@ -35,8 +36,6 @@ end it 'proceeds to the next page upon confirmation' do - allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) - click_idv_continue expect(page).to have_current_path(idv_phone_path) @@ -61,8 +60,6 @@ end it 'tracks when the user edits their address' do - allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) - click_button t('idv.buttons.change_address_label') fill_out_address_form_ok click_button t('forms.buttons.submit.update') # address form @@ -86,8 +83,6 @@ end it 'does not proceed to the next page if resolution fails' do - allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) - sign_in_and_2fa_user complete_doc_auth_steps_before_ssn_step fill_out_ssn_form_with_ssn_that_fails_resolution @@ -107,8 +102,6 @@ end it 'does not proceed to the next page if resolution raises an exception' do - allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) - sign_in_and_2fa_user complete_doc_auth_steps_before_ssn_step fill_out_ssn_form_with_ssn_that_raises_exception @@ -128,7 +121,6 @@ end it 'throttles resolution and continues when it expires' do - allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) sign_in_and_2fa_user complete_doc_auth_steps_before_ssn_step fill_out_ssn_form_with_ssn_that_fails_resolution @@ -225,9 +217,6 @@ sign_in_and_2fa_user complete_doc_auth_steps_before_verify_step - allow_any_instance_of(ApplicationController). - to receive(:analytics).and_return(fake_analytics) - allow(DocumentCaptureSession).to receive(:find_by). and_return(nil) @@ -276,8 +265,6 @@ it 'allows resubmitting form' do allow(DocumentCaptureSession).to receive(:find_by). and_return(nil) - allow_any_instance_of(ApplicationController). - to receive(:analytics).and_return(fake_analytics) click_idv_continue expect(page).to have_content(t('idv.failure.timeout')) From a250f4d25a545e9cd35e6793b3258ce5c5ed2658 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 10:59:45 -0400 Subject: [PATCH 2/8] Remove duplicate SSN toggle spec --- spec/features/idv/doc_auth/verify_step_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index 931037253d7..aa7b019c50d 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -230,19 +230,6 @@ end end - it 'can toggle viewing the ssn' do - expect(page).to have_text('9**-**-***4') - expect(page).not_to have_text(DocAuthHelper::GOOD_SSN) - - check t('forms.ssn.show') - expect(page).to have_text(DocAuthHelper::GOOD_SSN) - expect(page).not_to have_text('9**-**-***4') - - uncheck t('forms.ssn.show') - expect(page).to have_text('9**-**-***4') - expect(page).not_to have_text(DocAuthHelper::GOOD_SSN) - end - context 'resolution failure' do let(:skip_step_completion) { true } From 54ef2186dec839b07d2aed3ea4ae2df58ae4c991 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 11:00:30 -0400 Subject: [PATCH 3/8] Remove duplicate resolution failure spec --- spec/features/idv/doc_auth/verify_step_spec.rb | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index aa7b019c50d..8d6c1bce426 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -230,24 +230,6 @@ end end - context 'resolution failure' do - let(:skip_step_completion) { true } - - it 'does not proceed to the next page' do - sign_in_and_2fa_user - complete_doc_auth_steps_before_ssn_step - fill_out_ssn_form_with_ssn_that_fails_resolution - click_idv_continue - click_idv_continue - - expect(page).to have_current_path(idv_session_errors_warning_path) - - click_on t('idv.failure.button.warning') - - expect(page).to have_current_path(idv_doc_auth_verify_step) - end - end - context 'async timed out' do it 'allows resubmitting form' do allow(DocumentCaptureSession).to receive(:find_by). From 82933b93ec1eee19e5a7357a5982de14ed74d00f Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 11:15:42 -0400 Subject: [PATCH 4/8] Call AAMVA assertions consistently and on the correct user --- .../features/idv/doc_auth/verify_step_spec.rb | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index 8d6c1bce426..2fb749fd488 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -152,19 +152,21 @@ allow(IdentityConfig.store).to receive(:aamva_supported_jurisdictions).and_return( [Idp::Constants::MOCK_IDV_APPLICANT[:state_id_jurisdiction]], ) - - sign_in_and_2fa_user + expect_any_instance_of(Idv::Agent). + to receive(:proof_resolution). + with( + anything, + should_proof_state_id: true, + trace_id: anything, + ). + and_call_original + + user = create(:user, :signed_up) + sign_in_and_2fa_user(user) complete_doc_auth_steps_before_verify_step - agent = instance_double(Idv::Agent) - allow(Idv::Agent).to receive(:new).and_return(agent) - allow(agent).to receive(:proof_resolution).and_return( - success: true, errors: {}, context: { stages: [] }, - ) click_idv_continue - expect(agent).to have_received(:proof_resolution).with( - anything, should_proof_state_id: true, trace_id: anything - ) + expect(DocAuthLog.find_by(user_id: user.id).aamva).not_to be_nil end end @@ -174,19 +176,20 @@ IdentityConfig.store.aamva_supported_jurisdictions - [Idp::Constants::MOCK_IDV_APPLICANT[:state_id_jurisdiction]], ) - - sign_in_and_2fa_user + expect_any_instance_of(Idv::Agent). + to receive(:proof_resolution). + with( + anything, + should_proof_state_id: false, + trace_id: anything, + ). + and_call_original + + user = create(:user, :signed_up) + sign_in_and_2fa_user(user) complete_doc_auth_steps_before_verify_step - agent = instance_double(Idv::Agent) - allow(Idv::Agent).to receive(:new).and_return(agent) - allow(agent).to receive(:proof_resolution).and_return( - success: true, errors: {}, context: { stages: [] }, - ) click_idv_continue - expect(agent).to have_received(:proof_resolution).with( - anything, should_proof_state_id: false, trace_id: anything - ) expect(DocAuthLog.find_by(user_id: user.id).aamva).to be_nil end end @@ -195,20 +198,22 @@ it 'does not perform the state ID check' do allow(IdentityConfig.store).to receive(:aamva_sp_banlist_issuers). and_return('["urn:gov:gsa:openidconnect:sp:server"]') + expect_any_instance_of(Idv::Agent). + to receive(:proof_resolution). + with( + anything, + should_proof_state_id: false, + trace_id: anything, + ). + and_call_original visit_idp_from_sp_with_ial1(:oidc) - sign_in_and_2fa_user + user = create(:user, :signed_up) + sign_in_and_2fa_user(user) complete_doc_auth_steps_before_verify_step - agent = instance_double(Idv::Agent) - allow(Idv::Agent).to receive(:new).and_return(agent) - allow(agent).to receive(:proof_resolution).and_return( - success: true, errors: {}, context: { stages: [] }, - ) click_idv_continue - expect(agent).to have_received(:proof_resolution).with( - anything, should_proof_state_id: false, trace_id: anything - ) + expect(DocAuthLog.find_by(user_id: user.id).aamva).to be_nil end end From ad5e4c288f858321c628698e7911eccdd28aa4d3 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 11:16:14 -0400 Subject: [PATCH 5/8] Consolidate content specs --- spec/features/idv/doc_auth/verify_step_spec.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index 2fb749fd488..d1a43fb5fd0 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -16,21 +16,18 @@ end end - it 'is on the correct page' do + it 'displays the expected content' do expect(page).to have_current_path(idv_doc_auth_verify_step) expect(page).to have_content(t('headings.verify')) expect(page).to have_css( '.step-indicator__step--current', text: t('step_indicator.flows.idv.verify_info'), ) - end - it 'masks the ssn until toggled visible' do + # SSN is masked until revealed expect(page).to have_text('9**-**-***4') expect(page).not_to have_text(DocAuthHelper::GOOD_SSN) - check t('forms.ssn.show') - expect(page).not_to have_text('9**-**-***4') expect(page).to have_text(DocAuthHelper::GOOD_SSN) end From 37c1ff30896fe7f73470dec8b9df57e470f2f46a Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 11:17:29 -0400 Subject: [PATCH 6/8] Move setup behavior into test cases Avoid double-visiting, awkward "skip" exclusion which is too easy to forget --- spec/features/idv/doc_auth/verify_step_spec.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index d1a43fb5fd0..b9dc87f4a23 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -7,16 +7,14 @@ let(:skip_step_completion) { false } let(:max_attempts) { Throttle.max_attempts(:idv_resolution) } let(:fake_analytics) { FakeAnalytics.new } - let(:user) { create(:user, :signed_up) } before do allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics) - unless skip_step_completion - sign_in_and_2fa_user(user) - complete_doc_auth_steps_before_verify_step - end end it 'displays the expected content' do + sign_in_and_2fa_user + complete_doc_auth_steps_before_verify_step + expect(page).to have_current_path(idv_doc_auth_verify_step) expect(page).to have_content(t('headings.verify')) expect(page).to have_css( @@ -33,6 +31,8 @@ end it 'proceeds to the next page upon confirmation' do + sign_in_and_2fa_user + complete_doc_auth_steps_before_verify_step click_idv_continue expect(page).to have_current_path(idv_phone_path) @@ -48,6 +48,8 @@ end it 'proceeds to address page prepopulated with defaults if the user clicks change address' do + sign_in_and_2fa_user + complete_doc_auth_steps_before_verify_step click_button t('idv.buttons.change_address_label') expect(page).to have_current_path(idv_address_path) @@ -57,6 +59,9 @@ end it 'tracks when the user edits their address' do + sign_in_and_2fa_user + complete_doc_auth_steps_before_verify_step + click_button t('idv.buttons.change_address_label') fill_out_address_form_ok click_button t('forms.buttons.submit.update') # address form @@ -70,6 +75,9 @@ end it 'proceeds to the ssn page if the user clicks change ssn and allows user to go back' do + sign_in_and_2fa_user + complete_doc_auth_steps_before_verify_step + click_button t('idv.buttons.change_ssn_label') expect(page).to have_current_path(idv_doc_auth_ssn_step) From 22bce78360ce58570e01bc9278b8bb9b68763614 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 11:34:10 -0400 Subject: [PATCH 7/8] Add changelog changelog: Internal, Automated Testing, Improve automated testing performance From 5807a3a1f001d8404c100afa3709db304a5796af Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 7 Jul 2022 16:58:11 -0400 Subject: [PATCH 8/8] Add missing prep behavior --- spec/features/idv/doc_auth/verify_step_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/features/idv/doc_auth/verify_step_spec.rb b/spec/features/idv/doc_auth/verify_step_spec.rb index b9dc87f4a23..7e9cd01fdb9 100644 --- a/spec/features/idv/doc_auth/verify_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_step_spec.rb @@ -242,6 +242,9 @@ context 'async timed out' do it 'allows resubmitting form' do + sign_in_and_2fa_user + complete_doc_auth_steps_before_verify_step + allow(DocumentCaptureSession).to receive(:find_by). and_return(nil)