← Legacy Nightmare

The invoicing engine

≈ 25 min150 pts max

Context

Ticket SUP-2291, high priority: “VAT computation crashes for international customers.” An order from a Swiss customer took the checkout down this morning.

The suspect: computeInvoice, written in 2019 by Gérard, who has since left the company. Nobody dares to touch it, but it is covered by a characterization test suite (tests/invoice.test.ts). Support added tests/export.test.ts, which reproduces the ticket. It is red.

Objective

  1. Turn tests/export.test.ts green: outside the EU, an invoice is issued without VAT (export mode).
  2. Do not break any test of tests/invoice.test.ts.
  3. Leave the code more readable than you found it: the cyclomatic complexity of computeInvoice must go down to 8 or less. The function keeps its name and stays in src/invoice.ts.

⌘S / Ctrl+S runs the tests. Submit once everything is green: each failed submission costs points.

  • Editor
  • Tests
  • Terminal
  • Cyclomatic complexity