whisper-money/tests/Feature/OpenBanking
Víctor Falcón 4408f719b4
fix(banking): update external_account_id on reconnect and store IBAN (#220)
## Problem

Enable Banking issues **new account UIDs** (`external_account_id`) with
every new session. On reconnect, `AuthorizationController::callback()`
was correctly updating `session_id` on the `banking_connections` table
but **never refreshing `external_account_id` on child accounts**.

When the background `SyncBankingConnectionJob` ran after a reconnect, it
called `GET /accounts/{old-uid}/transactions` using stale UIDs from the
expired session, causing Enable Banking to return `401 EXPIRED_SESSION`
— surfaced to users as _"Authentication failed. Your credentials may
have expired or been revoked."_

## Changes

- **`AuthorizationController`** — added `refreshAccountIds()` private
method, called in the reconnect branch after `session_id` is updated and
before the sync job is dispatched. Matches existing accounts by **IBAN
first**, falls back to **positional order** (`created_at ASC`) for
legacy accounts without a stored IBAN.
- **`AuthorizationController`** — `createAccountsFromSession()` and
`createAccountsFromPending()` now persist the `iban` field on account
creation so future reconnects can use IBAN matching.
- **`Account` model** — `iban` added to `$fillable`.
- **Migration** — adds nullable `iban` column to `accounts` table.

## Tests

4 new feature tests in `AuthorizationControllerTest`:

- `reconnect callback updates external_account_id when enable banking
issues new account uids`
- `reconnect callback matches accounts by iban before falling back to
position`
- `reconnect callback uses positional fallback for accounts without
stored iban`
- `callback stores iban when creating accounts for the first time`

## Deploy notes

Run the migration after deploying:

```
php artisan migrate --force
```
2026-03-12 10:28:23 +00:00
..
AccountMappingTest.php feat: Integrate EnableBanking as open banking provider (#106) 2026-02-12 09:09:28 +01:00
AuthorizationControllerTest.php fix(banking): update external_account_id on reconnect and store IBAN (#220) 2026-03-12 10:28:23 +00:00
BalanceSyncServiceTest.php feat: Integrate EnableBanking as open banking provider (#106) 2026-02-12 09:09:28 +01:00
BinanceBalanceSyncTest.php perf: make banking syncs incremental on subsequent runs (#141) 2026-02-23 15:10:40 +01:00
BinanceControllerTest.php feat: Add Binance integration (#131) 2026-02-18 15:23:46 +01:00
BitpandaBalanceSyncTest.php feat: investment benefits — show gains/losses on investment accounts (#140) 2026-02-23 13:59:10 +01:00
BitpandaControllerTest.php feat: Add Bitpanda exchange integration (#132) 2026-02-19 09:26:31 +01:00
ConnectionControllerTest.php feat(connections): filter already-connected institutions from connect bank dialog (#217) 2026-03-11 12:06:49 +00:00
IndexaCapitalBalanceSyncTest.php fix(open-banking): use net_amounts for Indexa Capital invested amount calculation (#156) 2026-02-25 15:45:31 +01:00
IndexaCapitalControllerTest.php feat: Add Indexa Capital integration (#130) 2026-02-18 10:42:13 +01:00
InstitutionControllerTest.php feat: Integrate EnableBanking as open banking provider (#106) 2026-02-12 09:09:28 +01:00
OpenBankingFeatureFlagTest.php fix(onboarding): gate connect bank option behind open-banking feature flag (#197) 2026-03-03 20:49:27 +00:00
SyncBankingConnectionJobTest.php feat(open-banking): add update credentials flow for API-key connections (#154) 2026-02-25 13:41:24 +01:00
SyncBinanceHistoricalBalancesJobTest.php feat: Add Binance integration (#131) 2026-02-18 15:23:46 +01:00
TransactionSyncServiceTest.php feat: Add per-bank description formatter for bank-synced transactions (#120) 2026-02-13 09:54:58 +01:00