From 3dd62133f6decf93373315181253291f30be4e4d Mon Sep 17 00:00:00 2001 From: Sergiy Dybskiy Date: Sat, 17 Oct 2026 15:17:48 -0400 Subject: [PATCH] Keep charging for express shipping on free-shipping orders Co-authored-by: Claude --- .../fixtures/demo-pr/cart-total.test.ts | 14 +++++++++++++- apps/pr-reviewer/fixtures/demo-pr/cart-total.ts | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts b/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts index ba32b97..c80a2e3 100644 --- a/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts +++ b/apps/pr-reviewer/fixtures/demo-pr/cart-total.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import { cartTotal } from './cart-total.ts'; +import { cartTotal, checkoutTotal } from './cart-total.ts'; describe('cartTotal', () => { it('returns 0 for an empty cart', () => { @@ -64,3 +64,15 @@ describe('cartTotal', () => { expect(cartTotal([{ price: 3, qty: 1_000_000 }])).toBe(3_000_000); }); }); + +describe('checkoutTotal', () => { + it('ships standard orders over the threshold for free', () => { + expect(checkoutTotal({ items: [{ price: 60, qty: 2 }], weightKg: 1, taxRate: 0 })).toBe(120); + }); + + it('still charges for express shipping over the threshold', () => { + expect( + checkoutTotal({ items: [{ price: 60, qty: 2 }], weightKg: 1, express: true, taxRate: 0 }), + ).toBe(132); + }); +}); diff --git a/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts b/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts index 79cec63..923c8d9 100644 --- a/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts +++ b/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts @@ -20,6 +20,8 @@ export type Cart = { discount?: { code: string; percent: number }; }; +const FREE_SHIPPING_THRESHOLD = 100; + function roundCents(amount: number): number { return Math.round(amount * 100) / 100; } @@ -27,7 +29,7 @@ function roundCents(amount: number): number { export function checkoutTotal(cart: Cart): number { const subtotal = cartTotal(cart.items); const shipping = shippingCost(cart.weightKg, cart.express); - const freeShipping = subtotal >= 100; + const freeShipping = subtotal >= FREE_SHIPPING_THRESHOLD && !cart.express; const shippingCharge = freeShipping ? 0 : shipping; const taxable = subtotal + shippingCharge; const tax = roundCents(taxable * cart.taxRate);