The Checkout Meltdown — JavaScript Bug Hunt
Shoppers on Lumen Store are seeing wildly wrong totals at checkout the moment they apply a coupon.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Easy
- Modelled on: Classic e-commerce
- Visible tests: subtotal multiplies price by quantity; 20% coupon discounts the subtotal once; no coupon means no discount
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-1 (priority: Critical)
- Ticket: BUG-2107
- Reported by: support (14 duplicate tickets)
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- subtotal multiplies price by quantity — subtotal for 2 × $40.00: expected 80 but got 40
- 20% coupon discounts the subtotal once — discount for 20% of $80.00: expected 16 but got 8
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Shoppers on Lumen Store are seeing wildly wrong totals at checkout the moment they apply a coupon. The cart state itself is fine — the bug lives somewhere in the pure calculation layer that the React checkout page calls.
You have three files. Only calculateTotals.js is editable — the formatter and constants are shared with other teams and locked.
Fix the calculation so every test in the suite passes.
Bug report
BUG-2107 · Priority: Critical · Reported by: support (14 duplicate tickets)
Steps to reproduce:
- Add "Desk Lamp" ($40.00) ×2 to the cart
- Apply coupon SAVE20 (20% off)
- Observe the order summary
Expected: subtotal $80.00, discount $16.00, total $69.12 (with 8% tax) Actual: discount shows $64.00 and the total goes NEGATIVE on larger carts.
Also flagged by QA: a 100%-off promo coupon produces a total of exactly $0.00 in staging but a small positive number in prod.
Logs
console.error: [checkout] total sanity check failed { subtotal: 80, discount: 64, total: -1.28 }
console.error: [checkout] total sanity check failed { subtotal: 210, discount: 168, total: -3.36 }The code as shipped
src/cart/calculateTotals.js (editable)
var constants = require("./constants");
// items: [{ name, priceCents, quantity }]
// coupon: { rate } where rate is 0..1 (0.2 = 20% off) — or null
exports.calculateTotals = function (items, coupon) {
var subtotalCents = 0;
for (var i = 0; i < items.length; i++) {
subtotalCents += items[i].priceCents;
}
var rate = coupon ? coupon.rate : 0;
if (rate > constants.MAX_DISCOUNT_RATE) rate = constants.MAX_DISCOUNT_RATE;
var discountCents = Math.round(subtotalCents * rate * items.length);
var taxedCents = Math.round((subtotalCents - discountCents) * (1 + constants.TAX_RATE));
return {
subtotal: subtotalCents / 100,
discount: discountCents / 100,
total: taxedCents / 100,
};
};
Read-only context: src/cart/constants.js, src/cart/formatPrice.js.
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.