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: 8 additions & 5 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_in_person_verification_cancelled
# send SMS and email
send_enrollment_status_sms_notification(enrollment: enrollment)
send_failed_email(enrollment.user, enrollment)
Expand Down Expand Up @@ -271,7 +271,7 @@ def handle_expired_status_update(enrollment, response, response_message)
status: :expired,
status_check_completed_at: Time.zone.now,
)
enrollment.profile.deactivate_due_to_ipp_expiration
enrollment.profile.deactivate_due_to_in_person_verification_cancelled

if fraud_result_pending?(enrollment)
analytics(user: enrollment.user).idv_ipp_deactivated_for_never_visiting_post_office(
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_in_person_verification_cancelled
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_in_person_verification_cancelled
# 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_in_person_verification_cancelled
# send SMS and email
send_enrollment_status_sms_notification(enrollment: enrollment)
send_failed_email(enrollment.user, enrollment)
Expand Down
2 changes: 1 addition & 1 deletion app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def deactivate_due_to_gpo_expiration
)
end

def deactivate_due_to_ipp_expiration
def deactivate_due_to_in_person_verification_cancelled
update!(
active: false,
deactivation_reason: :verification_cancelled,
Expand Down
3 changes: 3 additions & 0 deletions spec/factories/in_person_enrollments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
enrollment_established_at { Time.zone.now }
status { :pending }
status_updated_at { Time.zone.now }
profile do
association(:profile, :in_person_verification_pending, user: user)
end
end

trait :expired do
Expand Down
142 changes: 98 additions & 44 deletions spec/jobs/get_usps_proofing_results_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@

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|
profile = enrollment.profile
profile.update(in_person_verification_pending_at: enrollment.created_at)
end
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 +818,16 @@
request_passed_proofing_unsupported_id_results_response,
)

it 'deactivates the associated 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 @@ -884,10 +888,11 @@
end

it 'deactivates the associated 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).not_to be_active
expect(pending_enrollment.profile.active).to be false
expect(pending_enrollment.profile.in_person_verification_pending_at).to be_nil
expect(pending_enrollment.profile.deactivation_reason).to eq('verification_cancelled')
end
Expand Down Expand Up @@ -989,6 +994,17 @@
),
)
end

it 'deactivates the associated profile' do
Comment thread
eileen-nava marked this conversation as resolved.
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 +1364,84 @@
),
)
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

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
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 'deactivates the associated 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))
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 +1460,16 @@
request_passed_proofing_secondary_id_type_results_response,
)

it 'deactivates the associated 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 +1481,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
4 changes: 2 additions & 2 deletions spec/models/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,10 @@
end
end

describe '#deactivate_due_to_ipp_expiration' do
describe '#deactivate_due_to_in_person_verification_cancelled' do
let(:profile) { create(:profile, :in_person_verification_pending) }
it 'updates the profile' do
profile.deactivate_due_to_ipp_expiration
profile.deactivate_due_to_in_person_verification_cancelled

expect(profile.active).to be false
expect(profile.deactivation_reason).to eq('verification_cancelled')
Expand Down
2 changes: 1 addition & 1 deletion spec/views/accounts/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
in_person_enrollment = user.in_person_enrollments.first
in_person_enrollment.update!(status: :expired, status_check_completed_at: Time.zone.now)
profile = user.profiles.first
profile.deactivate_due_to_ipp_expiration
profile.deactivate_due_to_in_person_verification_cancelled
end

it 'renders the idv partial' do
Expand Down