Saboteur Shop: try the bugs
These are the builds Saboteur tests: the correct app, and the same app with exactly one planted bug each. Open one, use it like a customer, and see whether you would have noticed. Saboteur's Kane CLI runs used local builds of the same code.
Test account: demo@saboteur.shop / sabotage123. Discount code: SAVE10.
No planted bug. Everything works as described.
Customer is charged less than the items in the cart: the last line item is left out of the subtotal and total
The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 7e943c2..e2d8d44 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -22,7 +22,7 @@ export function lineTotal(line: CartLine): number {
export function subtotal(lines: CartLine[]): number {
let sum = 0;
- for (let i = 0; i < lines.length; i++) {
+ for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i];
if (line) sum += lineTotal(line);
}
Customer cannot increase the quantity of an item with the + button
The patch
diff --git a/src/components/QtyStepper.tsx b/src/components/QtyStepper.tsx
index 4e709fc..129a6fd 100644
--- a/src/components/QtyStepper.tsx
+++ b/src/components/QtyStepper.tsx
@@ -24,7 +24,7 @@ export function QtyStepper({ value, onChange, label }: Props) {
type="button"
aria-label={`Increase quantity of ${label}`}
disabled={value >= MAX_QTY}
- onClick={() => onChange(value + 1)}
+ onClick={() => onChange(value)}
>
+
</button>
Customer gets a much smaller discount than SAVE10 promises
The patch
diff --git a/src/lib/discount.ts b/src/lib/discount.ts
index 4898229..ebaf7f6 100644
--- a/src/lib/discount.ts
+++ b/src/lib/discount.ts
@@ -1,5 +1,5 @@
const CODES: Record<string, number> = {
- SAVE10: 10,
+ SAVE10: 1,
};
export function discountPercent(code: string | null): number | null {
Shop loses the $5.00 shipping fee on small orders; total is $5.00 too low
The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 7e943c2..44627a6 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -31,7 +31,7 @@ export function subtotal(lines: CartLine[]): number {
export function shipping(afterDiscountCents: number, hasItems: boolean): number {
if (!hasItems) return 0;
- return afterDiscountCents < FREE_SHIPPING_FROM_CENTS ? SHIPPING_CENTS : 0;
+ return 0;
}
export function totals(lines: CartLine[], code: string | null): Totals {
Orders are placed with an email address nobody can reply to
The patch
diff --git a/src/lib/validate.ts b/src/lib/validate.ts
index 3a7b3db..cdfb863 100644
--- a/src/lib/validate.ts
+++ b/src/lib/validate.ts
@@ -1,4 +1,4 @@
-const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+const EMAIL = /^[^\s@]+@/;
export function isValidEmail(value: string): boolean {
return EMAIL.test(value.trim());
Customer clicks Remove on one item and a different item disappears
The patch
diff --git a/src/state/cart.tsx b/src/state/cart.tsx
index ba15605..a2a3b91 100644
--- a/src/state/cart.tsx
+++ b/src/state/cart.tsx
@@ -41,7 +41,7 @@ export function CartProvider({ children }: { children: ReactNode }) {
}));
},
remove(slug) {
- setState((s) => ({ ...s, lines: s.lines.filter((l) => l.slug !== slug) }));
+ setState((s) => ({ ...s, lines: s.lines.slice(1) }));
},
applyCode(code) {
setState((s) => ({ ...s, code }));
Customer can order the Wool Beanie, which is out of stock
The patch
diff --git a/src/pages/Product.tsx b/src/pages/Product.tsx
index 8d13aac..853ca0b 100644
--- a/src/pages/Product.tsx
+++ b/src/pages/Product.tsx
@@ -30,7 +30,7 @@ export function Product() {
<QtyStepper value={qty} onChange={setQty} label={product.name} />
<button
type="button"
- disabled={!product.inStock}
+ disabled={false}
onClick={() => {
add(product.slug, qty);
setAdded(true);
Customer has no order number to quote to support
The patch
diff --git a/src/pages/OrderConfirmed.tsx b/src/pages/OrderConfirmed.tsx
index 151585a..d7a90e2 100644
--- a/src/pages/OrderConfirmed.tsx
+++ b/src/pages/OrderConfirmed.tsx
@@ -19,7 +19,7 @@ export function OrderConfirmed() {
return (
<main className="confirmed">
<h1>Thank you for your order</h1>
- <p className="order-number">Order number: {order.id}</p>
+ <p className="order-number">Order number: {''}</p>
<ul>
{order.lines.map((l) => (
<li key={l.slug}>
After signing in the customer lands on the home page, not My account
The patch
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx
index 585578f..4fbfb62 100644
--- a/src/pages/Login.tsx
+++ b/src/pages/Login.tsx
@@ -12,7 +12,7 @@ export function Login() {
function submit(e: FormEvent) {
e.preventDefault();
if (auth.signIn(email, password)) {
- navigate('/account');
+ navigate('/');
} else {
setError('Email or password is incorrect');
}
Customer loses everything in the cart when the page reloads
The patch
diff --git a/src/state/cart.tsx b/src/state/cart.tsx
index ba15605..c69c32a 100644
--- a/src/state/cart.tsx
+++ b/src/state/cart.tsx
@@ -17,7 +17,7 @@ type CartApi = CartState & {
const CartContext = createContext<CartApi | null>(null);
export function CartProvider({ children }: { children: ReactNode }) {
- const [state, setState] = useState<CartState>(() => load<CartState>(KEY, { lines: [], code: null }));
+ const [state, setState] = useState<CartState>(() => ({ lines: [], code: null }));
useEffect(() => {
save(KEY, state);
The header cart badge shows how many different products are in the cart, not how many items. Adding the same product twice still shows 1, so shoppers lose track of how many items they have.
The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 76ed184..6607943 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -42,7 +42,7 @@ export function totals(lines: CartLine[], code: string | null): Totals {
}
export function itemCount(lines: CartLine[]): number {
- return lines.reduce((n, l) => n + l.qty, 0);
+ return lines.reduce((n, l) => n + (l.qty > 0 ? 1 : 0), 0);
}
export function clampQty(qty: number): number {
An order whose subtotal is $50 or more but drops below $50 after SAVE10 wrongly gets free shipping, so the customer is undercharged by $5.00.
The patch
diff --git a/src/lib/cart.ts b/src/lib/cart.ts
index 76ed184..fef1873 100644
--- a/src/lib/cart.ts
+++ b/src/lib/cart.ts
@@ -37,7 +37,7 @@ export function shipping(afterDiscountCents: number, hasItems: boolean): number
export function totals(lines: CartLine[], code: string | null): Totals {
const sub = subtotal(lines);
const discount = discountCents(sub, code);
- const ship = shipping(sub - discount, lines.length > 0);
+ const ship = shipping(sub, lines.length > 0);
return { subtotal: sub, discount, shipping: ship, total: sub - discount + ship };
}
After pressing "Sign out" on the account page, the header still shows "Signed in as demo@saboteur.shop", so the customer appears to still be logged in until they refresh the page.
The patch
diff --git a/src/state/auth.tsx b/src/state/auth.tsx
index 211e79e..b68e70e 100644
--- a/src/state/auth.tsx
+++ b/src/state/auth.tsx
@@ -27,7 +27,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
return ok;
},
signOut() {
- setEmail(null);
+ setEmail(email);
save(KEY, null);
},
};