diff --git a/spec/integration/customers/wallets_spec.rb b/spec/integration/customers/wallets_spec.rb index 13adf033..940e32c8 100644 --- a/spec/integration/customers/wallets_spec.rb +++ b/spec/integration/customers/wallets_spec.rb @@ -51,6 +51,15 @@ def assert_wallet_attributes(wallet, **attributes) end def assert_wallet_attributes_with_updated_balance(wallet, **attributes) + # The balance is synced synchronously when the wallet transaction settles, but the ongoing + # balance is now refreshed by an async job (RefreshWalletJob). Re-fetch until that refresh has + # landed, otherwise the ongoing balance can still be 0 when the balance already reached 2000. + expected_ongoing_balance_cents = attributes.fetch(:ongoing_balance_cents, 2000) + wait_until do + wallet = client.customers.wallets.get(wallet.external_customer_id, wallet.code) + wallet.ongoing_balance_cents == expected_ongoing_balance_cents + end + assert_wallet_attributes( wallet, credits_balance: '10.0', diff --git a/spec/integration/wallets_spec.rb b/spec/integration/wallets_spec.rb index 841aca63..b5f3da32 100644 --- a/spec/integration/wallets_spec.rb +++ b/spec/integration/wallets_spec.rb @@ -49,6 +49,15 @@ def assert_wallet_attributes(wallet, **attributes) end def assert_wallet_attributes_with_updated_balance(wallet, **attributes) + # The balance is synced synchronously when the wallet transaction settles, but the ongoing + # balance is now refreshed by an async job (RefreshWalletJob). Re-fetch until that refresh has + # landed, otherwise the ongoing balance can still be 0 when the balance already reached 2000. + expected_ongoing_balance_cents = attributes.fetch(:ongoing_balance_cents, 2000) + wait_until do + wallet = client.wallets.get(wallet.lago_id) + wallet.ongoing_balance_cents == expected_ongoing_balance_cents + end + assert_wallet_attributes( wallet, credits_balance: '10.0',