diff --git a/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts b/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts index ba32b97..213a945 100644 --- a/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts +++ b/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts @@ -63,4 +63,13 @@ describe('cartTotal', () => { it('handles large quantities', () => { expect(cartTotal([{ price: 3, qty: 1_000_000 }])).toBe(3_000_000); }); + + it('rounds each line to whole cents', () => { + expect( + cartTotal([ + { price: 33.3, qty: 3 }, + { price: 10.4, qty: 1 }, + ]), + ).toBe(110); + }); }); diff --git a/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts b/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts index c694360..d80aa50 100644 --- a/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts +++ b/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts @@ -4,7 +4,7 @@ export function cartTotal(items: { price: number; qty: number }[]): number { if (items[i].qty < 0) { throw new RangeError(`Negative quantity for item ${i}`); } - total += items[i].price * items[i].qty; + total += Math.round(items[i].price * items[i].qty); } return total; }