diff --git a/app/jobs/get_usps_proofing_results_job.rb b/app/jobs/get_usps_proofing_results_job.rb index 058faadb939..ed290f1ecee 100644 --- a/app/jobs/get_usps_proofing_results_job.rb +++ b/app/jobs/get_usps_proofing_results_job.rb @@ -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) @@ -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( @@ -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), @@ -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'] @@ -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) diff --git a/app/models/profile.rb b/app/models/profile.rb index 0ddb3b925bd..e26ab003fa3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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, diff --git a/spec/factories/in_person_enrollments.rb b/spec/factories/in_person_enrollments.rb index 70238b182c2..bfb36296ea4 100644 --- a/spec/factories/in_person_enrollments.rb +++ b/spec/factories/in_person_enrollments.rb @@ -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 diff --git a/spec/jobs/get_usps_proofing_results_job_spec.rb b/spec/jobs/get_usps_proofing_results_job_spec.rb index 77433303c03..454651054c6 100644 --- a/spec/jobs/get_usps_proofing_results_job_spec.rb +++ b/spec/jobs/get_usps_proofing_results_job_spec.rb @@ -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) @@ -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 @@ -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 @@ -989,6 +994,17 @@ ), ) 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.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 @@ -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 + 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 @@ -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, @@ -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( diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index b90c1bd4dbb..0f2058980aa 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -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') diff --git a/spec/views/accounts/show.html.erb_spec.rb b/spec/views/accounts/show.html.erb_spec.rb index d24efb61757..178e15b4240 100644 --- a/spec/views/accounts/show.html.erb_spec.rb +++ b/spec/views/accounts/show.html.erb_spec.rb @@ -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