Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/shipping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const FREE_SHIPPING_THRESHOLD = 5000;
export const BASE_RATE = 499;
export const PER_KG_RATE = 150;

export function shippingCost(subtotalCents, weightGrams) {
if (subtotalCents > FREE_SHIPPING_THRESHOLD) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

return 0;
}
const kilograms = Math.floor(weightGrams / 1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 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.

return BASE_RATE + kilograms * PER_KG_RATE;
}
11 changes: 11 additions & 0 deletions src/shipping.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { shippingCost } from "./shipping.js";

test("orders over the threshold ship free", () => {
assert.equal(shippingCost(6000, 2500), 0);
});

test("small orders pay the base rate plus weight", () => {
assert.equal(shippingCost(1000, 2000), 799);
});
Loading