test(tms): cover the driver-pay domain and service money math - #559
Merged
Conversation
Adds the first test coverage for the driver-pay vertical: - Domain: validation and money math for escrow accounts/transactions (sign rules per transaction type, funded percent, full funding), pay advances (outstanding balance, status sync), pay codes (code pattern, reimbursement classification, system code catalog), pay profiles (component rules, mileage band validation and resolution), worker pay assignments (effective windows, rate overrides), and recurring deductions/earnings (cap math, next-amount clamping). - Service: escrow open/adjust/close/interest-accrual flows (duplicate active account rejection, balance-floor enforcement, closure refunds per 49 CFR 376.12(k), interest math and accrual-date advancement), assignment overlap handling and rate-override validation, advance issue/update/write-off transitions, and deduction pay-code direction and escrow auto-linking. Also fixes an off-by-one in mileage band validation: contiguous bands (next.MinMiles == previous.MaxMiles) were rejected as overlapping even though ResolveMileageRate treats MaxMiles as exclusive, so the only gap-free encoding could not pass validation. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015houJkqb8SuqPW4YpLoWCq
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015houJkqb8SuqPW4YpLoWCq
Contributor
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
16 tasks
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.
Description
Third slice of the codebase completeness review: first test coverage for the driver-pay vertical, which previously had zero tests across ~5,000 LOC of money math. Coverage goes from 0% → 61.3% on the
driverpaydomain package and 0% → 49.8% ondriverpayservice(~2,600 lines of tests).Domain (
internal/core/domain/driverpay): escrow account/transaction validation including per-type sign rules (contributions and interest accruals must be positive; applications and refunds negative), funded-percent math and full-funding detection, pay-advance outstanding-balance math and status-sync transitions, pay-code pattern rules, reimbursement classification and the system code catalog, pay-profile component validation, mileage-band validation and rate resolution (including band boundaries and open-ended bands), worker-pay-assignment effective windows and rate overrides, and recurring deduction/earning cap math with next-amount clamping.Service (
internal/core/services/driverpayservice): escrow open (default interest rate from settlement control, duplicate-active-account rejection), adjust (balance-floor enforcement, transaction append with correctBalanceAfterMinor), close (refund of the remaining balance per 49 CFR 376.12(k), no refund on zero balance), interest accrual (exact year-fraction math, accrual-date advancement, ineligible-account no-ops), assignment overlap handling (earlier open assignments get ended at the new effective date; later-starting ones are rejected), rate-override component validation, advance issue/update/write-off transitions, and deduction pay-code direction checks with escrow auto-linking.The generated mocks don't yet cover the driver-pay repositories (and
CLAUDE.mdforbids a full mockery regeneration), so the service tests use package-local interface fakes — the same patternbankreceiptbatchservice's tests use.Bug found and fixed by the new tests:
validateBandsrejected contiguous mileage bands (next.MinMiles == previous.MaxMiles) as overlapping, butResolveMileageRatetreatsMaxMilesas exclusive — so the only encoding that produces gap-free mileage coverage could not pass validation, silently forcing 1-mile rate gaps in every banded pay profile. The check is nowband.MinMiles < prevMax, which still rejects genuine overlaps.Related Issue or Discussion
Found during a codebase completeness review; maintainer-driven session. Follow-up to #557 and #558.
Type of Change
Scope
services/tms/internal/core/domain/driverpay— 6 new test files + the one-linevalidateBandsfix inpayprofile.goservices/tms/internal/core/services/driverpayservice— 4 new test files + shared test fakesValidation
go test -coverfor both packages (all pass; coverage above),go vet,go build ./internal/...,go test -run TestFullSeedRunOnSQLite ./internal/infrastructure/database/seeder/(the dev seed still validates after the band fix), gofmt clean, golines applied with the repo's formatter settings.golangci-lintcould not run in this environment (binary built with Go 1.25, repo targets Go 1.26).cd services/tms && task test— full suite not run in this environment; changed-package tests pass.cd services/tms && task lint— see above.cd client && pnpm build— not run; no client changes.cd client && pnpm lint— not run; no client changes.Deployment Notes
validateBandschange only loosens validation (contiguous bands now accepted); every previously-valid pay profile remains valid. No schema, config, or API changes.Checklist
AGENTS.md,CLAUDE.md, and existing repository patterns.🤖 Generated with Claude Code
https://claude.ai/code/session_015houJkqb8SuqPW4YpLoWCq
Generated by Claude Code