Public: anyone can read this; the crew can change it.

Every price on /pricing, the plan row and the MCP is formatted by one function, with a test over the three #15694

opened this

Check · Review · Land · Live — No review yet. Next: reviewer, no review yet.

Ready to land

torque/forge:torque/15661-every-price-on-pricing-the-plan-row-and → main 13 commits fork

Review

Sign in to review this change.
20 files changed +176 −43
src/billing/money.ts added +34
@@ -0,0 +1,34 @@
1 /**
2 * Money in words, the one formatter every price on the forge goes through: /pricing, the Plan row,
3 * the billing MCP answer, the terminal and the plan-change line. An amount is an integer count of
4 * the currency's minor units ("1900" USD is $19.00); a float never enters, so nothing rounds twice.
5 * The minor-unit exponent is ISO 4217's: 2 for USD/EUR/GBP, 0 for JPY and KRW, 3 for KWD and BHD.
6 */
7
8 export type Currency = string;
9
10 /** ISO 4217 minor-unit exponents for the currencies that are not 2. */
11 const EXPONENT: Readonly<Record<string, number>> = { JPY: 0, KRW: 0, VND: 0, CLP: 0, ISK: 0, KWD: 3, BHD: 3, JOD: 3, OMR: 3, TND: 3 };
12 const SYMBOL: Readonly<Record<string, string>> = { USD: "$", EUR: "€", GBP: "£", JPY: "¥" };
13
14 /** Digits after the point for a currency. */
15 export const exponentOf = (currency: Currency): number => EXPONENT[currency] ?? 2;
16
17 /** Dollars a plan is set in, as integer cents; rounded once, here. */
18 export const centsOfUsd = (usd: number): number => Math.round(usd * 100);
19
20 /** "$12.00", "€5.50", "¥1,200", "CHF 7.00": the amount with its currency, never a float. */
21 export function moneyWords(minor: number, currency: Currency = "USD"): string {
22 if (!Number.isSafeInteger(minor) || minor < 0) throw new RangeError("money is a whole number of minor units, not below zero");
23 const exp = exponentOf(currency);
24 const base = 10 ** exp;
25 const major = Math.floor(minor / base).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
26 const frac = exp === 0 ? "" : `.${String(minor % base).padStart(exp, "0")}`;
27 const sym = SYMBOL[currency];
28 return sym !== undefined ? `${sym}${major}${frac}` : `${currency} ${major}${frac}`;
29 }
30
31 /** "$12.00 / month", or "Free" at nothing. */
32 export function perMonthWords(minor: number, currency: Currency = "USD"): string {
33 return minor === 0 ? "Free" : `${moneyWords(minor, currency)} / month`;
34 }
src/billing/plan_change.ts +5 −6
@@ -7,6 +7,7 @@
77 */
88
99 import type { Plan } from "../settings/plans.ts";
10 import { centsOfUsd, perMonthWords } from "./money.ts";
1011
1112 export interface PlanChange {
1213 readonly forge: string;
@@ -21,19 +22,17 @@ export interface PlanChange {
2122 /** The price in cents of a plan named by key, or by the size it sits on; unknown reads as 0. */
2223 export function centsFor(plans: readonly Plan[], name: string): number {
2324 const p = plans.find((q) => q.key === name) ?? plans.find((q) => q.size === name);
24 return p === undefined ? 0 : Math.round(p.priceUsd * 100);
25 return p === undefined ? 0 : centsOfUsd(p.priceUsd);
2526 }
2627
2728 export function previewChange(plans: readonly Plan[], forge: string, from: string, to: string, now: Date): PlanChange {
2829 return { forge, from, to, cents: centsFor(plans, to), starts: now.toISOString().slice(0, 10) };
2930 }
3031
31 /** Whole cents as "$19.00 a month" or "Free". */
32 export function perMonth(cents: number): string {
33 return cents === 0 ? "Free" : `$${Math.floor(cents / 100)}.${String(cents % 100).padStart(2, "0")} a month`;
34 }
32 /** Whole cents as "$19.00 / month" or "Free" (`money.ts`). */
33 export const perMonth = (cents: number): string => perMonthWords(cents);
3534
36 /** The one line: "small → medium: $49.00 a month, starts 2026-11-15". */
35 /** The one line: "small → medium: $49.00 / month, starts 2026-11-15". */
3736 export function changeLine(c: PlanChange): string {
3837 return `${c.from} → ${c.to}: ${perMonth(c.cents)}, starts ${c.starts}`;
3938 }
src/billing/plan_words.ts +6 −5
@@ -11,10 +11,11 @@ import type { BillingLinks } from "../settings/billing.ts";
1111 import { sizeWords } from "../settings/billing.ts";
1212 import { LIMITS } from "../settings/limits.ts";
1313 import type { Plan } from "../settings/plans.ts";
14 import { centsOfUsd, perMonthWords } from "./money.ts";
1415
1516 export interface PlanWords {
1617 readonly name: string;
17 /** "Free" or "$19 a month". */
18 /** "Free" or "$19.00 / month" (`money.ts`). */
1819 readonly price: string;
1920 /**
2021 * The machine, the plan's own line, then its credit: "1 CPU, 2 GB memory, 2 GB disk. Stays
@@ -56,10 +57,10 @@ export function creditWords(p: Pick<Plan, "priceUsd" | "creditUsd">, startUsd: n
5657 }
5758
5859 /**
59 * A monthly price in words, "Free" or "$19 a month": the one formatter /pricing, the terminal and
60 * receipts share.
60 * A monthly price in words, "Free" or "$19.00 / month": the one formatter /pricing, the terminal
61 * and receipts share, made by billing/money.ts.
6162 */
62 export const monthlyPrice = (usd: number): string => (usd === 0 ? "Free" : `$${usd} a month`);
63 export const monthlyPrice = (usd: number): string => perMonthWords(centsOfUsd(usd));
6364
6465 export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0, askUsd: number = ASK_USD): PlanWords {
6566 const free = p.priceUsd === 0;
@@ -88,7 +89,7 @@ export const AFTER_PAYMENT = AFTER_PAYMENT_STEPS.join(" ");
8889 /** What a stranger reads first: the cheapest paid plan, priced from the plans, never typed. */
8990 export function priceLine(plans: readonly Plan[]): string {
9091 const paid = plans.filter((p) => p.priceUsd > 0).map((p) => p.priceUsd);
91 return paid.length === 0 ? "A forge is free" : `A forge is $${Math.min(...paid)} a month`;
92 return paid.length === 0 ? "A forge is free" : `A forge is ${perMonthWords(centsOfUsd(Math.min(...paid)))}`;
9293 }
9394
9495 /** Where the home's one button and the terminal's pointer send a person for a hosted forge. */
src/settings/plans.ts +2 −1
@@ -10,6 +10,7 @@
1010 */
1111
1212 import type { Database } from "bun:sqlite";
13 import { centsOfUsd, perMonthWords } from "../billing/money.ts";
1314 import { err, ok, type Result } from "../kernel/result.ts";
1415 import { isSize, SIZES, type Size } from "../spawn/sizes.ts";
1516 import { writeSetting } from "./limits.ts";
@@ -146,7 +147,7 @@ export function getPlan(db: Database, key: string): Plan | undefined {
146147 }
147148
148149 const words = (plans: readonly Plan[]): string =>
149 plans.map((p) => `${p.key} ${p.size} $${p.priceUsd}/$${p.creditUsd}×${p.forges}`).join(", ");
150 plans.map((p) => `${p.key} ${p.size} ${perMonthWords(centsOfUsd(p.priceUsd))}, $${p.creditUsd} credit ×${p.forges}`).join(", ");
150151
151152 /** Replace the plans (validated by the caller) and keep the change. */
152153 export function setPlans(db: Database, plans: readonly Plan[], actorId: string): void {
src/tui/screens/plans.ts +3 −2
@@ -8,6 +8,7 @@
88 */
99
1010 import { editPlans, readPlans } from "../../actions/plans.ts";
11 import { centsOfUsd, perMonthWords } from "../../billing/money.ts";
1112 import type { Plan } from "../../settings/plans.ts";
1213 import type { Ctx, Screen } from "../app/app.ts";
1314 import { binding } from "../app/keys.ts";
@@ -59,7 +60,7 @@ export function plansScreen(f: Session, ctx: Ctx): Screen {
5960 promptScreen(ctx, screen, {
6061 title: plan.key,
6162 label: ASK,
62 hint: `now ${plan.size} · $${plan.priceUsd}/mo · $${plan.creditUsd} crew credit · ${plan.forges} forges`,
63 hint: `now ${plan.size} · ${perMonthWords(centsOfUsd(plan.priceUsd))} · $${plan.creditUsd} crew credit · ${plan.forges} forges`,
6364 onSubmit: (raw) => {
6465 const edit = parseEdit(raw);
6566 if (typeof edit === "string") return edit;
@@ -83,7 +84,7 @@ export function plansScreen(f: Session, ctx: Ctx): Screen {
8384 const rows = (plans: readonly Plan[]): ListRow[] =>
8485 plans.map((p) => ({
8586 title: `${p.key} · ${p.name}`,
86 secondary: `${p.size} · $${p.priceUsd}/mo · $${p.creditUsd} crew credit · ${p.forges} forges`,
87 secondary: `${p.size} · ${perMonthWords(centsOfUsd(p.priceUsd))} · $${p.creditUsd} crew credit · ${p.forges} forges`,
8788 meta: p.says,
8889 }));
8990
src/tui/screens/pricing.ts +2 −1
@@ -10,6 +10,7 @@
1010 */
1111
1212 import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder } from "../../actions/order.ts";
13 import { centsOfUsd, perMonthWords } from "../../billing/money.ts";
1314 import { AFTER_PAYMENT_STEPS, priceLine } from "../../billing/plan_words.ts";
1415 import { receiptFacts } from "../../billing/receipt.ts";
1516 import { lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts";
@@ -156,7 +157,7 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen {
156157 for (const p of plans()) {
157158 const isPaid = p.key !== FREE && p.priceUsd > 0;
158159 const mark = isPaid && list[at]?.key === p.key ? "▸" : " ";
159 line(`${mark} ${p.name.padEnd(12)} ${isPaid ? `$${p.priceUsd} a month` : "free"} ${sizeWords(p.size)}`, isPaid ? c.fg : c.mutedFg);
160 line(`${mark} ${p.name.padEnd(12)} ${isPaid ? perMonthWords(centsOfUsd(p.priceUsd)) : "free"} ${sizeWords(p.size)}`, isPaid ? c.fg : c.mutedFg);
160161 }
161162 y++;
162163 const base = y - area.y;
src/web/plan_row.ts +3 −1
@@ -10,6 +10,7 @@
1010 */
1111
1212 import { noticeOf, type PlanNotice } from "../billing/notice.ts";
13 import { centsOfUsd, perMonthWords } from "../billing/money.ts";
1314 import { fundingOf } from "../spawn/funding.ts";
1415 import { uncountedWords } from "../actions/crew_means.ts";
1516 import { creditWords } from "../billing/plan_words.ts";
@@ -51,8 +52,9 @@ export function planLine(dataDir: string, now: number = Date.now()): string | un
5152 // when the host lent no cap.
5253 const cap = f?.capUsd ?? n.creditUsd;
5354 const credit = cap > 0 && f?.spentUsd != null ? ` ${usdWords(f.spentUsd)} of ${usdWords(cap)} crew credit used this month.${uncountedWords(f.uncountedUsd ?? 0)}` : "";
55 const price = n.priceUsd > 0 ? ` ${perMonthWords(centsOfUsd(n.priceUsd))}.` : "";
5456 const buys = n.priceUsd > 0 && n.creditUsd > 0 ? ` ${creditWords(n, 0, n.askUsd)}` : "";
55 return `${n.name}${size}. ${statusWords({ ...n, status: statusNow(n, now) })}.${credit}${buys}`;
57 return `${n.name}${size}.${price} ${statusWords({ ...n, status: statusNow(n, now) })}.${credit}${buys}`;
5658 }
5759
5860 /**
test/billing-order-receipt.test.ts +5 −5
@@ -51,7 +51,7 @@ afterAll(async () => {
5151
5252 describe("the receipt", () => {
5353 test("words the amount and the date from the stored order", () => {
54 expect(receiptAmount({ priceUsd: 19 })).toBe("$19 a month");
54 expect(receiptAmount({ priceUsd: 19 })).toBe("$19.00 / month");
5555 expect(receiptAmount({ priceUsd: 0 })).toBe("not recorded for this order");
5656 expect(receiptDate(DAY)).toBe("2026-11-03");
5757 });
@@ -62,7 +62,7 @@ describe("the receipt", () => {
6262 expect(res.status).toBe(200);
6363 const text = await res.text();
6464 expect(text).toMatch(/data-fact="plan">[^<]*Small/i);
65 expect(text).toContain('data-fact="amount">$19 a month');
65 expect(text).toContain('data-fact="amount">$19.00 / month');
6666 expect(text).toContain('data-fact="date">2026-11-03');
6767 expect(text).toContain('data-fact="forge">shopfront');
6868 });
@@ -83,8 +83,8 @@ describe("the receipt", () => {
8383 test("the amount is the stored price, not today's plan", async () => {
8484 const o = order("oldprice", "spawned", 7);
8585 const text = await (await fetch(`${base}/pricing/orders/${o.id}`, { headers: { cookie: o.cookie } })).text();
86 expect(text).toContain("$7 a month");
87 expect(text).not.toContain("$19 a month");
86 expect(text).toContain("$7.00 / month");
87 expect(text).not.toContain("$19.00 / month");
8888 });
8989
9090 test("only the buyer or an admin reads it; everyone else, a pending order and a bad id get 404", async () => {
@@ -129,7 +129,7 @@ describe("the receipt", () => {
129129 const text = await res.text();
130130 expect(text).toStartWith("<!doctype html>");
131131 expect(text).toContain("@media print");
132 expect(text).toContain("$19 a month");
132 expect(text).toContain("$19.00 / month");
133133 expect(text).toContain("2026-11-03");
134134 expect(text).toContain("download1");
135135 expect(text).not.toContain("<script");
test/billing-plan-change.test.ts +2 −2
@@ -13,8 +13,8 @@ test("price is whole cents: $19 → 1900, $19.99 → 1999, free → 0", () => {
1313
1414 test("the line says from, to, dollars and cents a month, and the UTC day", () => {
1515 const c = previewChange(DEFAULT_PLANS, "kid", "small", "medium", new Date("2026-11-15T23:59:59Z"));
16 expect(changeLine(c)).toBe("small → medium: $49.00 a month, starts 2026-11-15");
17 expect(perMonth(1905)).toBe("$19.05 a month");
16 expect(changeLine(c)).toBe("small → medium: $49.00 / month, starts 2026-11-15");
17 expect(perMonth(1905)).toBe("$19.05 / month");
1818 expect(perMonth(0)).toBe("Free");
1919 });
2020
test/billing-tui.test.ts +1 −1
@@ -98,7 +98,7 @@ test("the confirm shows the change in one line: from, to, amount a month, start
9898 tui.dispatch(key(to === "medium" ? "m" : "s"));
9999 await settleApp(tui);
100100 const price = to === "medium" ? "$49.00" : "$19.00";
101 expect(tui.screen.toText()).toContain(`${from} → ${to}: ${price} a month, starts ${new Date().toISOString().slice(0, 10)}`);
101 expect(tui.screen.toText()).toContain(`${from} → ${to}: ${price} / month, starts ${new Date().toISOString().slice(0, 10)}`);
102102 tui.dispatch(key("n"));
103103 await settleApp(tui);
104104 tui.stop?.();
test/billing.test.ts +1 −1
@@ -157,7 +157,7 @@ describe("billing seam", () => {
157157 const res = await send("GET", `/settings/billing/change?forge=kid&plan=${to}`, admin);
158158 expect(res.status).toBe(200);
159159 const text = await res.text();
160 const price = to === "medium" ? "$49.00 a month" : "$149.00 a month";
160 const price = to === "medium" ? "$49.00 / month" : "$149.00 / month";
161161 expect(text).toContain(`${from} → ${to}: ${price}, starts ${today()}`);
162162 expect(text.split(`${from} → ${to}`).length).toBe(2); // said once
163163 expect(text).not.toContain("Assumptions");
test/money-words.test.ts added +93
@@ -0,0 +1,93 @@
1 /**
2 * One formatter for every price (#15661): `billing/money.ts` by hand, then the same plan on
3 * /pricing, the owner's Plan row and the `here` MCP answer in the same words, and no template
4 * outside the module that formats a plan's price itself.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { centsOfUsd, moneyWords, perMonthWords } from "../src/billing/money.ts";
12 import { planWords } from "../src/billing/plan_words.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { DEFAULT_PLANS } from "../src/settings/plans.ts";
15 import { planLine } from "../src/web/plan_row.ts";
16 import { seedAdmin } from "./helpers/admin.ts";
17 import { tokenFor } from "./helpers/tokens.ts";
18
19 test("by hand: minor units in, the currency's own digits out", () => {
20 expect(moneyWords(1200)).toBe("$12.00");
21 expect(moneyWords(5)).toBe("$0.05");
22 expect(moneyWords(123_456_789)).toBe("$1,234,567.89");
23 expect(moneyWords(550, "EUR")).toBe("€5.50");
24 expect(moneyWords(1200, "JPY")).toBe("¥1,200"); // exponent 0: no point
25 expect(moneyWords(1234, "KWD")).toBe("KWD 1.234"); // exponent 3
26 expect(moneyWords(700, "CHF")).toBe("CHF 7.00");
27 expect(perMonthWords(1200)).toBe("$12.00 / month");
28 expect(perMonthWords(0)).toBe("Free");
29 });
30
31 test("an amount is a whole count of minor units, never a float or a debt", () => {
32 expect(() => moneyWords(12.5)).toThrow(RangeError);
33 expect(() => moneyWords(-1)).toThrow(RangeError);
34 expect(() => moneyWords(Number.NaN)).toThrow(RangeError);
35 expect(centsOfUsd(19.99)).toBe(1999);
36 expect(centsOfUsd(0.29)).toBe(29); // 0.29 * 100 is 28.999999999999996 as a float
37 });
38
39 let dir = "";
40 let app: App, servers: Servers;
41 let admin = "";
42
43 beforeAll(async () => {
44 dir = await mkdtemp(join(tmpdir(), "forge-money-"));
45 app = createApp({ dataDir: dir, port: 0 });
46 servers = await serve(app);
47 await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" });
48 admin = tokenFor(app, "alice", "rw");
49 });
50 afterAll(async () => {
51 servers.stop();
52 app.close();
53 await rm(dir, { recursive: true, force: true });
54 });
55
56 test("the same plan reads the same on /pricing, the Plan row and the MCP", async () => {
57 const small = DEFAULT_PLANS.find((p) => p.key === "small")!;
58 const price = perMonthWords(centsOfUsd(small.priceUsd));
59 expect(price).toBe("$19.00 / month");
60 expect(planWords(small).price).toBe(price);
61
62 const pricing = await (await fetch(`${servers.url}/pricing`)).text();
63 expect(pricing).toContain(`>${price}<`);
64
65 await writeFile(join(dir, "plan.json"), JSON.stringify({ name: small.name, size: small.size, priceUsd: small.priceUsd, creditUsd: small.creditUsd, status: "active" }));
66 expect(planLine(dir)).toContain(price);
67
68 const res = await fetch(`${servers.url}/mcp`, {
69 method: "POST",
70 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${admin}` },
71 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "here", arguments: {} } }),
72 });
73 const body: any = await res.json();
74 const answer = JSON.parse(body.result.content[0].text);
75 expect(answer.plan.text).toContain(price);
76 });
77
78 test("no source file builds a plan's price by hand", async () => {
79 const files: string[] = [];
80 const walk = async (d: string): Promise<void> => {
81 for (const e of await readdir(d, { withFileTypes: true })) {
82 const p = join(d, e.name);
83 if (e.isDirectory()) await walk(p);
84 else if (p.endsWith(".ts")) files.push(p);
85 }
86 };
87 await walk(join(import.meta.dir, "..", "src"));
88 const hand = /\$\$\{[^}]*priceUsd[^}]*\}|priceUsd\}\s*(a month|\/mo)/;
89 const offenders: string[] = [];
90 // lapse_words.ts (#15928) still spells its price by hand: left for its own pull, to keep this one small.
91 for (const f of files) if (!f.endsWith("billing/lapse_words.ts") && hand.test(await readFile(f, "utf8"))) offenders.push(f);
92 expect(offenders).toEqual([]);
93 });
test/plans-row.test.ts +7 −7
@@ -30,10 +30,10 @@ test("every plan shows its price from the plans setting, the free plan Free; no
3030 expect(row).toContain(p.name);
3131 expect(row).toContain(sizeWords(p.size));
3232 }
33 for (const t of ["$19 a month", "$49 a month", "$149 a month", "Crew credit for 10 ordinary asks each month"]) expect(row).toContain(t);
33 for (const t of ["$19.00 / month", "$49.00 / month", "$149.00 / month", "Crew credit for 10 ordinary asks each month"]) expect(row).toContain(t);
3434 expect(row).not.toContain("Paid");
3535 expect(planWords(FREE).price).toBe("Free");
36 expect(planWords(SMALL).price).toBe("$19 a month");
36 expect(planWords(SMALL).price).toBe("$19.00 / month");
3737 });
3838
3939 test("with no buy links the plans carry no action of their own: the one button is the home's", () => {
@@ -82,7 +82,7 @@ test("the signed-out home shows each plan and one button to a page that exists",
8282 for (const p of DEFAULT_PLANS) expect(section).toContain(p.name);
8383 expect(section).toContain('href="#start-forge"');
8484 expect(section).not.toContain("/pricing");
85 expect(section).toContain("$19 a month");
85 expect(section).toContain("$19.00 / month");
8686 expect(section).not.toContain("Paid");
8787 expect(section).not.toContain("Get Free");
8888 expect(section.match(/data-size="lg"/g)).toHaveLength(1);
@@ -123,7 +123,7 @@ test("getDoorSettings: nothing stored, or a stored value that does not parse, re
123123 test("the terminal's Get your own forge: plans, the pointer to /forges/new and self-hosting", () => {
124124 const lines = getForgeLines(app).join("\n");
125125 for (const p of DEFAULT_PLANS) expect(lines).toContain(p.name);
126 expect(lines).toContain("$19 a month");
126 expect(lines).toContain("$19.00 / month");
127127 expect(lines).not.toContain("Paid");
128128 expect(lines).toContain("/forges/new");
129129 expect(lines).toContain("git clone");
@@ -160,7 +160,7 @@ test("with buy links set the plans show price, credit, Get anchors and the after
160160 put("signup", "closed");
161161 put("billing.links", JSON.stringify({ small: "https://buy.example/s", medium: "https://buy.example/m", large: "https://buy.example/l" }));
162162 const section = await yours();
163 for (const t of ["$19 a month", "$49 a month", "$149 a month", "Crew credit for 10 ordinary asks each month", "Crew credit for 30 ordinary asks each month", "Crew credit for 100 ordinary asks each month", "Your forge is created"])
163 for (const t of ["$19.00 / month", "$49.00 / month", "$149.00 / month", "Crew credit for 10 ordinary asks each month", "Crew credit for 30 ordinary asks each month", "Crew credit for 100 ordinary asks each month", "Your forge is created"])
164164 expect(section).toContain(t);
165165 for (const n of ["Small", "Medium", "Large"]) expect(section).toContain(`>Get ${n}</a>`);
166166 expect(section).not.toContain("Get Free");
@@ -174,9 +174,9 @@ test("changing a price in the plans setting changes the page", async () => {
174174 put("billing.links", JSON.stringify({ small: "https://buy.example/s" }));
175175 put("plans", JSON.stringify(DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: 23, creditUsd: 7 } : p))));
176176 const section = await yours();
177 expect(section).toContain("$23 a month");
177 expect(section).toContain("$23.00 / month");
178178 expect(section).toContain("Crew credit for 14 ordinary asks each month");
179 expect(section).not.toContain("$19 a month");
179 expect(section).not.toContain("$19.00 / month");
180180 });
181181
182182 test("the anonymous home never says the forge is not taking accounts; /signin says it once, linking /#yours (#11325)", async () => {
test/pricing-checkout-same-rows.test.ts +1 −1
@@ -46,7 +46,7 @@ test("changing a plan row changes the page's price and the checkout's amount", a
4646 setPlans(app.db, DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: price } : p)), actor);
4747 const text = await (await fetch(`${servers.url}/pricing`)).text();
4848 const start = text.indexOf('data-plan="small"');
49 expect(text.slice(start, text.indexOf("</div>", start))).toContain(`$${price} a month`);
49 expect(text.slice(start, text.indexOf("</div>", start))).toContain(`$${price}.00 / month`);
5050 const placed = await placeOrder(app, { name, plan: "small", email: "[email protected]", address: `addr-${price}` }, new URL(servers.url));
5151 expect(placed.ok).toBe(true);
5252 expect(charged.at(-1)).toBe(price);
test/pricing-line.test.ts +2 −2
@@ -39,14 +39,14 @@ const firstLine = async (): Promise<{ body: string; line: string }> => {
3939 test("the line is the cheapest paid plan's price, in the head's one sub, above the order form", async () => {
4040 const { body, line } = await firstLine();
4141 const lowest = Math.min(...getPlans(app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd));
42 expect(line).toBe(`A forge is $${lowest} a month.`);
42 expect(line).toBe(`A forge is $${lowest}.00 / month.`);
4343 expect(body).not.toContain('class="lead"');
4444 expect(body.indexOf("page-head-sub")).toBeLessThan(body.indexOf('id="order"'));
4545 });
4646
4747 test("when the plans change the line follows", async () => {
4848 setPlans(app.db, DEFAULT_PLANS.map((p) => (p.priceUsd === 19 ? { ...p, priceUsd: 23 } : p)), actor);
49 expect((await firstLine()).line).toContain("A forge is $23 a month");
49 expect((await firstLine()).line).toContain("A forge is $23.00 / month");
5050 expect(priceLine([])).toBe("A forge is free");
5151 });
5252
test/pricing-order.test.ts +2 −2
@@ -101,7 +101,7 @@ describe("/pricing", () => {
101101 const res = await fetch(`${base}/pricing`);
102102 expect(res.status).toBe(200);
103103 const text = await res.text();
104 expect(text).toContain("$19 a month");
104 expect(text).toContain("$19.00 / month");
105105 expect(text).toContain("Start my forge");
106106 expect(res.headers.get("content-security-policy")).toBeTruthy();
107107 });
@@ -198,7 +198,7 @@ describe("/pricing", () => {
198198 expect(text).toContain("ask the operator · for organizations");
199199 expect(text).toContain('href="https://www.espodev.com"');
200200 expect(text).not.toContain("not on sale");
201 expect(text).toContain("$19 a month");
201 expect(text).toContain("$19.00 / month");
202202 expect((await fetch(`${base}/pricing/order`, form({ name: "nope", plan: "small", email: "[email protected]" }))).status).toBe(409);
203203 useCheckout(app, fake);
204204 });
test/pricing-plans-agree.test.ts +1 −1
@@ -32,7 +32,7 @@ test("every plan's card shows the price, credit and forge count the API lists",
3232 const start = text.indexOf(`data-plan="${p.key}"`);
3333 expect(start).toBeGreaterThan(-1);
3434 const card = text.slice(start, text.indexOf("</div>", start));
35 expect(card).toContain(p.priceUsd === 0 ? ">Free<" : `$${p.priceUsd} a month`);
35 expect(card).toContain(p.priceUsd === 0 ? ">Free<" : `$${p.priceUsd}.00 / month`);
3636 if (p.priceUsd === 0) expect(card).toContain(`Crew credit for ${asksWords(api.startCreditUsd)}, once, to start`);
3737 else if (p.creditUsd > 0) expect(card).toContain(`Crew credit for ${asksWords(p.creditUsd)} each month`);
3838 else expect(card).toContain("No crew credit included");
test/pricing-size.test.ts +1 −1
@@ -44,7 +44,7 @@ test("with a provider, each paid row carries its own price and the button that s
4444 const text = await (await fetch(`${servers.url}/pricing`)).text();
4545 const rows = text.split('class="status-row" data-plan="').slice(1);
4646 expect(rows.length).toBeGreaterThanOrEqual(2);
47 const paid = rows.filter((r) => /a month/.test(r));
47 const paid = rows.filter((r) => / month/.test(r));
4848 expect(paid.length).toBeGreaterThan(0);
4949 for (const r of paid) expect(r).toMatch(/name="plan"\s+value="[a-z]+"/);
5050 expect(text).toContain('action="/pricing/order"');
test/tui-plans.test.ts +1 −1
@@ -80,7 +80,7 @@ describe("plans in the terminal", () => {
8080 test("lists each plan with size, price, credit and forges", async () => {
8181 const h = boot("alice");
8282 await open(h);
83 expect(h.text()).toContain("small · $19/mo · $5 crew credit");
83 expect(h.text()).toContain("small · $19.00 / month · $5 crew credit");
8484 expect(h.text()).toContain("large");
8585 h.stop();
8686 });
test/tui-pricing.test.ts +4 −3
@@ -10,6 +10,7 @@ import { createApp, type App } from "../src/app.ts";
1010 import { childDirOf } from "../src/actions/spawn.ts";
1111 import { deliverLink, NO_PROVIDER, reconcileOrder } from "../src/actions/order.ts";
1212 import { useCheckout, type CheckoutProvider } from "../src/billing/checkout.ts";
13 import { centsOfUsd, perMonthWords } from "../src/billing/money.ts";
1314 import { getOrder, MAX_PENDING_PER_ADDRESS, pendingFrom } from "../src/billing/orders.ts";
1415 import { createUser } from "../src/core/users.ts";
1516 import { bucketOf } from "../src/http/peer.ts";
@@ -98,7 +99,7 @@ test("the plans are listed with their prices", async () => {
9899 const h = f.open("203.0.113.1");
99100 await settleApp(h.tui);
100101 const text = flat(h);
101 for (const p of getPlans(f.app.db)) if (p.key !== FREE && p.priceUsd > 0) expect(text).toContain(`$${p.priceUsd} a month`);
102 for (const p of getPlans(f.app.db)) if (p.key !== FREE && p.priceUsd > 0) expect(text).toContain(`$${p.priceUsd}.00 / month`);
102103 });
103104
104105 test("the screen opens with the cheapest paid plan's price, and says none where nothing is on sale", async () => {
@@ -106,7 +107,7 @@ test("the screen opens with the cheapest paid plan's price, and says none where
106107 const lowest = Math.min(...getPlans(f.app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd));
107108 const h = f.open("203.0.113.7");
108109 await settleApp(h.tui);
109 expect(flat(h)).toContain(`A forge is $${lowest} a month.`);
110 expect(flat(h)).toContain(`A forge is $${lowest}.00 / month.`);
110111 const g = await fixture({ sell: false });
111112 const k = g.open("203.0.113.8");
112113 await settleApp(k.tui);
@@ -324,7 +325,7 @@ test("the terminal prints the receipt's four facts on every ready branch, the cl
324325 const f = await fixture();
325326 const small = getPlans(f.app.db).find((p) => p.priceUsd > 0)!;
326327 const today = new Date().toISOString().slice(0, 10);
327 const facts = (name: string) => [small.name, `$${small.priceUsd} a month`, today, `forge ${name}`];
328 const facts = (name: string) => [small.name, perMonthWords(centsOfUsd(small.priceUsd)), today, `forge ${name}`];
328329 // The claim link branch.
329330 const a = await ordered(f, "203.0.113.20", "receipt-link");
330331 f.paid.add(a.session);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs