Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/business.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion test/business.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down