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
25 changes: 8 additions & 17 deletions app/controllers/idv/ssn_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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
9 changes: 7 additions & 2 deletions app/forms/idv/ssn_format_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,6 +26,10 @@ def submit(params)
)
end

def updating_ssn?
ssn.present?
end

private

def consume_params(params)
Expand Down
2 changes: 1 addition & 1 deletion app/views/idv/in_person/ssn.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ locals:
<% end %>

<%= simple_form_for(
:doc_auth,
Idv::SsnFormatForm.new(current_user),
url: url_for,
method: :put,
html: { autocomplete: 'off' },
Expand Down
10 changes: 5 additions & 5 deletions app/views/idv/ssn/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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')) %>
Expand Down Expand Up @@ -66,7 +66,7 @@ locals:
<% end %>

<%= simple_form_for(
:doc_auth,
@ssn_form,
url: idv_ssn_url,
method: :put,
html: { autocomplete: 'off' },
Expand All @@ -78,15 +78,15 @@ locals:
<p><%= @error_message %></p>

<%= 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') %>
<% end %>
<% 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' %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_ssn_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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') },
},
) %>
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/idv/ssn_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,16 @@
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

it 'does not change threatmetrix_session_id when updating ssn' do
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
Expand Down
5 changes: 5 additions & 0 deletions spec/features/idv/doc_auth/verify_info_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/, ''))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not clear to me why this gsub is needed. Are you expecting the field to be blank? Could you use GOOD_SSN_MASKED?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm looking at the value of the field which is the SSN without the dashes.


fill_in t('idv.form.ssn_label_html'), with: '900456789'
click_button t('forms.buttons.submit.update')

Expand Down
22 changes: 21 additions & 1 deletion spec/forms/idv/ssn_format_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down