Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 7 additions & 4 deletions app/jobs/get_usps_proofing_results_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def handle_unsupported_id_type(enrollment, response)
proofed_at: proofed_at,
status_check_completed_at: Time.zone.now,
)

enrollment.profile.deactivate_due_to_ipp_expiration
Comment thread
eileen-nava marked this conversation as resolved.
Outdated
# send SMS and email
send_enrollment_status_sms_notification(enrollment: enrollment)
send_failed_email(enrollment.user, enrollment)
Expand Down Expand Up @@ -325,8 +325,10 @@ def handle_fraud_review_pending(enrollment)
end

def handle_unexpected_response(enrollment, response_message, reason:, cancel: true)
enrollment.cancelled! if cancel

if cancel
enrollment.cancelled!
enrollment.profile.deactivate_due_to_ipp_expiration
Comment thread
eileen-nava marked this conversation as resolved.
Outdated
end
analytics(user: enrollment.user).
idv_in_person_usps_proofing_results_job_unexpected_response(
**enrollment_analytics_attributes(enrollment, complete: cancel),
Expand All @@ -352,7 +354,7 @@ def handle_failed_status(enrollment, response)
proofed_at: proofed_at,
status_check_completed_at: Time.zone.now,
)

enrollment.profile.deactivate_due_to_ipp_expiration
Comment thread
eileen-nava marked this conversation as resolved.
Outdated
# send SMS and email
send_enrollment_status_sms_notification(enrollment: enrollment)
if response['fraudSuspected']
Expand Down Expand Up @@ -442,6 +444,7 @@ def handle_unsupported_secondary_id(enrollment, response)
proofed_at: proofed_at,
status_check_completed_at: Time.zone.now,
)
enrollment.profile.deactivate_due_to_ipp_expiration
Comment thread
eileen-nava marked this conversation as resolved.
Outdated
# send SMS and email
send_enrollment_status_sms_notification(enrollment: enrollment)
send_failed_email(enrollment.user, enrollment)
Expand Down
143 changes: 106 additions & 37 deletions spec/jobs/get_usps_proofing_results_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@
profile = enrollment.profile
profile.update(in_person_verification_pending_at: enrollment.created_at)
end
pending_enrollment.reload

allow(InPersonEnrollment).to receive(:needs_usps_status_check).
and_return(enrollment_records)
allow(IdentityConfig.store).to receive(:in_person_proofing_enabled).and_return(true)
Expand Down Expand Up @@ -824,6 +826,16 @@
request_passed_proofing_unsupported_id_results_response,
)

it 'updates the profile' do
expect(pending_enrollment.profile.in_person_verification_pending_at).not_to be_nil
job.perform Time.zone.now
pending_enrollment.reload

expect(pending_enrollment.profile.in_person_verification_pending_at).to be_nil
expect(pending_enrollment.profile.active).to be false
expect(pending_enrollment.profile.deactivation_reason).to eq('verification_cancelled')
end

it 'logs a message about the unsupported ID' do
expected_wait_until = nil
freeze_time do
Expand Down Expand Up @@ -989,6 +1001,17 @@
),
)
end

it 'updates the profile' do
expect(pending_enrollment.profile.in_person_verification_pending_at).not_to be_nil
job.perform(Time.zone.now)
pending_enrollment.reload

expect(pending_enrollment.profile.in_person_verification_pending_at).to be_nil
expect(pending_enrollment.profile.active).to be false
expect(pending_enrollment.profile.deactivation_reason).
to eq('verification_cancelled')
end
end

context 'when a unique id is invalid' do
Expand Down Expand Up @@ -1348,57 +1371,92 @@
),
)
end
end

context 'when the enrollment has failed' do
before do
stub_request_failed_proofing_results
end
context 'when the enrollment has failed' do
Comment thread
gina-yamada marked this conversation as resolved.
before do
stub_request_failed_proofing_results
end

it 'sends proofing failed email on response with failed status' do
user = pending_enrollment.user

freeze_time do
expect do
job.perform(Time.zone.now)
end.to have_enqueued_mail(UserMailer, :in_person_failed).with(
params: { user: user, email_address: user.email_addresses.first },
args: [{ enrollment: pending_enrollment }],
)
expect(job_analytics).to have_logged_event(
'GetUspsProofingResultsJob: Success or failure email initiated',
hash_including(
email_type: 'Failed',
job_name: 'GetUspsProofingResultsJob',
),
)
end
it 'sends proofing failed email on response with failed status' do
user = pending_enrollment.user

freeze_time do
expect do
job.perform(Time.zone.now)
end.to have_enqueued_mail(UserMailer, :in_person_failed).with(
params: { user: user, email_address: user.email_addresses.first },
args: [{ enrollment: pending_enrollment }],
)
expect(job_analytics).to have_logged_event(
'GetUspsProofingResultsJob: Success or failure email initiated',
hash_including(
email_type: 'Failed',
job_name: 'GetUspsProofingResultsJob',
),
)
end
end
end

it 'deactivates and sets fraud related fields of an expired enrollment' do
stub_request_expired_id_ipp_proofing_results
it 'updates the profile' do
expect(pending_enrollment.profile.in_person_verification_pending_at).not_to be_nil

job.perform(Time.zone.now)
job.perform(Time.zone.now)
pending_enrollment.reload
expect(pending_enrollment.profile.in_person_verification_pending_at).to be_nil
expect(pending_enrollment.profile.active).to be false
expect(pending_enrollment.profile.deactivation_reason).
to eq('verification_cancelled')
end

profile = pending_enrollment.reload.profile
expect(profile).not_to be_active
expect(profile.fraud_review_pending_at).to be_nil
expect(profile.fraud_rejection_at).not_to be_nil
expect(job_analytics).to have_logged_event(
:idv_ipp_deactivated_for_never_visiting_post_office,
)
it 'deactivates and sets fraud related fields of an expired enrollment' do
stub_request_expired_id_ipp_proofing_results

job.perform(Time.zone.now)

profile = pending_enrollment.reload.profile
expect(profile).not_to be_active
expect(profile.fraud_review_pending_at).to be_nil
expect(profile.fraud_rejection_at).not_to be_nil
expect(job_analytics).to have_logged_event(
:idv_ipp_deactivated_for_never_visiting_post_office,
)
end
end
end
end
end

describe 'Proofed with secondary id' do
let(:pending_enrollment) do
create(
:in_person_enrollment, :pending
)
let!(:pending_enrollments) do
['BALTIMORE', 'FRIENDSHIP', 'WASHINGTON', 'ARLINGTON', 'DEANWOOD'].map do |name|
create(
:in_person_enrollment,
:pending,
:with_notification_phone_configuration,
issuer: 'http://localhost:3000',
selected_location_details: { name: name },
sponsor_id: usps_ipp_sponsor_id,
)
end
end
let(:pending_enrollment) { pending_enrollments.first }

before do
enrollment_records = InPersonEnrollment.where(id: pending_enrollments.map(&:id))
# Below sets in_person_verification_pending_at
# on the profile associated with each pending enrollment
enrollment_records.each do |enrollment|

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to update the :in_person_enrollment :pending factory trait and set the profile in_person_verification_pending_at timestamp in there, maybe similar to what Andrew did here in the users factory?

I know we have a ticket to clean up the in_person_enrollments factory and am okay with also doing the suggested work while working on that ticket.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added this to the in_person_enrollment factory. see commit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding that, @shanechesnutt-ft!

profile = enrollment.profile
profile.update(in_person_verification_pending_at: enrollment.created_at)
end
pending_enrollment.reload
# binding.pry
Comment thread
eileen-nava marked this conversation as resolved.
Outdated
allow(InPersonEnrollment).to receive(:needs_usps_status_check).
and_return(enrollment_records)
allow(IdentityConfig.store).to receive(:in_person_proofing_enabled).and_return(true)
end

before do
allow(IdentityConfig.store).to receive(:in_person_proofing_enabled).and_return(true)
end
Expand All @@ -1417,6 +1475,16 @@
request_passed_proofing_secondary_id_type_results_response,
)

it 'updates the profile' do
expect(pending_enrollment.profile.in_person_verification_pending_at).not_to be_nil
job.perform(Time.zone.now)
pending_enrollment.reload

expect(pending_enrollment.profile.in_person_verification_pending_at).to be_nil
expect(pending_enrollment.profile.active).to be false
expect(pending_enrollment.profile.deactivation_reason).to eq('verification_cancelled')
end

it 'logs a message about enrollment with secondary ID' do
allow(IdentityConfig.store).to receive(
:in_person_send_proofing_notifications_enabled,
Expand All @@ -1428,6 +1496,7 @@
end.to have_enqueued_job(InPerson::SendProofingNotificationJob).
with(pending_enrollment.id).at(1.hour.from_now).on_queue(:intentionally_delayed)
end

expect(pending_enrollment.proofed_at).to eq(transaction_end_date_time)
expect(pending_enrollment.profile.active).to eq(false)
expect(job_analytics).to have_logged_event(
Expand Down