diff --git a/spec/integration/customers/wallets_spec.rb b/spec/integration/customers/wallets_spec.rb index 13adf033..d46f6974 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) + # balance_cents is synced synchronously when the wallet transaction settles, but + # ongoing_balance_cents is refreshed by an async job (RefreshWalletJob), so re-fetch + # until the ongoing refresh has landed before asserting. + 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..0b83aaca 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) + # balance_cents is synced synchronously when the wallet transaction settles, but + # ongoing_balance_cents is refreshed by an async job (RefreshWalletJob), so re-fetch + # until the ongoing refresh has landed before asserting. + 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',