Add tests for Purchases aggregate in Balance View detailed balance #237

Merged
Copilot merged 1 commit from copilot/fix-purchases-category-in-balance-view into main 2026-04-27 14:16:58 +00:00
Copilot commented 2026-04-27 13:53:26 +00:00 (Migrated from github.com)

After the previous update grouping purchases into a single aggregate item on the Balance View, the "Purchases" category was not appearing. Root cause: stale 24-hour cache from before the update. The code itself was correct — the aggregate entry is only pushed when $purchasesTotal > 0, so the item appears correctly once cache expires or a purchase is modified.

Description

  • Added 2 tests to BalanceTest.php verifying getDetailedMonthlyBalance() behavior:
    • Purchases aggregate entry appears with correct total, is_purchase: true, and category->name: 'Purchases' when purchases exist in the period
    • No "Purchases" entry is present when the period has no purchases
  • Fixed stale inline comment in BalanceService::getDetailedMonthlyBalance() that still referenced "individual purchase records" instead of the single aggregate approach

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (code change that neither fixes a bug nor adds a feature)
  • Performance improvement
  • Test coverage improvement

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this manually (if applicable)

Code Quality

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors

CI/CD Checks

  • All automated tests pass
  • Code formatting (Pint) passes
  • JavaScript/TypeScript linting passes
  • Build process completes successfully

Additional Notes

The "Purchases" category not appearing immediately after deployment is a cache issue, not a code bug. The cached detailed balance result (24h TTL) was generated before the aggregation change. It self-resolves when PurchaseObserver invalidates the cache on any purchase mutation, or after TTL expiry.

After the previous update grouping purchases into a single aggregate item on the Balance View, the "Purchases" category was not appearing. Root cause: stale 24-hour cache from before the update. The code itself was correct — the aggregate entry is only pushed when `$purchasesTotal > 0`, so the item appears correctly once cache expires or a purchase is modified. ## Description - Added 2 tests to `BalanceTest.php` verifying `getDetailedMonthlyBalance()` behavior: - Purchases aggregate entry appears with correct total, `is_purchase: true`, and `category->name: 'Purchases'` when purchases exist in the period - No "Purchases" entry is present when the period has no purchases - Fixed stale inline comment in `BalanceService::getDetailedMonthlyBalance()` that still referenced "individual purchase records" instead of the single aggregate approach ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update - [ ] Refactoring (code change that neither fixes a bug nor adds a feature) - [ ] Performance improvement - [x] Test coverage improvement ## Testing - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] I have tested this manually (if applicable) ## Code Quality - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings or errors ## CI/CD Checks - [x] All automated tests pass - [x] Code formatting (Pint) passes - [ ] JavaScript/TypeScript linting passes - [ ] Build process completes successfully ## Additional Notes The "Purchases" category not appearing immediately after deployment is a cache issue, not a code bug. The cached detailed balance result (24h TTL) was generated before the aggregation change. It self-resolves when `PurchaseObserver` invalidates the cache on any purchase mutation, or after TTL expiry.
coderabbitai[bot] commented 2026-04-27 13:53:33 +00:00 (Migrated from github.com)

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 2d23bcd9-c4d9-4165-a8b8-d2e274f06af4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- This is an auto-generated comment: skip review by coderabbit.ai --> > [!IMPORTANT] > ## Review skipped > > Bot user detected. > > To trigger a single review, invoke the `@coderabbitai review` command. > > <details> > <summary>⚙️ Run configuration</summary> > > **Configuration used**: defaults > > **Review profile**: CHILL > > **Plan**: Free > > **Run ID**: `2d23bcd9-c4d9-4165-a8b8-d2e274f06af4` > > </details> > > You can disable this status message by setting the `reviews.review_status` to `false` in the CodeRabbit configuration file. > > Use the checkbox below for a quick retry: > - [ ] <!-- {"checkboxId": "e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: skip review by coderabbit.ai --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub> <!-- tips_end -->
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-04-27 14:14:49 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Sign in to join this conversation.
No description provided.