Developer Builds Immutable Invoice API Where Corrections Create New Documents
A developer published a TypeScript/Express REST API that enforces a strict invoice lifecycle, making finalized invoices immutable and handling corrections by issuing new replacement documents rather than editing originals. The system uses four states — draft, issued, canceled, and replaced — with replacement operations wrapped in a single database transaction to prevent inconsistent states. Despite achieving over 97% test coverage across 56 tests, two real bugs slipped through undetected by automated testing. One bug involved incorrect currency division that rendered Vietnamese Dong amounts as hundredths of their actual value on generated PDFs, a mistake the tests missed because both the code and expected test values shared the same flawed assumption. The incident highlights a key limitation of unit testing: automated tests confirm code behaves consistently with developer expectations, but cannot catch bugs rooted in incorrect assumptions themselves.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in