whisper-money/tests/Feature
Víctor Falcón 5b1d059e02
feat(loans): backfill historical balances on loan creation (#322)
## Summary

Mirror the real-estate historical-balance pattern for loan accounts.
When a loan is created with a current balance, linearly interpolate
monthly `account_balances` rows between the loan start date
(`original_amount`) and today (current balance).

## Approach

Since we don't know how the user actually paid down the loan, use simple
linear regression between two known points:
- `(start_date, original_amount)` from `loan_details`
- `(today, current_balance)` from the latest `account_balances` row

Rows are placed on the start date, the 1st of each intermediate month,
and today.

## Changes

- **`LoanBalanceGeneratorService`** — linear interpolation + upsert on
`(account_id, balance_date)` so existing rows aren't duplicated.
- **`GenerateHistoricalLoanBalancesJob`** — `ShouldQueue`, 3 tries, 10s
backoff. Takes account, original amount, start date, current balance,
from, to.
- **`Settings/AccountController::store`** (loan branch) — after creating
`loanDetail`, if a starting balance was provided: generate the last 12
months synchronously, dispatch older window to the queue when
`start_date` predates it.
- **`LoanDetailController::update`** — when the detail is first created
for an existing account, use the most recent `AccountBalance` as the
current value and apply the same sync/async split.

## Tests

- Service: interpolation, single-balance edge, future start_date, upsert
dedupe, monthly 1st placement, from/to range.
- Job: implements `ShouldQueue`, respects from/to range.

```
Tests:    8 passed (62 assertions)
```

No dependency or directory-structure changes.
2026-04-24 13:09:34 +01:00
..
Api Remove encryption from bank account names (#104) 2026-02-09 14:15:26 +01:00
Auth Support soft-deleted users with reusable emails (#316) 2026-04-22 11:41:41 +01:00
Commands feat: selective retry of failed lead email jobs (#286) 2026-04-15 08:00:29 +01:00
Console Support soft-deleted users with reusable emails (#316) 2026-04-22 11:41:41 +01:00
Jobs feat(loans): backfill historical balances on loan creation (#322) 2026-04-24 13:09:34 +01:00
Listeners fix(budgets): make budget assignment idempotent (#303) 2026-04-18 18:39:00 +01:00
Onboarding feat: (Onboarding) add categorization intro screen with benefit cards (#201) 2026-03-05 11:47:12 +01:00
OpenBanking fix: route new PWA guests to signup (#313) 2026-04-21 10:53:05 +01:00
Services feat(loans): backfill historical balances on loan creation (#322) 2026-04-24 13:09:34 +01:00
Settings Support soft-deleted users with reusable emails (#316) 2026-04-22 11:41:41 +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 fix: route new PWA guests to signup (#313) 2026-04-21 10:53:05 +01:00
ApplyRealEstateRevaluationTest.php feat(accounts): add market value and annual revaluation to real estate accounts (#245) 2026-03-26 11:02:20 +01:00
AuthenticatedLayoutSafeAreaTest.php fix: keep iOS content below the notch (#280) 2026-04-13 13:59:05 +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
BackfillAccountIbansCommandTest.php chore: upgrade Laravel 12 to 13 (#242) 2026-03-25 12:56:33 +00: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 Fix net worth chart config UX and color scheme issues (#250) 2026-03-31 11:19:35 +01:00
BudgetTransactionServiceTest.php fix(budgets): retry assignment deadlocks (#304) 2026-04-19 11:21:27 +01:00
BulkUpdateTransactionsTest.php refactor: Simplify transaction endpoints architecture (#76) 2026-01-25 16:15:17 +01:00
CancelFreeEnableBankingConnectionsCommandTest.php Cancel Enable Banking connections for free users (#289) 2026-04-15 16:23:03 +02:00
CashflowAnalyticsTest.php fix(cashflow): net transfer categories in sankey (#257) 2026-04-01 14:48:38 +01:00
CashflowPageTest.php fix: route new PWA guests to signup (#313) 2026-04-21 10:53:05 +01:00
CurrencyConversionServiceTest.php feat(settings): centralize currency options and split profile/account support (#256) 2026-04-02 19:23:10 +02:00
DashboardAnalyticsTest.php feat: store invested_amount in user currency instead of account currency (#262) 2026-04-06 12:48:13 +02:00
DashboardTest.php fix: route new PWA guests to signup (#313) 2026-04-21 10:53:05 +01:00
DecryptTransactionsTest.php feat: Decrypt encrypted transactions on key unlock (#123) 2026-02-16 10:37:43 +01:00
DeleteUserCommandTest.php Support soft-deleted users with reusable emails (#316) 2026-04-22 11:41:41 +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
GenerateStripePromotionCodesCommandTest.php feat(stripe): add promo code generator (#311) 2026-04-20 18:15:28 +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 fix(user): persist detected timezones (#296) 2026-04-16 11:36:57 +01:00
LabelTest.php feat: add transaction labels feature (#24) 2025-12-13 13:02:19 +01:00
LandingAuthOverrideTest.php feat(landing): add signed auth links (#312) 2026-04-21 08:28:59 +01:00
LoanTest.php feat: link loans to existing properties (#275) 2026-04-13 09:51:13 +01:00
LocalizationTest.php feat(i18n): add localization test and fix missing Spanish translations (#174) 2026-03-01 12:32:39 +00:00
MailSenderTest.php Cancel Enable Banking connections for free users (#289) 2026-04-15 16:23:03 +02:00
PlaintextTransactionsTest.php Remove plaintext-transactions feature flag & E2E references (#116) 2026-02-13 11:10:21 +01:00
PopoverSafeAreaTest.php fix: keep iOS popovers below the notch (#282) 2026-04-13 15:19:56 +01:00
PwaTest.php fix: avoid iOS PWA status bar overlap (#281) 2026-04-13 14:38:48 +01:00
ReEvaluateTransactionRulesTest.php chore: upgrade Laravel 12 to 13 (#242) 2026-03-25 12:56:33 +00:00
RealEstateAvailabilityTest.php refactor(real-estate): remove Pennant gating (#308) 2026-04-20 13:31:49 +01:00
RealEstateTest.php refactor(real-estate): remove Pennant gating (#308) 2026-04-20 13:31:49 +01:00
ResendLeadVerificationEmailsCommandTest.php feat: resend verification emails to unverified leads (#287) 2026-04-15 09:13:27 +01:00
ResendSyncCommandTest.php feat: Sync new users to Resend contacts (#85) 2026-01-28 21:25:58 +01:00
ResendSyncLeadsCommandTest.php feat: verify waitlist leads (#285) 2026-04-14 11:26:01 +01:00
SentryConfigTest.php fix(ci): order sentry deploy after build (#309) 2026-04-20 13:35:07 +01:00
SitemapTest.php User Onboarding Flow (#23) 2025-12-12 13:06:08 +01:00
SubscriptionTest.php feat(billing): apply Stripe tax rates to subscriptions (#325) 2026-04-24 14:07:58 +02:00
SyncBankingConnectionsCommandTest.php chore: Remove account-mapping feature flag (#252) 2026-04-01 12:09:22 +02:00
SyncStripePricesCommandTest.php fix(pricing): update final release prices (#288) 2026-04-15 14:49:02 +01:00
TransactionFilterTest.php Move transaction filtering from client-side to server-side (#126) 2026-02-16 12:49:04 +01:00
TransactionTest.php fix: route new PWA guests to signup (#313) 2026-04-21 10:53:05 +01:00
UserLeadTest.php feat: verify waitlist leads (#285) 2026-04-14 11:26:01 +01:00
WelcomeBanksOrderingTest.php feat(open-banking): remove feature flag gating (#297) 2026-04-17 10:20:05 +02:00