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
10 changes: 9 additions & 1 deletion app/forms/gpo_verify_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions config/locales/errors/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/errors/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions config/locales/errors/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/locales/errors/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)的电话,请尝试用短信。
Expand Down
2 changes: 1 addition & 1 deletion spec/features/users/verify_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions spec/forms/gpo_verify_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,33 @@
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
result = subject.submit
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

Expand Down
2 changes: 1 addition & 1 deletion spec/support/idv_examples/verification_code_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down