Skip to content

Commit

Permalink
Minor code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
shanechesnutt-ft committed Feb 10, 2025
1 parent b99adbd commit 4ccd4e7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 14 deletions.
8 changes: 3 additions & 5 deletions app/forms/reset_password_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ def mark_profile_as_password_reset

def password_reset_profile
FeatureManagement.pending_in_person_password_reset_enabled? ?
find_pending_in_person_or_active_profile :
find_in_progress_in_person_or_active_profile :
active_profile
end

def find_pending_in_person_or_active_profile
user.pending_in_person_enrollment&.profile ||
user.in_fraud_review_in_person_enrollments.first&.profile ||
active_profile
def find_in_progress_in_person_or_active_profile
user.current_in_progress_in_person_enrollment_profile || active_profile
end

# It is possible for an account that is resetting their password to be "invalid".
Expand Down
3 changes: 1 addition & 2 deletions app/jobs/get_usps_proofing_results_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ def check_enrollment(enrollment)

def cancel_enrollment(enrollment)
enrollment_outcomes[:enrollments_cancelled] += 1
enrollment.cancelled!
enrollment.profile.deactivate_due_to_in_person_verification_cancelled
enrollment.cancel
end

def skip_enrollment(enrollment, profile_deactivation_reason)
Expand Down
16 changes: 9 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,26 +533,28 @@ def last_sign_in_email_address
email_addresses.confirmed.last_sign_in
end

def in_fraud_review_in_person_enrollments
in_person_enrollments.where(status: 'in_fraud_review').order(created_at: :desc)
# Find the user's most recent in-progress enrollment profile.
def current_in_progress_in_person_enrollment_profile
in_person_enrollments
.where(status: [:pending, :in_fraud_review])
.order(created_at: :desc)
.first&.profile
end

private

def find_password_reset_profile
FeatureManagement.pending_in_person_password_reset_enabled? ?
find_pending_in_person_or_active_profile :
find_in_person_in_progress_or_active_profile :
find_active_profile
end

def find_active_profile
profiles.where.not(activated_at: nil).order(activated_at: :desc).first
end

def find_pending_in_person_or_active_profile
pending_in_person_enrollment&.profile ||
in_fraud_review_in_person_enrollments.first&.profile ||
profiles.where.not(activated_at: nil).order(activated_at: :desc).first
def find_in_person_in_progress_or_active_profile
current_in_progress_in_person_enrollment_profile || find_active_profile
end

def lockout_period
Expand Down
49 changes: 49 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1950,4 +1950,53 @@ def it_should_not_send_survey
expect(user.last_sign_in_email_address).to eq(last_sign_in_email_address)
end
end

describe '#current_in_progress_in_person_enrollment_profile' do
let(:user) { create(:user) }

context 'when the user has a pending in-person enrollment' do
let!(:enrollment) { create(:in_person_enrollment, :pending, user: user) }

it 'returns the enrollments associated profile' do
expect(user.current_in_progress_in_person_enrollment_profile).to eq(enrollment.profile)
end
end

context 'when the user has an in_fraud_review in-person enrollment' do
let!(:enrollment) { create(:in_person_enrollment, :in_fraud_review, user: user) }

it 'returns the enrollments associated profile' do
expect(user.current_in_progress_in_person_enrollment_profile).to eq(enrollment.profile)
end
end

context 'when the user has an in_fraud_review and in_fraud_review in-person enrollment' do
let!(:pending_enrollment) { create(:in_person_enrollment, :pending, user: user) }
let!(:fraud_enrollment) { create(:in_person_enrollment, :in_fraud_review, user: user) }

context 'when the pending enrollment was created more recently' do
before do
pending_enrollment.update(created_at: Time.zone.now)
end

it "returns the pending enrollment's associated profile" do
expect(user.current_in_progress_in_person_enrollment_profile).to eq(
pending_enrollment.profile,
)
end
end

context 'when the in_fraud_review enrollment was created more recently' do
before do
fraud_enrollment.update(created_at: Time.zone.now)
end

it "returns the in_fraud_review enrollment's associated profile" do
expect(user.current_in_progress_in_person_enrollment_profile).to eq(
fraud_enrollment.profile,
)
end
end
end
end
end

0 comments on commit 4ccd4e7

Please sign in to comment.