diff --git a/app/controllers/idv/ssn_controller.rb b/app/controllers/idv/ssn_controller.rb index 936b331d6f3..420e3e4b7a9 100644 --- a/app/controllers/idv/ssn_controller.rb +++ b/app/controllers/idv/ssn_controller.rb @@ -14,19 +14,22 @@ class SsnController < ApplicationController def show increment_step_counts - analytics.idv_doc_auth_redo_ssn_submitted(**analytics_arguments) if updating_ssn + @ssn_form = Idv::SsnFormatForm.new(current_user, flow_session) + analytics.idv_doc_auth_redo_ssn_submitted(**analytics_arguments) if @ssn_form.updating_ssn? analytics.idv_doc_auth_ssn_visited(**analytics_arguments) Funnel::DocAuth::RegisterStep.new(current_user.id, sp_session[:issuer]). call('ssn', :view, true) - render :show, locals: extra_view_variables + render :show, locals: threatmetrix_view_variables end def update @error_message = nil - form_response = form_submit + + @ssn_form = Idv::SsnFormatForm.new(current_user, flow_session) + form_response = @ssn_form.submit(params.require(:doc_auth).permit(:ssn)) analytics.idv_doc_auth_ssn_submitted( **analytics_arguments.merge(form_response.to_h), @@ -41,18 +44,10 @@ def update redirect_to next_url else @error_message = form_response.first_error_message - render :show, locals: extra_view_variables + render :show, locals: threatmetrix_view_variables end end - def extra_view_variables - { - updating_ssn: updating_ssn, - success_alert_enabled: !updating_ssn, - **threatmetrix_view_variables, - } - end - private def next_url @@ -83,12 +78,8 @@ def increment_step_counts current_flow_step_counts['Idv::Steps::SsnStep'] += 1 end - def form_submit - Idv::SsnFormatForm.new(current_user).submit(params.require(:doc_auth).permit(:ssn)) - end - def updating_ssn - flow_session.dig('pii_from_doc', :ssn).present? + @ssn_form.updating_ssn? end end end diff --git a/app/forms/idv/ssn_format_form.rb b/app/forms/idv/ssn_format_form.rb index 6354b763d83..8b5a6e6f4b3 100644 --- a/app/forms/idv/ssn_format_form.rb +++ b/app/forms/idv/ssn_format_form.rb @@ -8,11 +8,12 @@ class SsnFormatForm attr_accessor :ssn def self.model_name - ActiveModel::Name.new(self, nil, 'Ssn') + ActiveModel::Name.new(self, nil, 'doc_auth') end - def initialize(user) + def initialize(user, flow_session = {}) @user = user + @ssn = flow_session.dig('pii_from_doc', :ssn) end def submit(params) @@ -25,6 +26,10 @@ def submit(params) ) end + def updating_ssn? + ssn.present? + end + private def consume_params(params) diff --git a/app/views/idv/in_person/ssn.html.erb b/app/views/idv/in_person/ssn.html.erb index 5e6cd1d086d..195f167c9b6 100644 --- a/app/views/idv/in_person/ssn.html.erb +++ b/app/views/idv/in_person/ssn.html.erb @@ -50,7 +50,7 @@ locals: <% end %> <%= simple_form_for( - :doc_auth, + Idv::SsnFormatForm.new(current_user), url: url_for, method: :put, html: { autocomplete: 'off' }, diff --git a/app/views/idv/ssn/show.html.erb b/app/views/idv/ssn/show.html.erb index e7bc914d943..b5d6ba650fd 100644 --- a/app/views/idv/ssn/show.html.erb +++ b/app/views/idv/ssn/show.html.erb @@ -17,7 +17,7 @@ locals: <% title t('titles.doc_auth.ssn') %> -<% if success_alert_enabled %> +<% if !@ssn_form.updating_ssn? %> <%= render AlertComponent.new( type: :success, class: 'margin-bottom-4', @@ -26,7 +26,7 @@ locals: <% end %> <% end %> -<% if updating_ssn %> +<% if @ssn_form.updating_ssn? %> <%= render PageHeadingComponent.new.with_content(t('doc_auth.headings.ssn_update')) %> <% else %> <%= render PageHeadingComponent.new.with_content(t('doc_auth.headings.ssn')) %> @@ -66,7 +66,7 @@ locals: <% end %> <%= simple_form_for( - :doc_auth, + @ssn_form, url: idv_ssn_url, method: :put, html: { autocomplete: 'off' }, @@ -78,7 +78,7 @@ locals:
<%= @error_message %>
<%= f.submit class: 'display-block margin-y-5' do %> - <% if updating_ssn %> + <% if @ssn_form.updating_ssn? %> <%= t('forms.buttons.submit.update') %> <% else %> <%= t('forms.buttons.continue') %> @@ -86,7 +86,7 @@ locals: <% end %> <% end %> -<% if updating_ssn %> +<% if @ssn_form.updating_ssn? %> <%= render 'idv/shared/back', fallback_path: idv_verify_info_path %> <% else %> <%= render 'idv/doc_auth/cancel', step: 'ssn' %> diff --git a/app/views/shared/_ssn_field.html.erb b/app/views/shared/_ssn_field.html.erb index d559c10df0f..44afe95439f 100644 --- a/app/views/shared/_ssn_field.html.erb +++ b/app/views/shared/_ssn_field.html.erb @@ -15,7 +15,7 @@ locals: required: true, pattern: '^\d{3}-?\d{2}-?\d{4}$', maxlength: 11, - input_html: { class: 'ssn-toggle usa-input', value: '' }, + input_html: { class: 'ssn-toggle', value: f.object.ssn }, error_messages: { patternMismatch: t('idv.errors.pattern_mismatch.ssn') }, }, ) %> diff --git a/spec/controllers/idv/ssn_controller_spec.rb b/spec/controllers/idv/ssn_controller_spec.rb index 442d7eb48f9..7afed831c25 100644 --- a/spec/controllers/idv/ssn_controller_spec.rb +++ b/spec/controllers/idv/ssn_controller_spec.rb @@ -144,7 +144,8 @@ end it 'adds a threatmetrix session id to flow session' do - subject.extra_view_variables + put :update, params: params + subject.threatmetrix_view_variables expect(flow_session[:threatmetrix_session_id]).to_not eq(nil) end @@ -152,7 +153,7 @@ flow_session['pii_from_doc'][:ssn] = ssn put :update, params: params session_id = flow_session[:threatmetrix_session_id] - subject.extra_view_variables + subject.threatmetrix_view_variables expect(flow_session[:threatmetrix_session_id]).to eq(session_id) end end diff --git a/spec/features/idv/doc_auth/verify_info_step_spec.rb b/spec/features/idv/doc_auth/verify_info_step_spec.rb index ad24b0a7d27..abfcce0cb46 100644 --- a/spec/features/idv/doc_auth/verify_info_step_spec.rb +++ b/spec/features/idv/doc_auth/verify_info_step_spec.rb @@ -75,7 +75,12 @@ it 'allows the user to enter in a new ssn and displays updated info' do click_link t('idv.buttons.change_ssn_label') + expect(page).to have_current_path(idv_ssn_path) + expect( + find_field(t('idv.form.ssn_label_html')).value, + ).to eq(DocAuthHelper::GOOD_SSN.gsub(/\D/, '')) + fill_in t('idv.form.ssn_label_html'), with: '900456789' click_button t('forms.buttons.submit.update') diff --git a/spec/forms/idv/ssn_format_form_spec.rb b/spec/forms/idv/ssn_format_form_spec.rb index 2f791a7a307..f368e6e7f19 100644 --- a/spec/forms/idv/ssn_format_form_spec.rb +++ b/spec/forms/idv/ssn_format_form_spec.rb @@ -2,8 +2,10 @@ describe Idv::SsnFormatForm do let(:user) { create(:user) } - let(:subject) { Idv::SsnFormatForm.new(user) } let(:ssn) { '111-11-1111' } + let(:flow_session) { {} } + + subject { Idv::SsnFormatForm.new(user, flow_session) } describe '#submit' do context 'when the form is valid' do @@ -34,6 +36,24 @@ end end + describe '#updating_ssn' do + context 'when no flow_session value is provided' do + subject { Idv::SsnFormatForm.new(user) } + + it { expect(subject.updating_ssn?).to eq(false) } + end + + context 'when the pii_from_doc hash does not contain an SSN value' do + it { expect(subject.updating_ssn?).to eq(false) } + end + + context 'when there is an SSN in the pii_from_doc hash' do + let(:flow_session) { { 'pii_from_doc' => { ssn: '900-12-3456' } } } + + it { expect(subject.updating_ssn?).to eq(true) } + end + end + describe 'presence validations' do it 'is invalid when required attribute is not present' do subject.submit(ssn: nil)