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
2 changes: 1 addition & 1 deletion app/controllers/idv/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class SessionsController < ApplicationController

def destroy
cancel_processing
clear_session
log_analytics
clear_session
redirect_to idv_url
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/anonymous_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def uuid
'anonymous-uuid'
end

def establishing_in_person_enrollment; end

def pending_in_person_enrollment; end

def second_factor_locked_at
nil
end
Expand Down
280 changes: 248 additions & 32 deletions app/services/analytics_events.rb

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions app/services/idv/analytics_events_enhancer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,20 @@ def profile_history
end

def proofing_components
return if !user&.respond_to?(:proofing_component) || !user.proofing_component
ProofingComponentsLogging.new(user.proofing_component)
return if !user

idv_session = Idv::Session.new(
user_session: session&.dig('warden.user.user.session') || {},
current_user: user,
service_provider: sp,
)

proofing_components_hash = ProofingComponents.new(
user:,
idv_session:,
).to_h

proofing_components_hash.empty? ? nil : proofing_components_hash
end
end
end
70 changes: 70 additions & 0 deletions app/services/idv/proofing_components.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

module Idv
class ProofingComponents
def initialize(
user:,
idv_session:
)
@user = user
@idv_session = idv_session
end

def document_check
if user.establishing_in_person_enrollment || user.pending_in_person_enrollment
Idp::Constants::Vendors::USPS
elsif idv_session.remote_document_capture_complete?
DocAuthRouter.doc_auth_vendor(
discriminator: idv_session.document_capture_session_uuid,
)
end
end

def document_type
return 'state_id' if idv_session.remote_document_capture_complete?
end

def source_check
Idp::Constants::Vendors::AAMVA if idv_session.verify_info_step_complete?
end

def resolution_check
Idp::Constants::Vendors::LEXIS_NEXIS if idv_session.verify_info_step_complete?
end

def address_check
if idv_session.verify_by_mail?
'gpo_letter'
elsif idv_session.address_verification_mechanism == 'phone'
'lexis_nexis_address'
end
end

def threatmetrix
if idv_session.threatmetrix_review_status.present?
FeatureManagement.proofing_device_profiling_collecting_enabled?
end
end

def threatmetrix_review_status
idv_session.threatmetrix_review_status
end

def to_h
{
document_check:,
document_type:,
source_check:,
resolution_check:,
address_check:,
threatmetrix:,
threatmetrix_review_status:,

}.compact
end

private

attr_reader :user, :idv_session
end
end
21 changes: 0 additions & 21 deletions app/services/idv/proofing_components_logging.rb

This file was deleted.

1 change: 1 addition & 0 deletions spec/features/idv/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@
and_return(proofing_device_profiling)
allow_any_instance_of(ApplicationController).to receive(:analytics) do |controller|
fake_analytics.user = controller.analytics_user
fake_analytics.session = controller.session
fake_analytics
end
allow(IdentityConfig.store).to receive(:idv_acuant_sdk_upgrade_a_b_testing_enabled).
Expand Down
6 changes: 5 additions & 1 deletion spec/features/idv/cancel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
start_idv_from_sp(sp)
sign_in_and_2fa_user(user)
complete_doc_auth_steps_before_agreement_step
allow_any_instance_of(ApplicationController).to receive(:analytics).and_return(fake_analytics)

allow_any_instance_of(ApplicationController).to receive(:analytics) do |controller|
fake_analytics.session = controller.session
fake_analytics
end
end

it 'shows the user a cancellation message with the option to go back to the step' do
Expand Down
35 changes: 24 additions & 11 deletions spec/services/idv/analytics_events_enhancer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
RSpec.describe Idv::AnalyticsEventsEnhancer do
let(:user) { build(:user) }
let(:sp) { nil }
let(:session) { nil }
let(:user_session) { nil }
let(:session) do
if user_session.present?
{
'warden.user.user.session' => user_session,
}
end
end

let(:analytics_class) do
Class.new(FakeAnalytics) do
include AnalyticsEvents
Expand Down Expand Up @@ -63,11 +71,7 @@ def track_event(_event, **kwargs)
end

describe 'proofing_components' do
let(:proofing_components) { nil }

before do
user.proofing_component = proofing_components
end
let(:user_session) { {} }

context 'without proofing component' do
it 'calls analytics method with original attributes' do
Expand All @@ -79,17 +83,26 @@ def track_event(_event, **kwargs)
end
end

context 'with proofing component' do
let(:proofing_components) do
ProofingComponent.new(source_check: Idp::Constants::Vendors::AAMVA)
context 'with proofing components' do
before do
# Set up the user_session so it looks like the user's been through doc auth
idv_session = Idv::Session.new(
user_session:,
current_user: user,
service_provider: sp,
)
idv_session.pii_from_doc = Idp::Constants::MOCK_IDV_APPLICANT
end

it 'calls analytics method with original attributes and proofing_components' do
analytics.idv_test_method(extra: true)

expect(analytics.called_kwargs).to match(
expect(analytics.called_kwargs).to eql(
extra: true,
proofing_components: kind_of(Idv::ProofingComponentsLogging),
proofing_components: {
document_check: 'mock',
document_type: 'state_id',
},
)
end
end
Expand Down
12 changes: 0 additions & 12 deletions spec/services/idv/proofing_components_logging_spec.rb

This file was deleted.

Loading