Repository navigation
Add shipping cost calculation - #2
marginsystems wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Vortex: 2 issues to fix at 1f08d9d · 2/2 files reviewed
Actionable comments posted: 2
- 🟠 Important · `if (subtotalCents > FREE_SHIPPING_THRESHOLD)` ·
src/shipping.js:6 - 🟠 Important · `Math.floor(weightGrams / 1000)` ·
src/shipping.js:9
🤖 Prompt for AI agents (2 findings)
Pull request mergestorm/sample-app#2: https://github.com/mergestorm/sample-app/pull/2 (head branch `shipping`)
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/shipping.js` (line 6, Important):
The description promises free shipping for orders of $50 or more, but the strict `>` charges shipping on an order of exactly 5000 cents. Any caller that passes a $50.00 subtotal gets the $4.99 base rate. Use `>=`, and add a test at exactly 5000.
2. In `@src/shipping.js` (line 9, Important):
The spec charges $1.50 per started kilogram, but floor only counts completed kilograms. A 2,500 g parcel is charged for 2 kg instead of 3, and any weight under 1,000 g adds nothing per-kg. Use `Math.ceil` so partial kilograms are charged. The existing 2,000 g test still passes under either rounding, so it does not catch this.
| export const PER_KG_RATE = 150; | ||
|
|
||
| export function shippingCost(subtotalCents, weightGrams) { | ||
| if (subtotalCents > FREE_SHIPPING_THRESHOLD) { |
There was a problem hiding this comment.
🟠 Important
if (subtotalCents > FREE_SHIPPING_THRESHOLD)
The description promises free shipping for orders of $50 or more, but the strict > charges shipping on an order of exactly 5000 cents. Any caller that passes a $50.00 subtotal gets the $4.99 base rate. Use >=, and add a test at exactly 5000.
🤖 Prompt for AI agents
Pull request mergestorm/sample-app#2: https://github.com/mergestorm/sample-app/pull/2 (head branch `shipping`)
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/shipping.js` (line 6, Important):
The description promises free shipping for orders of $50 or more, but the strict `>` charges shipping on an order of exactly 5000 cents. Any caller that passes a $50.00 subtotal gets the $4.99 base rate. Use `>=`, and add a test at exactly 5000.
| if (subtotalCents > FREE_SHIPPING_THRESHOLD) { | ||
| return 0; | ||
| } | ||
| const kilograms = Math.floor(weightGrams / 1000); |
There was a problem hiding this comment.
🟠 Important
Math.floor(weightGrams / 1000)
The spec charges $1.50 per started kilogram, but floor only counts completed kilograms. A 2,500 g parcel is charged for 2 kg instead of 3, and any weight under 1,000 g adds nothing per-kg. Use Math.ceil so partial kilograms are charged. The existing 2,000 g test still passes under either rounding, so it does not catch this.
🤖 Prompt for AI agents
Pull request mergestorm/sample-app#2: https://github.com/mergestorm/sample-app/pull/2 (head branch `shipping`)
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/shipping.js` (line 9, Important):
The spec charges $1.50 per started kilogram, but floor only counts completed kilograms. A 2,500 g parcel is charged for 2 kg instead of 3, and any weight under 1,000 g adds nothing per-kg. Use `Math.ceil` so partial kilograms are charged. The existing 2,000 g test still passes under either rounding, so it does not catch this.
Orders of $50 or more ship free, as the checkout page promises. Smaller orders pay a $4.99 base rate plus $1.50 per started kilogram.