diff --git a/src/business.js b/src/business.js index a8f0cd0..8a8a7bb 100644 --- a/src/business.js +++ b/src/business.js @@ -12,8 +12,7 @@ function calculateDiscountedPrice(price, discountPercent) { } function totalCart(items) { - // BUG: ignores quantity, so multi-quantity line items are undercounted. - return roundToCents(items.reduce((total, item) => total + item.price, 0)); + return roundToCents(items.reduce((total, item) => total + item.price * item.quantity, 0)); } function normalizeUsername(username) { diff --git a/test/business.test.js b/test/business.test.js index e84f4fa..5823775 100644 --- a/test/business.test.js +++ b/test/business.test.js @@ -22,7 +22,10 @@ test('cart total includes item quantities', () => { { name: 'Notebook', price: 2.5, quantity: 2 }, ]; - assert.equal(totalCart(items), 17); + const total = totalCart(items); + + assert.notEqual(total, 5.5); + assert.equal(total, 17); }); test('username normalization trims, lowercases, and collapses whitespace', () => {