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
11 changes: 11 additions & 0 deletions app/controllers/idv/capture_doc_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Idv
class CaptureDocController < ApplicationController
# rubocop:disable Rails/LexicallyScopedActionFilter
# index comes from the flow_state_matchine.rb
before_action :track_index_loads, only: [:index]
# rubocop:enable Rails/LexicallyScopedActionFilter
before_action :ensure_user_id_in_session

include Flow::FlowStateMachine
Expand All @@ -20,6 +24,13 @@ def return_to_sp

private

def track_index_loads
irs_attempts_api_tracker.idv_phone_upload_link_used(
document_capture_session: document_capture_session_uuid,
request_id: request_id,
)
end

def ensure_user_id_in_session
return if session[:doc_capture_user_id] &&
token.blank? &&
Expand Down
17 changes: 16 additions & 1 deletion app/services/irs_attempts_api/tracker_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def idv_letter_requested(success:, resend:)

# @param [Boolean] success
# @param [String] phone_number
# The phone upload link was sent during the IDV process
# The phone number that the link was sent to during the IDV process
# @param [Hash<Symbol,Array<Symbol>>] failure_reason
def idv_phone_upload_link_sent(
success:,
Expand All @@ -196,6 +196,21 @@ def idv_phone_upload_link_sent(
)
end

# @param [String] document_capture_session
# The document_capture_session included with the phone upload link used
# @param [String] request_id
# The request_id included with the phone upload link used
def idv_phone_upload_link_used(
document_capture_session:,
request_id:
)
track_event(
:idv_phone_upload_link_used,
document_capture_session: document_capture_session,
request_id: request_id,
)
end

# @param [Boolean] success
# @param [String] ssn
# User entered in SSN number during Identity verification
Expand Down
34 changes: 33 additions & 1 deletion spec/controllers/idv/capture_doc_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(:idv_phone_upload_link_used)
allow(Identity::Hostdata::EC2).to receive(:load).
and_return(OpenStruct.new(region: 'us-west-2', domain: 'example.com'))
end
Expand All @@ -33,6 +35,10 @@
it 'redirects to the root url' do
get :index

expect(@irs_attempts_api_tracker).to have_received(:idv_phone_upload_link_used).with(
{ document_capture_session: nil, request_id: '' },
)

expect(response).to redirect_to root_url
end
end
Expand All @@ -41,6 +47,10 @@
it 'redirects to the root url' do
get :index, params: { 'document-capture-session': 'foo' }

expect(@irs_attempts_api_tracker).to have_received(:idv_phone_upload_link_used).with(
{ document_capture_session: 'foo', request_id: '' },
)

expect(response).to redirect_to root_url
end
end
Expand All @@ -51,6 +61,10 @@
get :index, params: { 'document-capture-session': session_uuid }
end

expect(@irs_attempts_api_tracker).to have_received(:idv_phone_upload_link_used).with(
{ document_capture_session: session_uuid, request_id: '' },
)

expect(response).to redirect_to root_url
end
end
Expand All @@ -59,6 +73,10 @@
it 'redirects to the first step' do
get :index, params: { 'document-capture-session': session_uuid }

expect(@irs_attempts_api_tracker).to have_received(:idv_phone_upload_link_used).with(
{ document_capture_session: session_uuid, request_id: '' },
)

expect(response).to redirect_to idv_capture_doc_step_url(step: :document_capture)
end
end
Expand All @@ -68,6 +86,10 @@
mock_session(user.id)
get :index

expect(@irs_attempts_api_tracker).to have_received(:idv_phone_upload_link_used).with(
{ document_capture_session: nil, request_id: '' },
)

expect(response).to redirect_to idv_capture_doc_step_url(step: :document_capture)
end
end
Expand All @@ -94,6 +116,8 @@

mock_next_step(:document_capture)
get :show, params: { step: 'document_capture' }

expect(@irs_attempts_api_tracker).not_to have_received(:idv_phone_upload_link_used)
end

it 'renders the capture_complete template' do
Expand All @@ -108,20 +132,26 @@

mock_next_step(:capture_complete)
get :show, params: { step: 'capture_complete' }

expect(@irs_attempts_api_tracker).not_to have_received(:idv_phone_upload_link_used)
end

it 'renders a 404 with a non existent step' do
get :show, params: { step: 'foo' }

expect(@irs_attempts_api_tracker).not_to have_received(:idv_phone_upload_link_used)

expect(response).to_not be_not_found
end

it 'tracks analytics' do
it 'tracks expected events' do
mock_next_step(:capture_complete)
result = { step: 'capture_complete', flow_path: 'hybrid', step_count: 1 }

get :show, params: { step: 'capture_complete' }

expect(@irs_attempts_api_tracker).not_to have_received(:idv_phone_upload_link_used)

expect(@analytics).to have_received(:track_event).with(
'IdV: ' + "#{Analytics::DOC_AUTH} capture_complete visited".downcase, result
)
Expand All @@ -133,6 +163,8 @@
get :show, params: { step: 'capture_complete' }
get :show, params: { step: 'capture_complete' }

expect(@irs_attempts_api_tracker).not_to have_received(:idv_phone_upload_link_used)

expect(@analytics).to have_received(:track_event).ordered.with(
'IdV: ' + "#{Analytics::DOC_AUTH} capture_complete visited".downcase,
hash_including(step: 'capture_complete', step_count: 1),
Expand Down