diff --git a/app/controllers/concerns/idv_failure_concern.rb b/app/controllers/concerns/idv_failure_concern.rb index f6cd3ff629c..9956107d8f3 100644 --- a/app/controllers/concerns/idv_failure_concern.rb +++ b/app/controllers/concerns/idv_failure_concern.rb @@ -6,7 +6,7 @@ def render_failure @view_model = view_model(error: 'fail') flash_message(type: :error) elsif form_valid_but_vendor_validation_failed? - @view_model = view_model(error: step.vendor_validation_timed_out? ? 'timeout' : 'warning') + @view_model = view_model(error: 'warning', timed_out: step.vendor_validation_timed_out?) flash_message(type: :warning) else @view_model = view_model @@ -20,4 +20,13 @@ def form_valid_but_vendor_validation_failed? def flash_message(type:) flash.now[type.to_sym] = @view_model.flash_message end + + def view_model(error: nil, timed_out: nil) + view_model_class.new( + error: error, + remaining_attempts: remaining_step_attempts, + idv_form: idv_form, + timed_out: timed_out + ) + end end diff --git a/app/controllers/verify/finance_controller.rb b/app/controllers/verify/finance_controller.rb index 28ff568a3d5..2f4110552e9 100644 --- a/app/controllers/verify/finance_controller.rb +++ b/app/controllers/verify/finance_controller.rb @@ -56,12 +56,8 @@ def confirm_step_needed redirect_to verify_address_path if idv_session.financials_confirmation == true end - def view_model(error: nil) - Verify::FinancialsNew.new( - error: error, - remaining_attempts: remaining_step_attempts, - idv_form: idv_form - ) + def view_model_class + Verify::FinancialsNew end def idv_form diff --git a/app/controllers/verify/phone_controller.rb b/app/controllers/verify/phone_controller.rb index f659d12a686..888b08ac2b9 100644 --- a/app/controllers/verify/phone_controller.rb +++ b/app/controllers/verify/phone_controller.rb @@ -60,12 +60,8 @@ def step ) end - def view_model(error: nil) - Verify::PhoneNew.new( - error: error, - remaining_attempts: remaining_step_attempts, - idv_form: idv_form - ) + def view_model_class + Verify::PhoneNew end def step_params diff --git a/app/controllers/verify/sessions_controller.rb b/app/controllers/verify/sessions_controller.rb index 27e3818c043..21031c957db 100644 --- a/app/controllers/verify/sessions_controller.rb +++ b/app/controllers/verify/sessions_controller.rb @@ -99,15 +99,11 @@ def process_failure end end - def view_model(error: nil) - Verify::SessionsNew.new( - error: error, - remaining_attempts: remaining_idv_attempts, - idv_form: idv_form - ) + def view_model_class + Verify::SessionsNew end - def remaining_idv_attempts + def remaining_step_attempts Idv::Attempter.idv_max_attempts - current_user.idv_attempts end diff --git a/app/view_models/verify/base.rb b/app/view_models/verify/base.rb index 2be7d1bce72..46d0c291aa0 100644 --- a/app/view_models/verify/base.rb +++ b/app/view_models/verify/base.rb @@ -2,10 +2,11 @@ module Verify class Base include Rails.application.routes.url_helpers - def initialize(error: nil, remaining_attempts:, idv_form:) + def initialize(error: nil, remaining_attempts:, idv_form:, timed_out: nil) @error = error @remaining_attempts = remaining_attempts @idv_form = idv_form + @timed_out = timed_out end attr_reader :error, :remaining_attempts, :idv_form @@ -39,6 +40,7 @@ def warning_partial end def message + return html_paragraph(text: I18n.t("idv.modal.#{step_name}.timeout")) if timed_out? html_paragraph(text: I18n.t("idv.modal.#{step_name}.#{error}")) if error end @@ -56,12 +58,16 @@ def flash_message flash_heading = html_paragraph( text: I18n.t("idv.modal.#{step_name}.heading"), css_class: 'mb2 fs-20p' ) - flash_body = html_paragraph(text: I18n.t("idv.modal.#{step_name}.#{error}")) + flash_body = message flash_heading + flash_body + attempts end private + def timed_out? + @timed_out + end + def button_link_text I18n.t("idv.modal.button.#{error}") end diff --git a/spec/view_models/verify/base_spec.rb b/spec/view_models/verify/base_spec.rb index c36daff9791..a5dcd367dc8 100644 --- a/spec/view_models/verify/base_spec.rb +++ b/spec/view_models/verify/base_spec.rb @@ -22,4 +22,36 @@ end end end + + describe '#message' do + let(:timed_out) { false } + let(:view_model) do + Verify::Base.new( + error: error, + remaining_attempts: 1, + idv_form: nil, + timed_out: timed_out + ) + end + + subject(:message) { view_model.message } + + before { expect(view_model).to receive(:step_name).and_return(:phone) } + + context 'with a warning' do + let(:error) { 'warning' } + + it 'uses the warning copy' do + expect(message).to include(t('idv.modal.phone.warning')) + end + + context 'with a timeout' do + let(:timed_out) { true } + + it 'uses the timeout copy' do + expect(message).to include(t('idv.modal.phone.timeout')) + end + end + end + end end