From ca281df612e4f2725ce638fe5aaafa8033e8f804 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Wed, 12 Apr 2023 15:46:43 -0400 Subject: [PATCH 1/7] LG-9333 Preserve the SSN when returning to the SSN controller The SSN controller allows a user to enter or update their SSN. Prior to this commit the previous value of the SSN was not maintained when the user was updating their SSN. This commit attempts to fix that by making use of the SSN form that is used in the controller. The template is changed to eventually read the SSN from the form. Additionally, the form is used in a pattern that better matches the pattern you expect a form object to be used in. This was not the case before because of constraints that the flow state machine placed on HTML forms. changelog: Improvements, Proofing workflow, The user's SSN is preserved for users who enter and SSN then continue to the verify step but return to the SSN in the unsupervised remote proofing flow. --- app/controllers/idv/ssn_controller.rb | 25 ++++++++----------------- app/forms/idv/ssn_format_form.rb | 9 +++++++-- app/views/idv/in_person/ssn.html.erb | 2 +- app/views/idv/ssn/show.html.erb | 10 +++++----- app/views/shared/_ssn_field.html.erb | 2 +- 5 files changed, 22 insertions(+), 26 deletions(-) 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..ca08f707c28 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 usa-input', value: f.object.ssn }, error_messages: { patternMismatch: t('idv.errors.pattern_mismatch.ssn') }, }, ) %> From 2682750cf8cb36346561db00e9c3ba181e1847f8 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Fri, 14 Apr 2023 10:58:21 -0400 Subject: [PATCH 2/7] fix existing tests --- spec/controllers/idv/ssn_controller_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 49cc6cf6cf512f08a1614c7d19373b22496744df Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Fri, 14 Apr 2023 11:23:37 -0400 Subject: [PATCH 3/7] specs for the form --- spec/forms/idv/ssn_format_form_spec.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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) From 95fe7793ace88ce1e8b91f41891502c39feda145 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Fri, 14 Apr 2023 11:32:58 -0400 Subject: [PATCH 4/7] update an existing feature spec to check for pre-fill --- spec/features/idv/doc_auth/verify_info_step_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) 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') From 3de110d0626c76e875b1ac923038902101c7d0e2 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Fri, 14 Apr 2023 11:37:09 -0400 Subject: [PATCH 5/7] remove extraneous css --- app/views/shared/_ssn_field.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_ssn_field.html.erb b/app/views/shared/_ssn_field.html.erb index ca08f707c28..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: f.object.ssn }, + input_html: { class: 'ssn-toggle', value: f.object.ssn }, error_messages: { patternMismatch: t('idv.errors.pattern_mismatch.ssn') }, }, ) %> From 2b26e7f18e1db19dcbd69f86856f220f65656961 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Fri, 14 Apr 2023 11:40:55 -0400 Subject: [PATCH 6/7] put back use-input class --- app/views/shared/_ssn_field.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_ssn_field.html.erb b/app/views/shared/_ssn_field.html.erb index 44afe95439f..ca08f707c28 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', value: f.object.ssn }, + input_html: { class: 'ssn-toggle usa-input', value: f.object.ssn }, error_messages: { patternMismatch: t('idv.errors.pattern_mismatch.ssn') }, }, ) %> From c3c7d070db4fe68ab74d9b762c9f8d2a8a8820ae Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Fri, 14 Apr 2023 13:04:12 -0400 Subject: [PATCH 7/7] remove usa-input class --- app/views/shared/_ssn_field.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/_ssn_field.html.erb b/app/views/shared/_ssn_field.html.erb index ca08f707c28..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: f.object.ssn }, + input_html: { class: 'ssn-toggle', value: f.object.ssn }, error_messages: { patternMismatch: t('idv.errors.pattern_mismatch.ssn') }, }, ) %>