diff --git a/app/forms/gpo_verify_form.rb b/app/forms/gpo_verify_form.rb index 9d573091aab..8e840a01e2c 100644 --- a/app/forms/gpo_verify_form.rb +++ b/app/forms/gpo_verify_form.rb @@ -85,7 +85,11 @@ def submit_attempts def validate_otp_not_expired return unless gpo_confirmation_code.present? && gpo_confirmation_code.expired? - errors.add :otp, :gpo_otp_expired, type: :gpo_otp_expired + if user_can_request_another_letter? + errors.add :otp, :gpo_otp_expired + else + errors.add :otp, :gpo_otp_expired_and_cannot_request_another + end end def validate_pending_profile @@ -117,4 +121,8 @@ def activate_profile pending_profile&.remove_gpo_deactivation_reason pending_profile&.activate end + + def user_can_request_another_letter? + !Idv::GpoMail.new(user).rate_limited? + end end diff --git a/config/locales/errors/en.yml b/config/locales/errors/en.yml index c7d5b29a2c4..51020683ed6 100644 --- a/config/locales/errors/en.yml +++ b/config/locales/errors/en.yml @@ -62,6 +62,7 @@ en: format_mismatch: Please match the requested format. gpo_otp_expired: Your verification code has expired. Please request another letter for a new code. + gpo_otp_expired_and_cannot_request_another: Your verification code has expired. improbable_phone: Invalid phone number. Please make sure you enter a valid phone number. inclusion: is not included in the list invalid_calling_area: Calls to that phone number are not supported. Please try diff --git a/config/locales/errors/es.yml b/config/locales/errors/es.yml index 22a745cb3fe..64f053a1fa6 100644 --- a/config/locales/errors/es.yml +++ b/config/locales/errors/es.yml @@ -66,6 +66,7 @@ es: format_mismatch: Por favor, use el formato solicitado. gpo_otp_expired: Tu código de verificación ha caducado. Vuelve a solicitar otra carta para recibir un nuevo código. + gpo_otp_expired_and_cannot_request_another: Tu código de verificación ha caducado. improbable_phone: Número de teléfono no válido. Asegúrate de introducir un número de teléfono válido. inclusion: No se incluye en la lista. diff --git a/config/locales/errors/fr.yml b/config/locales/errors/fr.yml index 2b6c23f2de7..aa6f5507321 100644 --- a/config/locales/errors/fr.yml +++ b/config/locales/errors/fr.yml @@ -73,6 +73,7 @@ fr: format_mismatch: Veuillez vous assurer de respecter le format requis. gpo_otp_expired: Votre code de vérification a expiré. Veuillez solliciter une autre lettre afin d’obtenir un nouveau code. + gpo_otp_expired_and_cannot_request_another: Votre code de vérification a expiré. improbable_phone: Numéro de téléphone non valide. Veillez à saisir un numéro de téléphone valide. inclusion: N’est pas inclus dans la liste diff --git a/config/locales/errors/zh.yml b/config/locales/errors/zh.yml index 54df99bc016..b84a6e707fc 100644 --- a/config/locales/errors/zh.yml +++ b/config/locales/errors/zh.yml @@ -47,6 +47,7 @@ zh: expired: 已过期,请要求一个新的。 format_mismatch: 请使用与要求一致的格式。 gpo_otp_expired: 你的验证码已过期。请要求另外一封信来得到新代码。 + gpo_otp_expired_and_cannot_request_another: 你的验证码已过期。 improbable_phone: 电话号码有误。请保证你输入的电话号码无误。 inclusion: 没有在清单中 invalid_calling_area: 不支持给那个号码打的电话。如果你有一个可接受短信(SMS)的电话,请尝试用短信。 diff --git a/spec/features/users/verify_profile_spec.rb b/spec/features/users/verify_profile_spec.rb index 2dd3240bff8..1b950c4c84d 100644 --- a/spec/features/users/verify_profile_spec.rb +++ b/spec/features/users/verify_profile_spec.rb @@ -42,7 +42,7 @@ fill_in t('idv.gpo.form.otp_label'), with: otp click_button t('idv.gpo.form.submit') - expect(page).to have_content t('errors.messages.gpo_otp_expired') + expect(page).to have_content t('errors.messages.gpo_otp_expired_and_cannot_request_another') expect(current_path).to eq idv_verify_by_mail_enter_code_path end diff --git a/spec/forms/gpo_verify_form_spec.rb b/spec/forms/gpo_verify_form_spec.rb index a012923a40b..771d059e97a 100644 --- a/spec/forms/gpo_verify_form_spec.rb +++ b/spec/forms/gpo_verify_form_spec.rb @@ -88,10 +88,13 @@ context 'when OTP is expired' do let(:expiration_days) { 10 } let(:code_sent_at) { (expiration_days + 1).days.ago } + let(:minimum_wait_before_another_usps_letter_in_hours) { 0 } before do allow(IdentityConfig.store).to receive(:usps_confirmation_max_days). and_return(expiration_days) + allow(IdentityConfig.store).to receive(:minimum_wait_before_another_usps_letter_in_hours). + and_return(minimum_wait_before_another_usps_letter_in_hours) end it 'is invalid' do @@ -99,6 +102,19 @@ expect(result.success?).to eq(false) expect(subject.errors[:otp]).to eq [t('errors.messages.gpo_otp_expired')] end + + context 'and the user cannot request another letter' do + before do + allow(subject).to receive(:user_can_request_another_letter?).and_return(false) + end + it 'is invalid and uses different messaging' do + result = subject.submit + expect(result.success?).to eq(false) + expect(subject.errors[:otp]).to eq [ + t('errors.messages.gpo_otp_expired_and_cannot_request_another'), + ] + end + end end end diff --git a/spec/support/idv_examples/verification_code_entry.rb b/spec/support/idv_examples/verification_code_entry.rb index a5316310296..2830aa78ced 100644 --- a/spec/support/idv_examples/verification_code_entry.rb +++ b/spec/support/idv_examples/verification_code_entry.rb @@ -36,7 +36,7 @@ click_button t('idv.gpo.form.submit') expect(current_path).to eq idv_verify_by_mail_enter_code_path - expect(page).to have_content t('errors.messages.gpo_otp_expired') + expect(page).to have_content t('errors.messages.gpo_otp_expired_and_cannot_request_another') user.reload