Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions app/forms/idv/api_image_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
61 changes: 12 additions & 49 deletions spec/controllers/idv/image_uploads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@

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,
Expand Down Expand Up @@ -458,8 +459,9 @@

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,
Expand Down Expand Up @@ -536,8 +538,9 @@

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,
Expand Down Expand Up @@ -614,8 +617,9 @@

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,
Expand Down Expand Up @@ -662,7 +666,6 @@

it 'tracks events' do
stub_analytics
stub_attempts_tracker

expect(@analytics).to receive(:track_event).with(
'IdV: doc auth image upload form submitted',
Expand Down Expand Up @@ -699,25 +702,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)
Expand All @@ -744,7 +728,6 @@

it 'tracks events' do
stub_analytics
stub_attempts_tracker

expect(@analytics).to receive(:track_event).with(
'IdV: doc auth image upload form submitted',
Expand Down Expand Up @@ -783,26 +766,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)
Expand Down
25 changes: 25 additions & 0 deletions spec/forms/idv/api_image_upload_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down