Repository navigation
test(earnings): cover driverEarningsService grouping, boundaries and settled-only totals - #310
Merged
Tybravo merged 1 commit intoOct 23, 2026
Conversation
…settled-only totals Runs the real lookup/group pipeline against an in-memory MongoDB: daily totals, ISO week and month boundaries in UTC, RELEASED-only filtering, date ranges, zero-earnings responses and validation.
|
@lankeethebeast Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #227
Summary
driverEarningsServicebacksGET /api/v1/drivers/:id/earningsand had no tests. This adds 22 tests intests/driverEarningsService.test.ts, which follows the repo's flattests/layout.Escrow and delivery fixtures are stored in MongoMemoryServer and the real
$lookup→$grouppipeline runs against them, so every total asserted here is what MongoDB actually computes. Nothing in the service is mocked.What is covered
0.1 + 0.2→0.3), and theupdatedAtfallback whenreleasedAtis missing.%G-W%V) run Monday to Sunday (Sun 2026-01-04 →2026-W01, Mon 2026-01-05 →2026-W02). A week that straddles New Year takes its ISO week-year (Mon 2025-12-29 →2026-W01, Sun 2025-12-28 →2025-W52).RELEASEDescrows count. DISPUTED, REFUNDED, LOCKED, PENDING, EXPIRED and RESOLVED are excluded, and so is a released escrow whose delivery no longer exists.startDateandendDateare inclusive onreleasedAt. Open-ended ranges work on either side, andstartDate == endDateis accepted.periods: []andsummary: { totalAmount: 0, totalDeliveries: 0 }instead of an error. The same applies to an empty date range.driverId, unknowngroupBy,startDate > endDate, andassertValidDriverId.Verification
eslint and prettier are clean on the new file.
Note
The date-range filter matches on
releasedAtonly. A released escrow with noreleasedAtis still bucketed byupdatedAt, but it's excluded once astartDateorendDateis given. The tests don't depend on that edge case, but you may want to align the two.