Skip to content

Commit

Permalink
LG-14273: Ensure the in-person verification profile has an enrollment…
Browse files Browse the repository at this point in the history
… record (#11315)

* Ensure the in-person verifcation profile has an enrollment record

In theory, it should never happen that the profile is pending verification and the enrollment record does not exist.

changelog: Internal, Automated Testing, Improve test setup for enrolling profiles

* fix association for in_person_enrollment pending trait and setup for user with_pending_in_person_enrollment trait

* fix setup in individual specs

* Add and update traits in profile and users factory

* Update spec/factories/in_person_enrollments.rb

Co-authored-by: Zach Margolis <[email protected]>

* remove extraneous setup from profile model spec

---------

Co-authored-by: Eileen McFarland <[email protected]>
Co-authored-by: Zach Margolis <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2024
1 parent 6759e64 commit 3200cf8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
success: true,
errors: {},
mfa_method_counts: { phone: 1 },
profile_idv_level: 'legacy_in_person',
profile_idv_level: 'in_person',
identity_verified: true,
account_age_in_days: 0,
account_confirmed_at: user.confirmed_at,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

context 'with enrollment' do
let(:user) { create(:user, :with_pending_in_person_enrollment) }
let(:profile) { create(:profile, :with_pii, user: user) }

it 'renders show template' do
expect(response).to render_template :show
Expand Down
9 changes: 2 additions & 7 deletions spec/controllers/idv/personal_key_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def assert_personal_key_generated_for_profiles(*profile_pii_pairs)

let(:address_verification_mechanism) { 'phone' }

let(:in_person_enrollment) { nil }

let(:idv_session) { subject.idv_session }

let(:threatmetrix_review_status) { nil }
Expand Down Expand Up @@ -524,13 +522,10 @@ def assert_personal_key_generated_for_profiles(*profile_pii_pairs)
end

context 'with in person profile' do
let!(:in_person_enrollment) do
create(:in_person_enrollment, :pending, user: user).tap do
user.reload_pending_in_person_enrollment
end
end
let!(:profile) { create(:profile, :in_person_verification_pending, user: user) }

before do
user.reload_pending_in_person_enrollment
allow(IdentityConfig.store).to receive(:in_person_proofing_enabled).and_return(true)
end

Expand Down
7 changes: 6 additions & 1 deletion spec/factories/in_person_enrollments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
status { :pending }
status_updated_at { Time.zone.now }
profile do
association(:profile, :in_person_verification_pending, user: user)
association(
:profile,
:in_person_verification_pending,
user: user,
in_person_enrollment: instance,
)
end
end

Expand Down
15 changes: 14 additions & 1 deletion spec/factories/profiles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@

trait :in_person_verification_pending do
in_person_verification_pending_at { 15.days.ago }
idv_level { :legacy_in_person }
idv_level { :in_person }
in_person_enrollment do
association(:in_person_enrollment, :pending, profile: instance, user:)
end
end

trait :in_person_verified do
verified_at { Time.zone.now }
activated_at { Time.zone.now }
idv_level { :in_person }
in_person_verification_pending_at { nil }
in_person_enrollment do
association(:in_person_enrollment, :passed, profile: instance, user:)
end
end

trait :fraud_pending_reason do
Expand Down
11 changes: 4 additions & 7 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@
end

trait :with_pending_in_person_enrollment do
after :build do |user|
profile = create(:profile, :with_pii, :in_person_verification_pending, user: user)
create(:in_person_enrollment, :pending, user: user, profile: profile)
profiles do
[association(:profile, :with_pii, :in_person_verification_pending, user: instance)]
end
end

Expand Down Expand Up @@ -270,16 +269,14 @@
confirmed_at { Time.zone.now.round }

after :build do |user|
profile = create(
create(
:profile,
:with_pii,
:active,
:verified,
:in_person_verification_pending,
:in_person_verified,
user: user,
)
create(:in_person_enrollment, :passed, user: user, profile: profile)
profile.in_person_verification_pending_at = nil
end
end

Expand Down
3 changes: 0 additions & 3 deletions spec/models/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,6 @@
describe '#deactivate_due_to_encryption_error' do
context 'when the profile has a "pending" in_person_enrollment' do
subject { create(:profile, :in_person_verification_pending, user: user) }
let!(:enrollment) do
create(:in_person_enrollment, user: user, profile: subject, status: :pending)
end

before do
subject.deactivate_due_to_encryption_error
Expand Down
8 changes: 4 additions & 4 deletions spec/views/accounts/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
end

context 'when current user has ipp pending profile' do
let(:user) { build(:user, :with_pending_in_person_enrollment) }
let(:user) { create(:user, :with_pending_in_person_enrollment) }

it 'renders idv partial' do
expect(render).to render_template(partial: 'accounts/_identity_verification')
Expand All @@ -114,7 +114,7 @@
context 'when current user has an in_person_enrollment that was failed' do
let(:vtr) { ['Pe'] }
let(:sp_name) { 'sinatra-test-app' }
let(:user) { build(:user, :with_pending_in_person_enrollment) }
let(:user) { create(:user, :with_pending_in_person_enrollment) }

before do
# Make the in_person_enrollment and associated profile failed
Expand All @@ -132,7 +132,7 @@
context 'when current user has an in_person_enrollment that was cancelled' do
let(:vtr) { ['Pe'] }
let(:sp_name) { 'sinatra-test-app' }
let(:user) { build(:user, :with_pending_in_person_enrollment) }
let(:user) { create(:user, :with_pending_in_person_enrollment) }

before do
# Make the in_person_enrollment and associated profile cancelled
Expand All @@ -150,7 +150,7 @@
context 'when current user has an in_person_enrollment that expired' do
let(:vtr) { ['Pe'] }
let(:sp_name) { 'sinatra-test-app' }
let(:user) { build(:user, :with_pending_in_person_enrollment) }
let(:user) { create(:user, :with_pending_in_person_enrollment) }

before do
# Expire the in_person_enrollment and associated profile
Expand Down

0 comments on commit 3200cf8

Please sign in to comment.