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
26 changes: 13 additions & 13 deletions app/controllers/idv/phone_errors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module Idv
class PhoneErrorsController < ApplicationController
include Idv::AvailabilityConcern
include IdvStepConcern
include StepIndicatorConcern
include IdvSession
include Idv::AbTestAnalyticsConcern

before_action :confirm_two_factor_authenticated
before_action :confirm_idv_phone_step_needed
before_action :confirm_idv_phone_step_submitted, except: [:failure]
before_action :confirm_step_allowed, except: [:failure]
before_action :set_gpo_letter_available
before_action :ignore_form_step_wait_requests

Expand Down Expand Up @@ -39,21 +37,23 @@ def failure
track_event(type: :failure)
end

def self.step_info
Idv::StepInfo.new(
key: :phone_errors,
controller: self,
action: :failure,
next_steps: [FlowPolicy::FINAL],
preconditions: ->(idv_session:, user:) { idv_session.previous_phone_step_params.present? },
undo_step: ->(idv_session:, user:) {},
)
end

private

def rate_limiter
RateLimiter.new(user: idv_session.current_user, rate_limit_type: :proof_address)
end

def confirm_idv_phone_step_needed
return unless user_fully_authenticated?
redirect_to idv_enter_password_url if idv_session.user_phone_confirmation == true
end

def confirm_idv_phone_step_submitted
redirect_to idv_phone_url if idv_session.previous_phone_step_params.nil?
end

def ignore_form_step_wait_requests
head(:no_content) if request.headers['HTTP_X_FORM_STEPS_WAIT']
end
Expand Down
1 change: 1 addition & 0 deletions app/policies/idv/flow_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def steps
ipp_verify_info: Idv::InPerson::VerifyInfoController.step_info,
address: Idv::AddressController.step_info,
phone: Idv::PhoneController.step_info,
phone_errors: Idv::PhoneErrorsController.step_info,
otp_verification: Idv::OtpVerificationController.step_info,
request_letter: Idv::ByMail::RequestLetterController.step_info,
enter_password: Idv::EnterPasswordController.step_info,
Expand Down
28 changes: 16 additions & 12 deletions spec/controllers/idv/phone_errors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
{ sample_bucket1: :sample_value1, sample_bucket2: :sample_value2 }
end

describe '#step_info' do
it 'returns a valid StepInfo object' do
expect(Idv::PhoneErrorsController.step_info).to be_valid
end
end

before do
allow(subject).to receive(:remaining_attempts).and_return(5)
stub_analytics
Expand All @@ -13,6 +19,13 @@

if user
stub_sign_in(user)
subject.idv_session.welcome_visited = true
subject.idv_session.idv_consent_given = true
subject.idv_session.flow_path = 'standard'
subject.idv_session.pii_from_doc = Idp::Constants::MOCK_IDV_APPLICANT
subject.idv_session.ssn = '123-45-6789'
subject.idv_session.applicant = Idp::Constants::MOCK_IDV_APPLICANT_WITH_PHONE
subject.idv_session.resolution_successful = true
subject.idv_session.user_phone_confirmation = false
subject.idv_session.previous_phone_step_params = previous_phone_step_params
end
Expand All @@ -28,7 +41,7 @@
context 'authenticated user' do
let(:user) { create(:user) }

context 'the user has not submtted a phone number' do
context 'the user has not submitted a phone number' do
it 'redirects to phone step' do
subject.idv_session.previous_phone_step_params = nil
get action
Expand Down Expand Up @@ -78,19 +91,10 @@
subject.idv_session.user_phone_confirmation = true
end

it 'redirects to the review url' do
it 'allows the back button and renders the template' do
get action

expect(response).to redirect_to(idv_enter_password_url)
end
it 'does not log an event' do
expect(@analytics).not_to receive(:track_event).with(
'IdV: phone error visited',
hash_including(
type: action,
),
)
get action
expect(response).to render_template(template)
end
end
end
Expand Down