diff --git a/app/jobs/in_person/send_proofing_notification_job.rb b/app/jobs/in_person/send_proofing_notification_job.rb index d8d30952fc0..b5db32eadcf 100644 --- a/app/jobs/in_person/send_proofing_notification_job.rb +++ b/app/jobs/in_person/send_proofing_notification_job.rb @@ -53,6 +53,10 @@ def perform(enrollment_id) private + def formatter + Idv::InPerson::EnrollmentCodeFormatter + end + def log_job_completed(enrollment:) analytics(user: enrollment.user). idv_in_person_send_proofing_notification_job_completed( @@ -81,6 +85,7 @@ def notification_message(enrollment:) app_name: APP_NAME, proof_date: proof_date, contact_number: IdentityConfig.store.idv_contact_phone_number, + reference_string: formatter.format(enrollment.enrollment_code), ) end end diff --git a/config/locales/telephony/en.yml b/config/locales/telephony/en.yml index eb0b8cdd769..8f903b97cd4 100644 --- a/config/locales/telephony/en.yml +++ b/config/locales/telephony/en.yml @@ -15,7 +15,7 @@ en: code expires in %{expiration} minutes. confirmation_ipp_enrollment_result: sms: |- - %{app_name}: You visited the Post Office on %{proof_date}. Check email for your result. Not you? Report this right away: %{contact_number} + %{app_name}: You visited the Post Office on %{proof_date}. Check email for your result. Not you? Report this right away: %{contact_number}. Ref: %{reference_string} confirmation_otp: sms: |- %{app_name}: Your one-time code is %{code}. It expires in %{expiration} minutes. Don't share this code with anyone. diff --git a/config/locales/telephony/es.yml b/config/locales/telephony/es.yml index 8be4d787dad..14b60b64948 100644 --- a/config/locales/telephony/es.yml +++ b/config/locales/telephony/es.yml @@ -15,7 +15,7 @@ es: Este código expira en %{expiration} minutos. confirmation_ipp_enrollment_result: sms: |- - %{app_name}: Visitó la oficina de correos el %{proof_date}. Revise su correo electrónico para ver su resultado. ¿No fue usted? Informe ahora mismo: %{contact_number} + %{app_name}: Visitó la oficina de correos el %{proof_date}. Revise su correo electrónico. ¿No fue usted? Llame: %{contact_number}. Ref: %{reference_string} confirmation_otp: sms: |- %{app_name}: La contraseña es %{code}. Esta contraseña puede usarse una vez y se vence en %{expiration} minutos. No la comparta con nadie. diff --git a/config/locales/telephony/fr.yml b/config/locales/telephony/fr.yml index b1428880d30..5e936074fd4 100644 --- a/config/locales/telephony/fr.yml +++ b/config/locales/telephony/fr.yml @@ -16,7 +16,7 @@ fr: minutes. confirmation_ipp_enrollment_result: sms: |- - %{app_name}: Vous avez visité le bureau de poste le %{proof_date}. Vérifiez votre e-mail pour votre résultat. Ce n'est pas vous? Signalez-le immédiatement: %{contact_number} + %{app_name}: Vous avez visité le bureau de poste le %{proof_date}. Vérifiez votre e-mail. Ce n'est pas vous? Signalez-le: %{contact_number}. Réf: %{reference_string} confirmation_otp: sms: |- %{app_name}: Votre code à usage unique est %{code}. Il est valable pendant %{expiration} minutes. Vous ne devez pas partager ce code avec personne. diff --git a/spec/jobs/in_person/send_proofing_notification_job_spec.rb b/spec/jobs/in_person/send_proofing_notification_job_spec.rb index 48d98abda68..66e04ea14fd 100644 --- a/spec/jobs/in_person/send_proofing_notification_job_spec.rb +++ b/spec/jobs/in_person/send_proofing_notification_job_spec.rb @@ -12,6 +12,7 @@ :passed, :with_notification_phone_configuration, proofed_at: Time.zone.now - 3.days, + enrollment_code: '1234567890123456', ) end let(:failing_enrollment) do @@ -145,28 +146,76 @@ end end - it 'sends a message that respects the user email locale preference' do - allow(Telephony).to receive(:send_notification).and_return(sms_success_response) + context 'sends a message that respects the user email locale preference' do + let(:proofed_date) { Time.zone.now.strftime('%m/%d/%Y') } + let(:phone_number) { passed_enrollment.notification_phone_configuration.formatted_phone } + let(:contact_number) { '(844) 555-5555' } + let(:reference_string) { passed_enrollment.enrollment_code } + let(:formatted_string) { '1234-5678-9012-3456' } - passed_enrollment.user.update!(email_language: 'fr') - passed_enrollment.update!(proofed_at: Time.zone.now) - proofed_date = Time.zone.now.strftime('%m/%d/%Y') - phone_number = passed_enrollment.notification_phone_configuration.formatted_phone - contact_number = '(844) 555-5555' + before do + allow(Telephony).to receive(:send_notification).and_return(sms_success_response) + allow(Idv::InPerson::EnrollmentCodeFormatter).to receive(:format). + and_return(formatted_string) + end - expect(Telephony). - to( - receive(:send_notification). - with( - to: phone_number, - message: "Login.gov: Vous avez visité le bureau de poste le #{proofed_date}." \ - " Vérifiez votre e-mail pour votre résultat. Ce n'est pas vous?" \ - " Signalez-le immédiatement: #{contact_number}", - country_code: Phonelib.parse(phone_number).country, - ), - ) + it 'handles English language preference' do + passed_enrollment.user.update!(email_language: 'en') + passed_enrollment.update!(proofed_at: Time.zone.now) - job.perform(passed_enrollment.id) + expect(Telephony). + to( + receive(:send_notification). + with( + to: phone_number, + message: "Login.gov: You visited the Post Office on #{proofed_date}." \ + " Check email for your result." \ + " Not you? Report this right away: #{contact_number}." \ + " Ref: #{formatted_string}", + country_code: Phonelib.parse(phone_number).country, + ), + ) + + job.perform(passed_enrollment.id) + end + + it 'handles French language preference' do + passed_enrollment.user.update!(email_language: 'fr') + passed_enrollment.update!(proofed_at: Time.zone.now) + + expect(Telephony). + to( + receive(:send_notification). + with( + to: phone_number, + message: "Login.gov: Vous avez visité le bureau de poste le #{proofed_date}." \ + " Vérifiez votre e-mail. Ce n'est pas vous? Signalez-le: #{contact_number}." \ + " Réf: #{formatted_string}", + country_code: Phonelib.parse(phone_number).country, + ), + ) + + job.perform(passed_enrollment.id) + end + + it 'handles Spanish language preference' do + passed_enrollment.user.update!(email_language: 'es') + passed_enrollment.update!(proofed_at: Time.zone.now) + + expect(Telephony). + to( + receive(:send_notification). + with( + to: phone_number, + message: "Login.gov: Visitó la oficina de correos el #{proofed_date}." \ + " Revise su correo electrónico. ¿No fue usted? Llame: #{contact_number}." \ + " Ref: #{formatted_string}", + country_code: Phonelib.parse(phone_number).country, + ), + ) + + job.perform(passed_enrollment.id) + end end end