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
14 changes: 12 additions & 2 deletions app/controllers/idv/in_person/ssn_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ def show
def update
clear_future_steps!
ssn_form = Idv::SsnFormatForm.new(idv_session.ssn)
form_response = ssn_form.submit(params.require(:doc_auth).permit(:ssn))
form_response = ssn_form.submit(ssn: ssn_params[:ssn])
@ssn_presenter = Idv::SsnPresenter.new(
sp_name: decorated_sp_session.sp_name,
ssn_form: ssn_form,
step_indicator_steps: step_indicator_steps,
)

attempts_api_tracker.idv_ssn_submitted(
success: form_response.success?,
social_security: ssn_params[:ssn],
failure_reason: attempts_api_tracker.parse_failure_reason(form_response),
)

if form_response.success?
idv_session.previous_ssn = idv_session.ssn
idv_session.ssn = SsnFormatter.normalize(params[:doc_auth][:ssn])
idv_session.ssn = SsnFormatter.normalize(ssn_params[:ssn])
redirect_to next_url
else
flash[:error] = form_response.first_error_message
Expand Down Expand Up @@ -89,6 +95,10 @@ def analytics_arguments
}.merge(ab_test_analytics_buckets)
.merge(**extra_analytics_properties)
end

def ssn_params
params.require(:doc_auth).permit(:ssn)
end
end
end
end
15 changes: 13 additions & 2 deletions app/controllers/idv/ssn_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ def show
def update
clear_future_steps!
ssn_form = Idv::SsnFormatForm.new(idv_session.ssn)
form_response = ssn_form.submit(params.require(:doc_auth).permit(:ssn))
form_response = ssn_form.submit(ssn: ssn_params[:ssn])

@ssn_presenter = Idv::SsnPresenter.new(
sp_name: decorated_sp_session.sp_name,
ssn_form: ssn_form,
step_indicator_steps: step_indicator_steps,
)

attempts_api_tracker.idv_ssn_submitted(
success: form_response.success?,
social_security: ssn_params[:ssn],
failure_reason: attempts_api_tracker.parse_failure_reason(form_response),
)

if form_response.success?
idv_session.previous_ssn = idv_session.ssn
idv_session.ssn = SsnFormatter.normalize(params[:doc_auth][:ssn])
idv_session.ssn = SsnFormatter.normalize(ssn_params[:ssn])
redirect_to next_url
else
flash[:error] = form_response.first_error_message
Expand Down Expand Up @@ -91,5 +98,9 @@ def analytics_arguments
previous_ssn_edit_distance: previous_ssn_edit_distance,
}.merge(ab_test_analytics_buckets)
end

def ssn_params
params.require(:doc_auth).permit(:ssn)
end
end
end
21 changes: 3 additions & 18 deletions app/forms/idv/ssn_format_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SsnFormatForm
include ActiveModel::Model
include FormSsnFormatValidator

ATTRIBUTES = [:ssn].freeze

attr_accessor :ssn

def self.model_name
Expand All @@ -18,12 +16,12 @@ def initialize(incoming_ssn)
@updating_ssn = ssn.present?
end

def submit(params)
consume_params(params)
def submit(ssn:)
@ssn = ssn

FormResponse.new(
success: valid?,
errors: errors,
errors:,
extra: {
pii_like_keypaths: [
[:same_address_as_id],
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.

is :same_address_as_id necessary here, or is this an artifact of the code doing something else at some point?

Expand All @@ -37,18 +35,5 @@ def submit(params)
def updating_ssn?
@updating_ssn
end

private

def consume_params(params)
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.

it seems like this was a construct developed for forms that are "consuming" a number of different params; while i might argue about whether or not it's that useful generally, it certainly seems like overkill for a form that is only using one param.

params.each do |key, value|
raise_invalid_ssn_parameter_error(key) unless ATTRIBUTES.include?(key.to_sym)
send(:"#{key}=", value)
end
end

def raise_invalid_ssn_parameter_error(key)
raise ArgumentError, "#{key} is an invalid ssn attribute"
end
end
end
13 changes: 13 additions & 0 deletions app/services/attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def idv_ipp_ready_to_verify_visit
track_event('idv-ipp-ready-to-verify-visit')
end

# @param [Boolean] success
# @param [String] social_security
# @param [Hash<Symbol,Array<Symbol>>] failure_reason
# A user inputs their SSN number during Identity verification
def idv_ssn_submitted(success:, social_security:, failure_reason: nil)
track_event(
'idv-ssn-submitted',
success:,
social_security:,
failure_reason:,
)
end

# @param [Boolean] success True if the entered code matched the sent code
# @param [Hash<Symbol,Array<Symbol>>] failure_reason if code did not match
# A user that requested to verify their address by mail entered the code contained in the letter
Expand Down
14 changes: 13 additions & 1 deletion spec/controllers/idv/in_person/ssn_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
stub_sign_in(user)
controller.user_session['idv/in_person'] = flow_session
stub_analytics
stub_attempts_tracker
controller.idv_session.flow_path = 'standard'
end

Expand Down Expand Up @@ -140,6 +141,11 @@
end

it 'sends analytics_submitted event' do
expect(@attempts_api_tracker).to receive(:idv_ssn_submitted).with(
success: true,
social_security: ssn,
failure_reason: nil,
)
put :update, params: params

expect(@analytics).to have_logged_event(analytics_name, analytics_args)
Expand Down Expand Up @@ -196,7 +202,8 @@
end

context 'invalid ssn' do
let(:params) { { doc_auth: { ssn: 'i am not an ssn' } } }
let(:ssn) { 'i am not an ssn' }
let(:params) { { doc_auth: { ssn: } } }
let(:analytics_name) { 'IdV: doc auth ssn submitted' }
let(:analytics_args) do
{
Expand All @@ -211,6 +218,11 @@
render_views

it 'renders the show template with an error message' do
expect(@attempts_api_tracker).to receive(:idv_ssn_submitted).with(
success: false,
social_security: ssn,
failure_reason: { ssn: [:invalid] },
)
put :update, params: params

expect(response).to have_rendered('idv/shared/ssn')
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/idv/ssn_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
stub_sign_in(user)
stub_up_to(:document_capture, idv_session: controller.idv_session)
stub_analytics
stub_attempts_tracker
end

describe '#step_info' do
Expand Down Expand Up @@ -163,6 +164,11 @@
end

it 'updates idv_session.ssn to the ssn' do
expect(@attempts_api_tracker).to receive(:idv_ssn_submitted).with(
success: true,
social_security: ssn,
failure_reason: nil,
)
expect { put :update, params: params }.to change { subject.idv_session.ssn }
.from(nil).to(ssn)
expect(@analytics).to have_logged_event(analytics_name, analytics_args)
Expand Down Expand Up @@ -273,6 +279,11 @@
render_views

it 'renders the show template with an error message' do
expect(@attempts_api_tracker).to receive(:idv_ssn_submitted).with(
success: false,
social_security: ssn,
failure_reason: { ssn: [:invalid] },
)
put :update, params: params

expect(response).to have_rendered('idv/shared/ssn')
Expand Down
7 changes: 0 additions & 7 deletions spec/forms/idv/ssn_format_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@
expect(result.errors).to include(:ssn)
end
end

context 'when the form has invalid attributes' do
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.

form now cannot accept invalid attributes, so this spec is unnecessary

it 'raises an error' do
expect { subject.submit(ssn: '111111111', foo: 1) }
.to raise_error(ArgumentError, 'foo is an invalid ssn attribute')
end
end
end

describe '#updating_ssn?' do
Expand Down