Skip to content
Merged
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
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: test
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm test
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# sample-app
Sample repository for trying Mergestorm code review, stacks and the merge queue

A small shopping-cart library used to demonstrate Mergestorm: AI code review on pull requests, auto-fixes, stacked PRs and the merge queue.

Prices are integer cents. Run the tests with `npm test`.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "sample-app",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"test": "node --test"
}
}
14 changes: 14 additions & 0 deletions src/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function lineTotal(item) {
return item.price * item.quantity;
}

export function subtotal(items) {
return items.reduce((sum, item) => sum + lineTotal(item), 0);
}

export function applyDiscount(amount, percent) {
if (percent < 0 || percent > 100) {
throw new RangeError("percent must be between 0 and 100");
}
return Math.round(amount * (100 - percent)) / 100;
}
15 changes: 15 additions & 0 deletions src/cart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { applyDiscount, lineTotal, subtotal } from "./cart.js";

test("lineTotal multiplies price by quantity", () => {
assert.equal(lineTotal({ price: 250, quantity: 3 }), 750);
});

test("subtotal adds every line", () => {
assert.equal(subtotal([{ price: 100, quantity: 2 }, { price: 50, quantity: 1 }]), 250);
});

test("applyDiscount takes a percentage off", () => {
assert.equal(applyDiscount(1000, 10), 900);
});
Loading