test: characterize legacy totals and conversion arithmetic; add internal/totals (#20) #86

Merged
amiryahaya merged 1 commit from test/legacy-characterization into main 2026-10-23 11:19:06 +02:00
Owner

Closes #20.

What

Before building checkout (#26), the legacy money arithmetic was run and the new calculator was held to its numbers.

  • api/testdata/legacy/Characterize.cs (run with make legacy-golden, needs the .NET 10 SDK; output committed so CI does not need it): the legacy formulas copied verbatim, each block citing its source file, run on 34 scenarios and 195 price conversions with .NET decimal. It writes golden.json. The expected numbers come from .NET, not from my arithmetic.
  • internal/totals: a pure calculation core (no database, no HTTP) for ticket checkout, overstay, upgrades, wallet top-ups and tour-operator itineraries. Its tests read the golden file and compare every field, every ticket, every scenario.
  • ADR 0005 records the rules, the deliberate differences and the questions below.

What running the legacy code revealed

  1. The grand total is rounded to a whole currency unit (.5 and above goes up), after adding the unrounded tax. A customer pays KES 593 or USD 116, never cents; the printed parts need not add up. This is legacy behaviour and is kept.
  2. A fixed promo is per ticket and uncapped: a KES 50 voucher on a KES 30 ticket gave a grand total of -20.
  3. A stay unpriced on its first day was kept and charged for the priced days only: a 3-day ticket sold for 2 days. The last day alone decided.
  4. A wallet top-up paid by card is charged tax and the convenience fee. Wallet payments and upgrades are not.
  5. Tour operators pay price x days plus the fee (unless from the e-wallet), with no tax and no whole-unit rounding.
  6. Legacy converted-price rounding depended on the server's culture (ToString("F")): 2 decimals under en-US or in a container, 3 under en-MY, which is this team's own machines. The new exact conversion matches legacy in all 195 cases under the invariant culture.
  7. Promo MinimumOrder and IsAutoApply are stored and never enforced anywhere (for the promo module, #28).

Deliberate differences (each pinned by a test that also asserts the recorded legacy value)

fixed discount stops at the ticket's price; a stay is sold only if priced on every day; amounts are stored in cents (numeric(18,2)).

Questions for the project owner (also in ADR 0005)

  • Is the whole-unit grand total intended for USD too? (USD customers lose up to fifty cents either way.)
  • What culture did production run with? If 3 decimals, converted prices differed by a fraction of a cent.
  • Is charging tax and fee on a card wallet top-up wanted?

Standards review (docs/development-standards.md)

  • TDD: the golden-file test existed before the calculator. Three deliberate breaks (floor instead of round-half-up; no cap on a fixed discount; tax and fee charged on wallet payments) each fail for the intended reason.
  • SOLID / coupling: totals is pure, depends only on money, and defines its own small request and result types; no database, HTTP or other module.
  • Coverage: 95.2% total; totals 97.7%. make lint 0 issues. Security scans run on main after merge.

Known limits

  • CI cannot regenerate the golden file (no .NET). If the harness changes, rerun make legacy-golden and commit the result.
  • The harness holds the arithmetic, not the whole legacy service (it needs a database and the full solution), so price lookup and settings reads are inputs here.

🤖 Generated with Claude Code

Closes #20. ## What Before building checkout (#26), the legacy money arithmetic was run and the new calculator was held to its numbers. - **`api/testdata/legacy/Characterize.cs`** (run with `make legacy-golden`, needs the .NET 10 SDK; output committed so CI does not need it): the legacy formulas copied **verbatim**, each block citing its source file, run on **34 scenarios and 195 price conversions** with .NET `decimal`. It writes `golden.json`. The expected numbers come from .NET, not from my arithmetic. - **`internal/totals`**: a pure calculation core (no database, no HTTP) for ticket checkout, overstay, upgrades, wallet top-ups and tour-operator itineraries. Its tests read the golden file and compare every field, every ticket, every scenario. - **ADR 0005** records the rules, the deliberate differences and the questions below. ## What running the legacy code revealed 1. **The grand total is rounded to a whole currency unit** (`.5` and above goes up), after adding the *unrounded* tax. A customer pays KES 593 or USD 116, never cents; the printed parts need not add up. This is legacy behaviour and is kept. 2. **A fixed promo is per ticket and uncapped**: a KES 50 voucher on a KES 30 ticket gave a grand total of **-20**. 3. **A stay unpriced on its first day was kept and charged for the priced days only**: a 3-day ticket sold for 2 days. The last day alone decided. 4. **A wallet top-up paid by card is charged tax and the convenience fee.** Wallet payments and upgrades are not. 5. **Tour operators** pay price x days plus the fee (unless from the e-wallet), with no tax and no whole-unit rounding. 6. **Legacy converted-price rounding depended on the server's culture** (`ToString("F")`): 2 decimals under en-US or in a container, 3 under en-MY, which is this team's own machines. The new exact conversion matches legacy in **all 195 cases** under the invariant culture. 7. Promo `MinimumOrder` and `IsAutoApply` are stored and never enforced anywhere (for the promo module, #28). ## Deliberate differences (each pinned by a test that also asserts the recorded legacy value) fixed discount stops at the ticket's price; a stay is sold only if priced on every day; amounts are stored in cents (`numeric(18,2)`). ## Questions for the project owner (also in ADR 0005) - Is the whole-unit grand total intended for **USD** too? (USD customers lose up to fifty cents either way.) - What culture did production run with? If 3 decimals, converted prices differed by a fraction of a cent. - Is charging tax and fee on a card wallet top-up wanted? ## Standards review (docs/development-standards.md) - **TDD**: the golden-file test existed before the calculator. Three deliberate breaks (floor instead of round-half-up; no cap on a fixed discount; tax and fee charged on wallet payments) each fail for the intended reason. - **SOLID / coupling**: `totals` is pure, depends only on `money`, and defines its own small request and result types; no database, HTTP or other module. - **Coverage**: 95.2% total; totals 97.7%. `make lint` 0 issues. Security scans run on `main` after merge. ## Known limits - CI cannot regenerate the golden file (no .NET). If the harness changes, rerun `make legacy-golden` and commit the result. - The harness holds the *arithmetic*, not the whole legacy service (it needs a database and the full solution), so price lookup and settings reads are inputs here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test: characterize the legacy totals and conversion arithmetic; add internal/totals (closes #20)
All checks were successful
ci / changes (pull_request) Successful in 7s
ci / api (pull_request) Successful in 11m41s
ci / ci-gate (pull_request) Successful in 4s
68f0e7c9a8
api/testdata/legacy/Characterize.cs holds the legacy formulas verbatim, runs 34 scenarios and 195 price
conversions with .NET decimal, and writes the committed golden.json. internal/totals is the pure calculation
core for checkout, held to those numbers; two legacy defects are fixed on purpose and pinned against the
recorded legacy value. ADR 0005 records the rules and the questions for the owner.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!86
No description provided.