BDD & TDD / Scenario
Boss: The Legacy Rescue
A 400-line pricing function with no tests, a hidden clock, a global config, and a live bug. Change its behavior without burning the shop down.
- Difficulty
- Boss
- Format
- Scenario
- Points
- 300
- Estimate
- 18 min
// MISSION BRIEF
Your Mission
Finance wants tax rounding changed in calculateOrderTotal, a 400-line legacy
function with zero tests, direct DB calls, Date.now() scattered through it,
and a global config object. Last "quick change" here caused a refund incident.
Plan the rescue like a professional: safety net first, seams second, behavior change last.
Scoring: boss fight. Five weighted decisions; the opening move counts double.
// FIRST CONTACT
Battle teaser
First artifact
pricing.js (shape of the beast)
Your first move, before touching a single line:
- ARewrite the function from the spec; the old code is unsalvageable
- BCharacterization (golden master) tests: feed a broad matrix of real-ish orders through the CURRENT code and pin its exact outputs, bugs included
- CFix the .005 rounding bug immediately, it is a known defect
- DRefactor the 400 lines into clean functions first, tests will be easier after
Answers, scoring, hints, and the full battle stay sealed.
// SKILL TAGS
legacy-codetddcharacterization-testsrefactoring