From 6dfc304b855c7291077da0644c03cd93fe538ef0 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Mon, 23 Jan 2023 13:20:19 -0500 Subject: [PATCH 1/3] corrected the form response used by doc_auth_submitted event. changelog: Internal, Attempts API, Event bugfix --- app/forms/idv/api_image_upload_form.rb | 36 +++++++++++--------- spec/forms/idv/api_image_upload_form_spec.rb | 25 ++++++++++++++ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/app/forms/idv/api_image_upload_form.rb b/app/forms/idv/api_image_upload_form.rb index 1393d050399..26165791b88 100644 --- a/app/forms/idv/api_image_upload_form.rb +++ b/app/forms/idv/api_image_upload_form.rb @@ -97,6 +97,25 @@ def validate_pii_from_doc(client_response) analytics.idv_doc_auth_submitted_pii_validation(**response.to_h) + pii_from_doc = response.pii_from_doc || {} + stored_image_result = store_encrypted_images_if_required + + irs_attempts_api_tracker.idv_document_upload_submitted( + success: response.success?, + document_state: pii_from_doc[:state], + document_number: pii_from_doc[:state_id_number], + document_issued: pii_from_doc[:state_id_issued], + document_expiration: pii_from_doc[:state_id_expiration], + document_front_image_filename: stored_image_result&.front_filename, + document_back_image_filename: stored_image_result&.back_filename, + document_image_encryption_key: stored_image_result&.encryption_key, + first_name: pii_from_doc[:first_name], + last_name: pii_from_doc[:last_name], + date_of_birth: pii_from_doc[:dob], + address: pii_from_doc[:address1], + failure_reason: response.errors&.except(:hints)&.presence, + ) + store_pii(client_response) if client_response.success? && response.success? response @@ -209,23 +228,6 @@ def update_analytics(client_response) flow_path: params[:flow_path], ).merge(acuant_sdk_upgrade_ab_test_data), ) - pii_from_doc = client_response.pii_from_doc || {} - stored_image_result = store_encrypted_images_if_required - irs_attempts_api_tracker.idv_document_upload_submitted( - success: client_response.success?, - document_state: pii_from_doc[:state], - document_number: pii_from_doc[:state_id_number], - document_issued: pii_from_doc[:state_id_issued], - document_expiration: pii_from_doc[:state_id_expiration], - document_front_image_filename: stored_image_result&.front_filename, - document_back_image_filename: stored_image_result&.back_filename, - document_image_encryption_key: stored_image_result&.encryption_key, - first_name: pii_from_doc[:first_name], - last_name: pii_from_doc[:last_name], - date_of_birth: pii_from_doc[:dob], - address: pii_from_doc[:address1], - failure_reason: client_response.errors&.except(:hints)&.presence, - ) end def store_encrypted_images_if_required diff --git a/spec/forms/idv/api_image_upload_form_spec.rb b/spec/forms/idv/api_image_upload_form_spec.rb index 00e17b46ac6..52120847048 100644 --- a/spec/forms/idv/api_image_upload_form_spec.rb +++ b/spec/forms/idv/api_image_upload_form_spec.rb @@ -79,6 +79,24 @@ describe '#submit' do context 'with a valid form' do it 'logs analytics' do + expect(irs_attempts_api_tracker).to receive(:idv_document_upload_submitted).with( + { + address: '1 FAKE RD', + date_of_birth: '1938-10-06', + document_back_image_filename: nil, + document_expiration: '2099-12-31', + document_front_image_filename: nil, + document_image_encryption_key: nil, + document_issued: '2019-12-31', + document_number: '1111111111111', + document_state: 'MT', + failure_reason: nil, + first_name: 'FAKEY', + last_name: 'MCFAKERSON', + success: true, + }, + ) + form.submit expect(fake_analytics).to have_logged_event( @@ -244,6 +262,13 @@ end it 'includes doc_pii errors' do + expect(irs_attempts_api_tracker).to receive(:idv_document_upload_submitted).with( + hash_including( + { + success: false, + }, + ), + ) response = form.submit expect(response.errors[:doc_pii]).to eq('bad') end From 3c1a8201971a1e90be2478f3800bf93fd3cbcb83 Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Mon, 23 Jan 2023 15:06:42 -0500 Subject: [PATCH 2/3] updated specs to reflect function being moved. --- .../idv/image_uploads_controller_spec.rb | 57 +++---------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/spec/controllers/idv/image_uploads_controller_spec.rb b/spec/controllers/idv/image_uploads_controller_spec.rb index 0c2c39f360b..055d40eae0f 100644 --- a/spec/controllers/idv/image_uploads_controller_spec.rb +++ b/spec/controllers/idv/image_uploads_controller_spec.rb @@ -380,8 +380,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, - success: true, - failure_reason: nil, + success: false, + failure_reason: {pii: ["We couldn’t read the full name on your ID. Try taking new pictures."]}, document_state: 'ND', document_number: nil, document_issued: nil, @@ -458,8 +458,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, - success: true, - failure_reason: nil, + success: false, + failure_reason: {pii: ["We couldn’t read the full name on your ID. Try taking new pictures."]}, document_state: 'ND', document_number: nil, document_issued: nil, @@ -536,8 +536,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, - success: true, - failure_reason: nil, + success: false, + failure_reason: {pii: ["Try taking new pictures."]}, document_state: 'Maryland', document_number: nil, document_issued: nil, @@ -614,8 +614,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, - success: true, - failure_reason: nil, + success: false, + failure_reason: {pii: ["We couldn’t read the birth date on your ID. Try taking new pictures."]}, document_back_image_filename: nil, document_front_image_filename: nil, document_image_encryption_key: nil, @@ -662,7 +662,6 @@ it 'tracks events' do stub_analytics - stub_attempts_tracker expect(@analytics).to receive(:track_event).with( 'IdV: doc auth image upload form submitted', @@ -699,25 +698,6 @@ flow_path: 'standard', ) - expect(@irs_attempts_api_tracker).to receive(:track_event).with( - :idv_document_upload_submitted, - success: false, - failure_reason: { - front: [I18n.t('doc_auth.errors.general.multiple_front_id_failures')], - }, - document_back_image_filename: nil, - document_front_image_filename: nil, - document_image_encryption_key: nil, - document_state: nil, - document_number: nil, - document_issued: nil, - document_expiration: nil, - first_name: nil, - last_name: nil, - date_of_birth: nil, - address: nil, - ) - action expect_funnel_update_counts(user, 1) @@ -744,7 +724,6 @@ it 'tracks events' do stub_analytics - stub_attempts_tracker expect(@analytics).to receive(:track_event).with( 'IdV: doc auth image upload form submitted', @@ -783,26 +762,6 @@ flow_path: 'standard', ) - expect(@irs_attempts_api_tracker).to receive(:track_event).with( - :idv_document_upload_submitted, - success: false, - failure_reason: { - general: [I18n.t('doc_auth.errors.alerts.barcode_content_check')], - back: [I18n.t('doc_auth.errors.general.fallback_field_level')], - }, - document_back_image_filename: nil, - document_front_image_filename: nil, - document_image_encryption_key: nil, - document_state: nil, - document_number: nil, - document_issued: nil, - document_expiration: nil, - first_name: nil, - last_name: nil, - date_of_birth: nil, - address: nil, - ) - action expect_funnel_update_counts(user, 1) From 12b44d5791c5422ce576f5b8cce65dfb64b19abb Mon Sep 17 00:00:00 2001 From: Rwolfe-Nava Date: Mon, 23 Jan 2023 15:17:01 -0500 Subject: [PATCH 3/3] linter fixes --- .../controllers/idv/image_uploads_controller_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/controllers/idv/image_uploads_controller_spec.rb b/spec/controllers/idv/image_uploads_controller_spec.rb index 055d40eae0f..56946a2834c 100644 --- a/spec/controllers/idv/image_uploads_controller_spec.rb +++ b/spec/controllers/idv/image_uploads_controller_spec.rb @@ -381,7 +381,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, success: false, - failure_reason: {pii: ["We couldn’t read the full name on your ID. Try taking new pictures."]}, + failure_reason: { pii: + ['We couldn’t read the full name on your ID. Try taking new pictures.'] }, document_state: 'ND', document_number: nil, document_issued: nil, @@ -459,7 +460,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, success: false, - failure_reason: {pii: ["We couldn’t read the full name on your ID. Try taking new pictures."]}, + failure_reason: { pii: + ['We couldn’t read the full name on your ID. Try taking new pictures.'] }, document_state: 'ND', document_number: nil, document_issued: nil, @@ -537,7 +539,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, success: false, - failure_reason: {pii: ["Try taking new pictures."]}, + failure_reason: { pii: + ['Try taking new pictures.'] }, document_state: 'Maryland', document_number: nil, document_issued: nil, @@ -615,7 +618,8 @@ expect(@irs_attempts_api_tracker).to receive(:track_event).with( :idv_document_upload_submitted, success: false, - failure_reason: {pii: ["We couldn’t read the birth date on your ID. Try taking new pictures."]}, + failure_reason: { pii: + ['We couldn’t read the birth date on your ID. Try taking new pictures.'] }, document_back_image_filename: nil, document_front_image_filename: nil, document_image_encryption_key: nil,