Repository navigation
Add shipping cost calculation #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) { | ||
| return 0; | ||
| } | ||
| const kilograms = Math.floor(weightGrams / 1000); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 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 🤖 Prompt for AI agents |
||
| return BASE_RATE + kilograms * PER_KG_RATE; | ||
| } | ||
| 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); | ||
| }); |
There was a problem hiding this comment.
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