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
6 changes: 6 additions & 0 deletions app/controllers/idv/otp_verification_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def show
def update
result = phone_confirmation_otp_verification_form.submit(code: params[:code])
analytics.idv_phone_confirmation_otp_submitted(**result.to_h)
irs_attempts_api_tracker.idv_phone_otp_submitted(
phone_number: idv_session.user_phone_confirmation_session.phone,
success: result.success?,
failure_reason: result.success? ? {} : result.extra.slice(:code_expired, :code_matches),
)

if result.success?
idv_session.user_phone_confirmation = true
redirect_to idv_review_url
Expand Down
13 changes: 13 additions & 0 deletions app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ def idv_document_upload_submitted(
)
end

# Tracks when a user submits OTP code sent to their phone
# @param [String] phone_number
# param [Boolean] success
# @param [Hash<Symbol,Array<Symbol>>] failure_reason
def idv_phone_otp_submitted(phone_number:, success:, failure_reason: nil)
track_event(
:idv_phone_otp_submitted,
phone_number: phone_number,
success: success,
failure_reason: failure_reason,
)
end

# The user has exceeded the rate limit during idv document upload
def idv_document_upload_rate_limited
track_event(
Expand Down
33 changes: 33 additions & 0 deletions spec/controllers/idv/otp_verification_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

before do
stub_analytics
stub_attempts_tracker
allow(@analytics).to receive(:track_event)
allow(@irs_attempts_api_tracker).to receive(:track_event)

sign_in(user)
stub_verify_steps_one_and_two(user)
Expand Down Expand Up @@ -97,5 +99,36 @@
expected_result,
)
end

describe 'track irs analytics event' do
context 'when the phone otp code is valid' do
it 'captures success event' do
put :update, params: { code: phone_confirmation_otp_code }

expect(@irs_attempts_api_tracker).to have_received(:track_event).with(
:idv_phone_otp_submitted,
phone_number: phone,
success: true,
failure_reason: {},
)
end
end

context 'when the phone otp code is invalid' do
it 'captures failure event' do
put :update, params: { code: '000' }

expect(@irs_attempts_api_tracker).to have_received(:track_event).with(
:idv_phone_otp_submitted,
phone_number: phone,
success: false,
failure_reason: {
code_matches: false,
code_expired: false,
},
)
end
end
end
end
end