// Tests for the band-price minting tool's pure parts — the committed table // must stay the doc's matrix. node test/stripe-band-prices.test.mjs import assert from "node:assert/strict"; import { BAND_TABLE, priceLabel, netEURYear } from "../tools/stripe-band-prices.mjs"; let failures = 0; async function test(name, fn) { try { await fn(); console.log("PASS " + name); } catch (e) { console.log("FAIL " + name + " — " + (e && e.message)); failures++; } } await test("the table is the elevens ladder — 11 prices in all", () => { // 3 base + 8 band prices: nominally 3 × 4, minus Business's solidarity // (deliberately absent — a hardship price aimed at businesses never // parsed; Reduced at €5.50/person covers nonprofits/education). const tiers = Object.keys(BAND_TABLE); assert.deepEqual(tiers, ["family", "community", "business"]); const bandCount = tiers.reduce((n, t) => n + Object.keys(BAND_TABLE[t].bands).length, 0); assert.equal(tiers.length + bandCount, 11); assert.ok(!BAND_TABLE.business.bands.solidarity, "business must not offer solidarity"); // Spot-pin the ladder's load-bearing figures (decimal cents). assert.equal(BAND_TABLE.family.base, "550"); assert.equal(BAND_TABLE.community.base, "11"); assert.equal(BAND_TABLE.business.base, "1100"); assert.equal(BAND_TABLE.business.bands.supporter, "1500"); assert.equal(BAND_TABLE.business.bands.reduced, "550"); // The included-members identity: €0.11 × the 100-member floor = the €11 // minimum, and every band scales it (supporter €15, reduced €5.50). assert.equal(BAND_TABLE.community.minSeats, 100); assert.equal(Number(BAND_TABLE.community.base) * BAND_TABLE.community.minSeats, 1100); // Bands only ever use the fixed vocabulary; per-unit tiers name their unit. for (const t of tiers) { for (const b of Object.keys(BAND_TABLE[t].bands)) { assert.ok(["supporter", "reduced", "solidarity"].includes(b), `${t}: unknown band ${b}`); } assert.ok([null, "member", "seat"].includes(BAND_TABLE[t].unit)); } }); await test("priceLabel: whole euros bare, cents as a pair, sub-cent to three places", () => { assert.equal(priceLabel("550", null), "€5.50/year"); assert.equal(priceLabel("1100", "seat"), "€11/seat/year"); assert.equal(priceLabel("11", "member"), "€0.11/member/year"); assert.equal(priceLabel("5.5", "member"), "€0.055/member/year"); assert.equal(priceLabel("139900", null), "€1,399/year"); }); await test("netEURYear: the EEA fee model — flat absorbs the fixed fee, per-unit doesn't", () => { // Flat annual: one charge — €5.50 → 5.50 − 0.0825 − 0.25 = 5.168. assert.equal(netEURYear("550", null), 5.168); // Per-unit rates only carry the percentage; the €0.25 lands once per space. assert.equal(netEURYear("1100", "seat"), 10.835); assert.equal(netEURYear("11", "member"), 0.108); }); console.log(failures === 0 ? "\nALL PASSED" : `\n${failures} FAILED`); process.exit(failures === 0 ? 0 : 1);