diff --git a/app/controllers/idv/phone_errors_controller.rb b/app/controllers/idv/phone_errors_controller.rb index 0ddadb5d828..8c6cdfd7fb3 100644 --- a/app/controllers/idv/phone_errors_controller.rb +++ b/app/controllers/idv/phone_errors_controller.rb @@ -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 @@ -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 diff --git a/app/policies/idv/flow_policy.rb b/app/policies/idv/flow_policy.rb index c32175ae3c2..2c95c55facc 100644 --- a/app/policies/idv/flow_policy.rb +++ b/app/policies/idv/flow_policy.rb @@ -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, diff --git a/spec/controllers/idv/phone_errors_controller_spec.rb b/spec/controllers/idv/phone_errors_controller_spec.rb index eb9a367e6d6..697d8326044 100644 --- a/spec/controllers/idv/phone_errors_controller_spec.rb +++ b/spec/controllers/idv/phone_errors_controller_spec.rb @@ -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 @@ -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 @@ -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 @@ -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