whisper-money/tests/Feature
Víctor Falcón ae2a8c0118
fix(open-banking): use net_amounts for Indexa Capital invested amount calculation (#156)
## Why

### Problem

The Indexa Capital dashboard shows +€11,339.01 profit for the Index
funds account, but our app shows +€9,680.43 — a €1,658.58 discrepancy.
The invested amount (and therefore the profit) is wrong.

### Root Cause

`calculateInvestedAmount()` used `instruments_cost + cash_amount` to
determine how much was invested. However, `instruments_cost` is the
**cost basis of currently held fund shares**, not the actual money
deposited. When Indexa rebalances portfolios, they sell shares
(realizing gains) and buy new ones at a higher cost basis. This inflates
`instruments_cost` over time without any new deposits, making the
"invested" figure too high and profit too low.

## What

### Changes

- Use `net_amounts` from the Indexa Capital API response instead of
`instruments_cost + cash_amount`
- `net_amounts` is an object keyed by date (`YYYYMMDD` format), where
each value is the cumulative net investment (inflows - outflows -
tax_outflows), matching Indexa Capital's own "investment" figure
- Keep `total_amount - return` as a fallback when `net_amounts` is
unavailable
- Return `null` when neither data source is available

### Concrete numbers (Index funds account, 2026-02-24)

| | Old (wrong) | New (correct) |
|---|---|---|
| Invested | €48,081.67 | €46,423.09 |
| Profit | €9,680.43 | €11,339.01 |

## Verification

### Tests

- Updated `stores invested_amount from net_amounts data` — verifies
invested_amount is sourced from `net_amounts`, not `instruments_cost +
cash_amount`
- Updated `stores null invested_amount when net_amounts is missing` —
verifies graceful null when API lacks `net_amounts`
- Updated `falls back to total_amount minus return when net_amounts is
missing` — verifies fallback path
- All 11 balance sync tests pass, all 23 SyncBankingConnectionJob tests
pass
2026-02-25 15:45:31 +01:00
..
Api Remove encryption from bank account names (#104) 2026-02-09 14:15:26 +01:00
Auth fix: Disable email verification on dev/local 2026-02-07 17:52:53 +01:00
Console Remove encryption from browser tests and demo user (#129) 2026-02-17 11:45:27 +01:00
Jobs/Drip Add subscription cancellation email with manual trigger command (#47) 2025-12-30 20:32:44 +01:00
Listeners chore: Sync users to Resend after email verification (#98) 2026-02-03 22:59:28 +01:00
Onboarding User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
OpenBanking fix(open-banking): use net_amounts for Indexa Capital invested amount calculation (#156) 2026-02-25 15:45:31 +01:00
Settings Remove encryption from bank account names (#104) 2026-02-09 14:15:26 +01:00
Sync refactor: Simplify transaction endpoints architecture (#76) 2026-01-25 16:15:17 +01:00
AccountBalanceControllerTest.php feat: investment benefits — show gains/losses on investment accounts (#140) 2026-02-23 13:59:10 +01:00
AccountControllerTest.php perf(accounts): replace client-side API calls with Inertia deferred prop (#144) 2026-02-23 20:08:41 +01:00
AutomationRuleEvaluationTest.php feat: Apply automation rules to bank-synced transactions (#112) 2026-02-12 14:20:55 +01:00
AutomationRuleTest.php chore: Simplify IndexedDB sync by moving to Inertia shared props (#63) 2026-01-19 19:15:26 +01:00
BalanceLookupTest.php feat: investment benefits — show gains/losses on investment accounts (#140) 2026-02-23 13:59:10 +01:00
BudgetHistoricalAssignmentTest.php Remove budgets feature flag (#108) 2026-02-12 09:58:01 +01:00
BudgetPeriodDateTest.php Remove budgets feature flag (#108) 2026-02-12 09:58:01 +01:00
BudgetTest.php Remove budgets feature flag (#108) 2026-02-12 09:58:01 +01:00
BudgetTransactionServiceTest.php fix(budgets): handle refunds correctly in budget spending calculations (#152) 2026-02-24 21:12:36 +01:00
BulkUpdateTransactionsTest.php refactor: Simplify transaction endpoints architecture (#76) 2026-01-25 16:15:17 +01:00
CashflowAnalyticsTest.php test: Fix Carbon month overflow in date calculations (#87) 2026-02-01 11:33:09 +01:00
CurrencyConversionServiceTest.php feat: Add Binance integration (#131) 2026-02-18 15:23:46 +01:00
DashboardAnalyticsTest.php feat: enable invested amount tracking for savings accounts (#142) 2026-02-23 17:19:33 +01:00
DashboardTest.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
DecryptTransactionsTest.php feat: Decrypt encrypted transactions on key unlock (#123) 2026-02-16 10:37:43 +01:00
DeleteUserCommandTest.php test: Optimize tests performance 2026-01-17 19:20:23 +01:00
DemoAccountRestrictionsTest.php test: Optimize DemoAccountRestrictionsTest to run under 10s 2026-01-28 21:27:27 +01:00
EncryptionTest.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
ExampleTest.php Install Pest 2025-11-07 12:01:58 +00:00
ExchangeRateServiceTest.php feat: Add multi-currency conversion for net worth charts (#138) 2026-02-20 10:45:23 +01:00
IdorVulnerabilityTest.php refactor: Simplify transaction endpoints architecture (#76) 2026-01-25 16:15:17 +01:00
ImportDataTest.php fix: Apply automation rule labels on transaction creation and import (#79) 2026-01-27 11:11:29 +01:00
InertiaSharedDataTest.php SEO landing page 2025-11-25 11:33:11 +01:00
LabelTest.php feat: add transaction labels feature (#24) 2025-12-13 13:02:19 +01:00
PlaintextTransactionsTest.php Remove plaintext-transactions feature flag & E2E references (#116) 2026-02-13 11:10:21 +01:00
PwaTest.php feat: Improve PWA standalone experience and redirect to dashboard (#90) 2026-02-01 11:33:10 +01:00
ResendSyncCommandTest.php feat: Sync new users to Resend contacts (#85) 2026-01-28 21:25:58 +01:00
SitemapTest.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
SubscriptionTest.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
SyncBankingConnectionsCommandTest.php perf: make banking syncs incremental on subsequent runs (#141) 2026-02-23 15:10:40 +01:00
TransactionFilterTest.php Move transaction filtering from client-side to server-side (#126) 2026-02-16 12:49:04 +01:00
TransactionTest.php Move transaction filtering from client-side to server-side (#126) 2026-02-16 12:49:04 +01:00
UserLeadTest.php Add User Lead functionality and tests 2025-11-25 10:31:25 +01:00