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
11 changes: 10 additions & 1 deletion app/controllers/concerns/idv_failure_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 2 additions & 6 deletions app/controllers/verify/finance_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/verify/phone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions app/controllers/verify/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC says this is not tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops turns out the shared view_model helper method I defined was not included in this controller, fixed in 57b53cf

end

def remaining_idv_attempts
def remaining_step_attempts
Idv::Attempter.idv_max_attempts - current_user.idv_attempts
end

Expand Down
10 changes: 8 additions & 2 deletions app/view_models/verify/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
32 changes: 32 additions & 0 deletions spec/view_models/verify/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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