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
20 changes: 14 additions & 6 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def activate

def activate_after_passing_review
update!(
fraud_review_pending: false, fraud_rejection: false, fraud_review_pending_at: nil,
fraud_rejection_at: nil
fraud_review_pending: false,
fraud_rejection: false,
fraud_review_pending_at: nil,
fraud_rejection_at: nil,
)
track_fraud_review_adjudication(decision: 'pass')
activate
Expand All @@ -68,15 +70,21 @@ def deactivate(reason)

def deactivate_for_fraud_review
update!(
active: false, fraud_review_pending: true, fraud_rejection: false,
fraud_review_pending_at: Time.zone.now, fraud_rejection_at: nil
active: false,
fraud_review_pending: true,
fraud_rejection: false,
fraud_review_pending_at: Time.zone.now,
fraud_rejection_at: nil,
)
end

def reject_for_fraud(notify_user:)
update!(
active: false, fraud_review_pending: false, fraud_rejection: true,
fraud_review_pending_at: nil, fraud_rejection_at: Time.zone.now
active: false,
fraud_review_pending: false,
fraud_rejection: true,
fraud_review_pending_at: nil,
fraud_rejection_at: Time.zone.now,
)
track_fraud_review_adjudication(
decision: notify_user ? 'manual_reject' : 'automatic_reject',
Expand Down
36 changes: 16 additions & 20 deletions spec/models/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Profile do
let(:user) { create(:user, :signed_up, password: 'a really long sekrit') }
let(:another_user) { create(:user, :signed_up) }
let(:profile) { create(:profile, user: user) }
let(:profile) { user.profiles.create }

let(:dob) { '1920-01-01' }
let(:ssn) { '666-66-1234' }
Expand Down Expand Up @@ -195,15 +195,15 @@
it 'prevents create! via ActiveRecord uniqueness validation' do
profile.active = true
profile.save!
expect { Profile.create!(user_id: user.id, active: true) }.
expect { user.profiles.create!(active: true) }.
to raise_error(ActiveRecord::RecordInvalid)
end

it 'prevents save! via psql unique partial index' do
profile.active = true
profile.save!
expect do
another_profile = Profile.new(user_id: user.id, active: true)
another_profile = user.profiles.new(active: true)
another_profile.save!(validate: false)
end.to raise_error(ActiveRecord::RecordNotUnique)
end
Expand All @@ -216,7 +216,7 @@
end

it 'is true when the user is re-activated' do
existing_profile = Profile.create(user: user)
existing_profile = user.profiles.create
existing_profile.activate
profile.activate

Expand All @@ -235,15 +235,15 @@

describe '#activate' do
it 'activates current Profile, de-activates all other Profile for the user' do
active_profile = Profile.create(user: user, active: true)
active_profile = user.profiles.create(active: true)
profile.activate
active_profile.reload
expect(active_profile).to_not be_active
expect(profile).to be_active
end

it 'sends a reproof completed push event' do
Profile.create(user: user, active: true)
user.profiles.create(active: true)
expect(PushNotification::HttpPush).to receive(:deliver).
with(PushNotification::ReproofCompletedEvent.new(user: user))

Expand All @@ -264,7 +264,7 @@
end

it 'does not activate a profile if under fraud review' do
profile.update(fraud_review_pending_at: Time.zone.today - 1.day)
profile.update(fraud_review_pending_at: 1.day.ago)
profile.activate

expect(profile).to_not be_active
Expand Down Expand Up @@ -296,7 +296,7 @@
it 'activates a profile if it passes fraud review' do
profile = create(
:profile, user: user, active: false,
fraud_review_pending_at: Time.zone.today - 1.day
fraud_review_pending_at: 1.day.ago
)
profile.activate_after_passing_review

Expand All @@ -310,7 +310,7 @@
:profile,
user: user,
active: false,
fraud_review_pending_at: Time.zone.today - 1.day,
fraud_review_pending_at: 1.day.ago,
initiating_service_provider: sp,
)
end
Expand Down Expand Up @@ -356,7 +356,7 @@
:profile,
user: user,
active: false,
fraud_review_pending_at: Time.zone.today - 1.day,
fraud_review_pending_at: 1.day.ago,
initiating_service_provider: sp,
)
expect(profile.initiating_service_provider.irs_attempts_api_enabled?).to be_falsey
Expand Down Expand Up @@ -394,7 +394,7 @@

context 'it notifies the user' do
let(:profile) do
profile = create(:profile, user: user, fraud_review_pending_at: Time.zone.today - 1.day)
profile = user.profiles.create(fraud_review_pending_at: 1.day.ago)
profile.reject_for_fraud(notify_user: true)
profile
end
Expand All @@ -414,7 +414,7 @@

context 'it does not notify the user' do
let(:profile) do
profile = create(:profile, user: user, fraud_review_pending_at: Time.zone.today - 1.day)
profile = user.profiles.create(fraud_review_pending_at: 1.day.ago)
profile.reject_for_fraud(notify_user: false)
profile
end
Expand All @@ -429,11 +429,9 @@
context 'when the SP is the IRS' do
let(:sp) { create(:service_provider, :irs) }
let(:profile) do
create(
:profile,
user: user,
user.profiles.create(
active: false,
fraud_review_pending_at: Time.zone.today - 1.day,
fraud_review_pending_at: 1.day.ago,
initiating_service_provider: sp,
)
end
Expand Down Expand Up @@ -476,11 +474,9 @@
context 'when the SP is not the IRS' do
it 'does not log an event' do
sp = create(:service_provider)
profile = create(
:profile,
user: user,
profile = user.profiles.create(
active: false,
fraud_review_pending_at: Time.zone.today - 1.day,
fraud_review_pending_at: 1.day.ago,
initiating_service_provider: sp,
)
allow(IdentityConfig.store).to receive(:irs_attempt_api_enabled).and_return(true)
Expand Down