Skip to content

Commit

Permalink
feat(wallet): Ensure resetting the ready_to_be_refreshed flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Oct 14, 2024
1 parent 3d0101c commit e141e57
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/services/events/post_process_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def flag_wallets_for_refresh
return unless customer
return unless customer.wallets.active.any?

customer.wallets.active.not_ready_to_be_refreshed.update_all(ready_to_be_refreshed: true)
customer.wallets.active.not_ready_to_be_refreshed.update_all(ready_to_be_refreshed: true) # rubocop:disable Rails/SkipsModelValidations
end

def handle_pay_in_advance
Expand Down
3 changes: 2 additions & 1 deletion app/services/wallets/balance/update_ongoing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def compute_update_params
ongoing_usage_balance_cents: total_usage_amount_cents,
credits_ongoing_usage_balance:,
ongoing_balance_cents:,
credits_ongoing_balance:
credits_ongoing_balance:,
ready_to_be_refreshed: false
}

if !wallet.depleted_ongoing_balance? && ongoing_balance_cents <= 0
Expand Down
4 changes: 3 additions & 1 deletion spec/services/wallets/balance/update_ongoing_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
ongoing_usage_balance_cents: 200,
credits_balance: 10.0,
credits_ongoing_balance: 8.0,
credits_ongoing_usage_balance: 2.0
credits_ongoing_usage_balance: 2.0,
ready_to_be_refreshed: true
)
end
let(:total_usage_amount_cents) { 450 }
Expand All @@ -28,6 +29,7 @@
.and change(wallet, :credits_ongoing_usage_balance).from(2.0).to(4.5)
.and change(wallet, :ongoing_balance_cents).from(800).to(550)
.and change(wallet, :credits_ongoing_balance).from(8.0).to(5.5)
.and change(wallet, :ready_to_be_refreshed).from(true).to(false)

expect(wallet).not_to be_depleted_ongoing_balance
end
Expand Down

0 comments on commit e141e57

Please sign in to comment.