Repository navigation
Add an order summary with discount and tax - #4
marginsystems wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Vortex: 1 issue to fix at a6bdd72 · 2/2 files reviewed
Actionable comment posted: 1
- 🟠 Important · `applyDiscount(itemsTotal, discountPercent)` returns `Math.round(amount * (100 - percent)) / 100`... ·
src/summary.js:6
🤖 Prompt for AI agents (1 finding)
Pull request mergestorm/sample-app#4: https://github.com/mergestorm/sample-app/pull/4 (head branch `order-summary`)
Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.
Findings to address:
1. In `@src/summary.js` (line 6, Important):
`applyDiscount(itemsTotal, discountPercent)` returns `Math.round(amount * (100 - percent)) / 100`, which is not an integer cent value when the product is not a multiple of 100. For example, an items total of 2001 cents with a 10% discount gives `discounted` = 1800.9, and `total` becomes fractional (1980.9) as well. This happens for any cart whose total times (100 - percent) is not divisible by 100, so it is common. Since the README uses integer cents, either round to whole cents here or fix `applyDiscount` to round after dividing (`Math.round(amount * (100 - percent) / 100)`). The added test only covers a round-number case and would not catch this.
|
|
||
| export function orderSummary(items, { discountPercent = 0, taxRatePercent = 0 } = {}) { | ||
| const itemsTotal = subtotal(items); | ||
| const discounted = applyDiscount(itemsTotal, discountPercent); |
There was a problem hiding this comment.
🟠 Important
applyDiscount(itemsTotal, discountPercent) returns Math.round(amount * (100 - percent)) / 100...
applyDiscount(itemsTotal, discountPercent) returns Math.round(amount * (100 - percent)) / 100, which is not an integer cent value when the product is not a multiple of 100. For example, an items total of 2001 cents with a 10% discount gives discounted = 1800.9, and total becomes fractional (1980.9) as well. This happens for any cart whose total times (100 - percent) is not divisible by 100, so it is common. Since the README uses integer cents, either round to whole cents here or fix applyDiscount to round after dividing (Math.round(amount * (100 - percent) / 100)). The added test only covers a round-number case and would not catch this.
🤖 Prompt for AI agents
Pull request mergestorm/sample-app#4: https://github.com/mergestorm/sample-app/pull/4 (head branch `order-summary`)
Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.
In `@src/summary.js` (line 6, Important):
`applyDiscount(itemsTotal, discountPercent)` returns `Math.round(amount * (100 - percent)) / 100`, which is not an integer cent value when the product is not a multiple of 100. For example, an items total of 2001 cents with a 10% discount gives `discounted` = 1800.9, and `total` becomes fractional (1980.9) as well. This happens for any cart whose total times (100 - percent) is not divisible by 100, so it is common. Since the README uses integer cents, either round to whole cents here or fix `applyDiscount` to round after dividing (`Math.round(amount * (100 - percent) / 100)`). The added test only covers a round-number case and would not catch this.
Builds on the sales tax PR: items total, discount, tax and grand total for checkout.