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
13 changes: 6 additions & 7 deletions app/jobs/get_usps_proofing_results_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ def handle_successful_status_update(enrollment, response)
proofed_at: proofed_at,
status_check_completed_at: Time.zone.now,
)
send_verified_email(enrollment.user, enrollment)
analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_email_initiated(
**email_analytics_attributes(enrollment),
email_type: 'Success',
)
send_verified_email(enrollment.user, enrollment)
end

def retro_fail_enrollment(enrollment, response)
def handle_unsupported_secondary_id(enrollment, response)
proofed_at = parse_usps_timestamp(response['transactionEndDateTime'])
enrollment_outcomes[:enrollments_failed] += 1
analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_enrollment_updated(
Expand All @@ -397,11 +397,11 @@ def retro_fail_enrollment(enrollment, response)
proofed_at: proofed_at,
status_check_completed_at: Time.zone.now,
)
send_failed_email(enrollment.user, enrollment)
analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_email_initiated(
**email_analytics_attributes(enrollment),
email_type: 'Failed',
email_type: 'Failed unsupported secondary ID',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my one thought with this is that there isn't really a separate version of the failed email for unsupported ids. We have a standard failure email (which is the one we're sending in this case) and a failure b/c of suspected fraud.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I was hesitant at first, but noticed that we log 'Failed unsupported ID type' in handle_unsupported_id_type above, and think this message would be useful for filtering when searching logs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that makes sense to me then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this event is established, it'd be good to first confirm there has been a discussion w/ product to check if they currently have dashboards or reports that would need to be adjusted for the updated value.

)
send_failed_email(enrollment.user, enrollment)
end

def process_enrollment_response(enrollment, response)
Expand All @@ -412,12 +412,11 @@ def process_enrollment_response(enrollment, response)

case response['status']
when IPP_STATUS_PASSED
if enrollment.capture_secondary_id_enabled && response['secondaryIdType']
retro_fail_enrollment(enrollment, response)
if enrollment.capture_secondary_id_enabled && response['secondaryIdType'].present?
handle_unsupported_secondary_id(enrollment, response)
elsif SUPPORTED_ID_TYPES.include?(response['primaryIdType'])
handle_successful_status_update(enrollment, response)
else
# Unsupported ID type
handle_unsupported_id_type(enrollment, response)
end
when IPP_STATUS_FAILED
Expand Down
61 changes: 34 additions & 27 deletions spec/jobs/get_usps_proofing_results_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'rails_helper'

RSpec.shared_examples 'enrollment_with_a_status_update' do |passed:, status:, response_json:|
RSpec.shared_examples 'enrollment_with_a_status_update' do |passed:,
email_type:,
enrollment_status:,
Comment on lines +4 to +5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added email_type as a new parameter and renamed status to enrollment_status

response_json:|

it 'logs a message with common attributes' do
freeze_time do
pending_enrollment.update(
Expand Down Expand Up @@ -43,17 +47,22 @@
end
end

context 'email_analytics_attributes' do
before(:each) do
stub_request_passed_proofing_results
end
Comment on lines -47 to -49
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this stub was causing only 'passed' emails to be sent, no matter what the test calling this shared example had configured


it 'logs message with email analytics attributes' do
freeze_time do
job.perform(Time.zone.now)
it 'logs message with email analytics attributes' do
freeze_time do
job.perform(Time.zone.now)
if email_type == 'deadline passed'
expect(job_analytics).to have_logged_event(
'GetUspsProofingResultsJob: deadline passed email initiated',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expired enrollments trigger sending of a completely different type of email; now that we're no longer always sending 'passed' emails, we can test specifically for them

enrollment_code: pending_enrollment.enrollment_code,
enrollment_id: pending_enrollment.id,
wait_until: anything,
service_provider: pending_enrollment.issuer,
timestamp: Time.zone.now,
)
else
expect(job_analytics).to have_logged_event(
'GetUspsProofingResultsJob: Success or failure email initiated',
email_type: anything,
email_type: email_type,
Comment on lines -56 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we're no longer always sending 'passed' emails, we can expect a specific email_type

enrollment_code: pending_enrollment.enrollment_code,
wait_until: anything,
service_provider: pending_enrollment.issuer,
Expand All @@ -75,7 +84,7 @@
expect(pending_enrollment.status_updated_at).to eq(Time.zone.now)
expect(pending_enrollment.status_check_attempted_at).to eq(Time.zone.now)
expect(pending_enrollment.status_check_completed_at).to eq(Time.zone.now)
expect(pending_enrollment.status).to eq(status)
expect(pending_enrollment.status).to eq(enrollment_status)
expect(pending_enrollment.profile.active).to eq(passed)
end
end
Expand Down Expand Up @@ -608,7 +617,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: true,
status: 'passed',
email_type: 'Success',
enrollment_status: 'passed',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_passed_proofing_results_response,
)
Expand Down Expand Up @@ -643,7 +653,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: false,
status: 'failed',
email_type: 'Failed',
enrollment_status: 'failed',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_failed_proofing_results_response,
)
Expand Down Expand Up @@ -678,7 +689,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: false,
status: 'failed',
email_type: 'Failed fraud suspected',
enrollment_status: 'failed',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_failed_suspected_fraud_proofing_results_response,
)
Expand Down Expand Up @@ -714,7 +726,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: false,
status: 'failed',
email_type: 'Failed unsupported ID type',
enrollment_status: 'failed',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_passed_proofing_unsupported_id_results_response,
)
Expand Down Expand Up @@ -750,7 +763,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: false,
status: 'expired',
email_type: 'deadline passed',
enrollment_status: 'expired',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_expired_proofing_results_response,
)
Expand Down Expand Up @@ -778,7 +792,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: false,
status: 'expired',
email_type: 'deadline passed',
enrollment_status: 'expired',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_unexpected_expired_proofing_results_response,
)
Expand Down Expand Up @@ -1048,7 +1063,8 @@
it_behaves_like(
'enrollment_with_a_status_update',
passed: false,
status: 'failed',
email_type: 'Failed unsupported secondary ID',
enrollment_status: 'failed',
response_json: UspsInPersonProofing::Mock::Fixtures.
request_passed_proofing_secondary_id_type_results_response,
)
Expand All @@ -1064,15 +1080,6 @@
reason: 'Provided secondary proof of address',
),
)

expect(job_analytics).to have_logged_event(
'GetUspsProofingResultsJob: Success or failure email initiated',
email_type: 'Failed',
enrollment_code: pending_enrollment.enrollment_code,
service_provider: anything,
timestamp: anything,
wait_until: nil,
)
Comment on lines -1068 to -1075
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this expectation was redundant with the 'enrollment_with_a_status_update' shared example above

end
end
end
Expand Down