From 59ecdef27e0f34e9ac613937fde248ec34267aa5 Mon Sep 17 00:00:00 2001 From: Jonathan Hooper Date: Wed, 19 Jul 2023 11:39:22 -0400 Subject: [PATCH] LG-9968 Read from `fraud_pending_reason` to find fraud pending profiles This commit makes the first change to switch over to the new `fraud_pending_reason` column. It reads from the column instead of the `fraud_review_pending_at` timestamp to determine if a profile is fraud review pending. This will allow us to stop writing to the `fraud_review_pending_at` timestamp until the user actually enters the fraud review workflow and go back and make the value nil for users who have not entered fraud review. Eventually we will need to consider the presence of `fraud_pending_reason` and absence of `fraud_review_pending_at` as a new state (i.e. the user has not started fraud review but is eligible to start fraud review once they verify their address). That is out of scope for this PR which is intended to switch the reads to make that new state possible in a future release. changelog: Internal, Profile State, The code that computes whether a user is fraud review pending was changed to compute the fraud review pending status based off of the fraud_pending_reason column and fraud_rejection_at column to remove the fraud_review_pending_at column from the computation and allow the way that column is written to be changed in a future deploy. --- app/models/profile.rb | 10 ++++------ app/models/user.rb | 4 +--- .../idv/gpo_verify_controller_spec.rb | 9 ++++++--- .../steps/gpo_otp_verification_step_spec.rb | 5 +++++ spec/models/user_spec.rb | 20 ++++--------------- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 0dfb29e91fb..c446d7f7d54 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -31,7 +31,7 @@ class Profile < ApplicationRecord attr_reader :personal_key def fraud_review_pending? - fraud_review_pending_at.present? + fraud_pending_reason.present? && !fraud_rejection? end def fraud_rejection? @@ -112,8 +112,10 @@ def activate_after_fraud_review_unnecessary def activate_after_passing_in_person transaction do update!( - deactivation_reason: nil, fraud_review_pending_at: nil, + fraud_rejection_at: nil, + fraud_pending_reason: nil, + deactivation_reason: nil, ) activate end @@ -134,10 +136,6 @@ def deactivate(reason) update!(active: false, deactivation_reason: reason) end - def has_deactivation_reason? - deactivation_reason.present? || has_fraud_deactivation_reason? || gpo_verification_pending? - end - def has_fraud_deactivation_reason? fraud_review_pending? || fraud_rejection? end diff --git a/app/models/user.rb b/app/models/user.rb index 366518ccb75..d132e59ef93 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -140,9 +140,7 @@ def pending_profile pending = profiles.where(deactivation_reason: :in_person_verification_pending).or( profiles.where.not(gpo_verification_pending_at: nil), ).or( - profiles.where.not(fraud_review_pending_at: nil), - ).or( - profiles.where.not(fraud_rejection_at: nil), + profiles.where.not(fraud_pending_reason: nil), ).order(created_at: :desc).first if pending.blank? diff --git a/spec/controllers/idv/gpo_verify_controller_spec.rb b/spec/controllers/idv/gpo_verify_controller_spec.rb index f4c111859fb..c4720e654c7 100644 --- a/spec/controllers/idv/gpo_verify_controller_spec.rb +++ b/spec/controllers/idv/gpo_verify_controller_spec.rb @@ -203,8 +203,9 @@ create( :profile, :with_pii, + :fraud_review_pending, + fraud_pending_reason: 'threatmetrix_reject', user: user, - fraud_review_pending_at: 1.day.ago, ) end @@ -239,8 +240,9 @@ create( :profile, :with_pii, + :fraud_review_pending, + fraud_pending_reason: 'threatmetrix_reject', user: user, - fraud_review_pending_at: 1.day.ago, ) end @@ -276,8 +278,9 @@ create( :profile, :with_pii, + :fraud_review_pending, + fraud_pending_reason: 'threatmetrix_review', user: user, - fraud_review_pending_at: 1.day.ago, ) end diff --git a/spec/features/idv/steps/gpo_otp_verification_step_spec.rb b/spec/features/idv/steps/gpo_otp_verification_step_spec.rb index 235ef73fda6..6ba031d7320 100644 --- a/spec/features/idv/steps/gpo_otp_verification_step_spec.rb +++ b/spec/features/idv/steps/gpo_otp_verification_step_spec.rb @@ -19,6 +19,7 @@ dob: '1970-01-01', }, fraud_review_pending_at: fraud_review_pending_timestamp, + fraud_pending_reason: fraud_pending_reason, fraud_rejection_at: fraud_rejection_timestamp, ) end @@ -32,6 +33,7 @@ let(:user) { profile.user } let(:threatmetrix_enabled) { false } let(:fraud_review_pending_timestamp) { nil } + let(:fraud_pending_reason) { nil } let(:fraud_rejection_timestamp) { nil } let(:redirect_after_verification) { nil } let(:profile_should_be_active) { true } @@ -47,6 +49,7 @@ context 'ThreatMetrix disabled, but we have ThreatMetrix status on proofing component' do let(:threatmetrix_enabled) { false } let(:fraud_review_pending_timestamp) { 1.day.ago } + let(:fraud_pending_reason) { 'threatmetrix_review' } it_behaves_like 'gpo otp verification' end @@ -60,6 +63,7 @@ context 'ThreatMetrix says "review"' do let(:fraud_review_pending_timestamp) { 1.day.ago } + let(:fraud_pending_reason) { 'threatmetrix_review' } let(:profile_should_be_active) { false } let(:fraud_review_pending) { true } it_behaves_like 'gpo otp verification' @@ -67,6 +71,7 @@ context 'ThreatMetrix says "reject"' do let(:fraud_rejection_timestamp) { 1.day.ago } + let(:fraud_pending_reason) { 'threatmetrix_review' } let(:profile_should_be_active) { false } let(:fraud_review_pending) { true } it_behaves_like 'gpo otp verification' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3185e805989..4f488a917b6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -577,10 +577,7 @@ describe '#fraud_review_pending?' do it 'returns true if fraud review is pending' do user = create(:user) - user.profiles.create( - active: false, - fraud_review_pending_at: 15.days.ago, - ) + create(:profile, :fraud_review_pending, user: user) expect(user.fraud_review_pending?).to eq true end @@ -589,10 +586,7 @@ describe '#fraud_rejection?' do it 'returns true if fraud rejection' do user = create(:user) - user.profiles.create( - active: false, - fraud_rejection_at: 15.days.ago, - ) + create(:profile, :fraud_rejection, user: user) expect(user.fraud_rejection?).to eq true end @@ -602,10 +596,7 @@ context 'with a fraud review pending profile' do it 'returns the profile pending review' do user = create(:user) - profile = user.profiles.create( - active: false, - fraud_review_pending_at: 15.days.ago, - ) + profile = create(:profile, :fraud_review_pending, user: user) expect(user.fraud_review_pending_profile).to eq(profile) end @@ -621,10 +612,7 @@ context 'with a fraud rejection profile' do it 'returns the profile with rejection' do user = create(:user) - profile = user.profiles.create( - active: false, - fraud_rejection_at: 15.days.ago, - ) + profile = create(:profile, :fraud_rejection, user: user) expect(user.fraud_rejection_profile).to eq(profile) end