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
Check · Review · Land · Live — No review yet.
torque/forge:torque/15661-every-price-on-pricing-the-plan-row-and → main 13 commits fork
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 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import type { Plan } from "../settings/plans.ts"; |
| 10 | import { centsOfUsd, perMonthWords } from "./money.ts"; | |
| 10 | 11 | |
| 11 | 12 | export interface PlanChange { |
| 12 | 13 | readonly forge: string; |
| @@ -21,19 +22,17 @@ export interface PlanChange { | ||
| 21 | 22 | /** The price in cents of a plan named by key, or by the size it sits on; unknown reads as 0. */ |
| 22 | 23 | export function centsFor(plans: readonly Plan[], name: string): number { |
| 23 | 24 | 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); | |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | export function previewChange(plans: readonly Plan[], forge: string, from: string, to: string, now: Date): PlanChange { |
| 28 | 29 | return { forge, from, to, cents: centsFor(plans, to), starts: now.toISOString().slice(0, 10) }; |
| 29 | 30 | } |
| 30 | 31 | |
| 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); | |
| 35 | 34 | |
| 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". */ | |
| 37 | 36 | export function changeLine(c: PlanChange): string { |
| 38 | 37 | return `${c.from} → ${c.to}: ${perMonth(c.cents)}, starts ${c.starts}`; |
| 39 | 38 | } |
src/billing/plan_words.ts +6 −5
| @@ -11,10 +11,11 @@ import type { BillingLinks } from "../settings/billing.ts"; | ||
| 11 | 11 | import { sizeWords } from "../settings/billing.ts"; |
| 12 | 12 | import { LIMITS } from "../settings/limits.ts"; |
| 13 | 13 | import type { Plan } from "../settings/plans.ts"; |
| 14 | import { centsOfUsd, perMonthWords } from "./money.ts"; | |
| 14 | 15 | |
| 15 | 16 | export interface PlanWords { |
| 16 | 17 | readonly name: string; |
| 17 | /** "Free" or "$19 a month". */ | |
| 18 | /** "Free" or "$19.00 / month" (`money.ts`). */ | |
| 18 | 19 | readonly price: string; |
| 19 | 20 | /** |
| 20 | 21 | * 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 | ||
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | /** |
| 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. | |
| 61 | 62 | */ |
| 62 | export const monthlyPrice = (usd: number): string => (usd === 0 ? "Free" : `$${usd} a month`); | |
| 63 | export const monthlyPrice = (usd: number): string => perMonthWords(centsOfUsd(usd)); | |
| 63 | 64 | |
| 64 | 65 | export function planWords(p: Plan, links: BillingLinks = {}, startUsd = 0, askUsd: number = ASK_USD): PlanWords { |
| 65 | 66 | const free = p.priceUsd === 0; |
| @@ -88,7 +89,7 @@ export const AFTER_PAYMENT = AFTER_PAYMENT_STEPS.join(" "); | ||
| 88 | 89 | /** What a stranger reads first: the cheapest paid plan, priced from the plans, never typed. */ |
| 89 | 90 | export function priceLine(plans: readonly Plan[]): string { |
| 90 | 91 | 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)))}`; | |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | 95 | /** 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 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import type { Database } from "bun:sqlite"; |
| 13 | import { centsOfUsd, perMonthWords } from "../billing/money.ts"; | |
| 13 | 14 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 14 | 15 | import { isSize, SIZES, type Size } from "../spawn/sizes.ts"; |
| 15 | 16 | import { writeSetting } from "./limits.ts"; |
| @@ -146,7 +147,7 @@ export function getPlan(db: Database, key: string): Plan | undefined { | ||
| 146 | 147 | } |
| 147 | 148 | |
| 148 | 149 | 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(", "); | |
| 150 | 151 | |
| 151 | 152 | /** Replace the plans (validated by the caller) and keep the change. */ |
| 152 | 153 | export function setPlans(db: Database, plans: readonly Plan[], actorId: string): void { |
src/tui/screens/plans.ts +3 −2
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import { editPlans, readPlans } from "../../actions/plans.ts"; |
| 11 | import { centsOfUsd, perMonthWords } from "../../billing/money.ts"; | |
| 11 | 12 | import type { Plan } from "../../settings/plans.ts"; |
| 12 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| 13 | 14 | import { binding } from "../app/keys.ts"; |
| @@ -59,7 +60,7 @@ export function plansScreen(f: Session, ctx: Ctx): Screen { | ||
| 59 | 60 | promptScreen(ctx, screen, { |
| 60 | 61 | title: plan.key, |
| 61 | 62 | 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`, | |
| 63 | 64 | onSubmit: (raw) => { |
| 64 | 65 | const edit = parseEdit(raw); |
| 65 | 66 | if (typeof edit === "string") return edit; |
| @@ -83,7 +84,7 @@ export function plansScreen(f: Session, ctx: Ctx): Screen { | ||
| 83 | 84 | const rows = (plans: readonly Plan[]): ListRow[] => |
| 84 | 85 | plans.map((p) => ({ |
| 85 | 86 | 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`, | |
| 87 | 88 | meta: p.says, |
| 88 | 89 | })); |
| 89 | 90 |
src/tui/screens/pricing.ts +2 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder } from "../../actions/order.ts"; |
| 13 | import { centsOfUsd, perMonthWords } from "../../billing/money.ts"; | |
| 13 | 14 | import { AFTER_PAYMENT_STEPS, priceLine } from "../../billing/plan_words.ts"; |
| 14 | 15 | import { receiptFacts } from "../../billing/receipt.ts"; |
| 15 | 16 | import { lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts"; |
| @@ -156,7 +157,7 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen { | ||
| 156 | 157 | for (const p of plans()) { |
| 157 | 158 | const isPaid = p.key !== FREE && p.priceUsd > 0; |
| 158 | 159 | 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); | |
| 160 | 161 | } |
| 161 | 162 | y++; |
| 162 | 163 | const base = y - area.y; |
src/web/plan_row.ts +3 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import { noticeOf, type PlanNotice } from "../billing/notice.ts"; |
| 13 | import { centsOfUsd, perMonthWords } from "../billing/money.ts"; | |
| 13 | 14 | import { fundingOf } from "../spawn/funding.ts"; |
| 14 | 15 | import { uncountedWords } from "../actions/crew_means.ts"; |
| 15 | 16 | import { creditWords } from "../billing/plan_words.ts"; |
| @@ -51,8 +52,9 @@ export function planLine(dataDir: string, now: number = Date.now()): string | un | ||
| 51 | 52 | // when the host lent no cap. |
| 52 | 53 | const cap = f?.capUsd ?? n.creditUsd; |
| 53 | 54 | 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))}.` : ""; | |
| 54 | 56 | 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}`; | |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | /** |
test/billing-order-receipt.test.ts +5 −5
| @@ -51,7 +51,7 @@ afterAll(async () => { | ||
| 51 | 51 | |
| 52 | 52 | describe("the receipt", () => { |
| 53 | 53 | 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"); | |
| 55 | 55 | expect(receiptAmount({ priceUsd: 0 })).toBe("not recorded for this order"); |
| 56 | 56 | expect(receiptDate(DAY)).toBe("2026-11-03"); |
| 57 | 57 | }); |
| @@ -62,7 +62,7 @@ describe("the receipt", () => { | ||
| 62 | 62 | expect(res.status).toBe(200); |
| 63 | 63 | const text = await res.text(); |
| 64 | 64 | 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'); | |
| 66 | 66 | expect(text).toContain('data-fact="date">2026-11-03'); |
| 67 | 67 | expect(text).toContain('data-fact="forge">shopfront'); |
| 68 | 68 | }); |
| @@ -83,8 +83,8 @@ describe("the receipt", () => { | ||
| 83 | 83 | test("the amount is the stored price, not today's plan", async () => { |
| 84 | 84 | const o = order("oldprice", "spawned", 7); |
| 85 | 85 | 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"); | |
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | 90 | 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", () => { | ||
| 129 | 129 | const text = await res.text(); |
| 130 | 130 | expect(text).toStartWith("<!doctype html>"); |
| 131 | 131 | expect(text).toContain("@media print"); |
| 132 | expect(text).toContain("$19 a month"); | |
| 132 | expect(text).toContain("$19.00 / month"); | |
| 133 | 133 | expect(text).toContain("2026-11-03"); |
| 134 | 134 | expect(text).toContain("download1"); |
| 135 | 135 | 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", () => { | ||
| 13 | 13 | |
| 14 | 14 | test("the line says from, to, dollars and cents a month, and the UTC day", () => { |
| 15 | 15 | 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"); | |
| 18 | 18 | expect(perMonth(0)).toBe("Free"); |
| 19 | 19 | }); |
| 20 | 20 |
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 | ||
| 98 | 98 | tui.dispatch(key(to === "medium" ? "m" : "s")); |
| 99 | 99 | await settleApp(tui); |
| 100 | 100 | 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)}`); | |
| 102 | 102 | tui.dispatch(key("n")); |
| 103 | 103 | await settleApp(tui); |
| 104 | 104 | tui.stop?.(); |
test/billing.test.ts +1 −1
| @@ -157,7 +157,7 @@ describe("billing seam", () => { | ||
| 157 | 157 | const res = await send("GET", `/settings/billing/change?forge=kid&plan=${to}`, admin); |
| 158 | 158 | expect(res.status).toBe(200); |
| 159 | 159 | 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"; | |
| 161 | 161 | expect(text).toContain(`${from} → ${to}: ${price}, starts ${today()}`); |
| 162 | 162 | expect(text.split(`${from} → ${to}`).length).toBe(2); // said once |
| 163 | 163 | 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 | ||
| 30 | 30 | expect(row).toContain(p.name); |
| 31 | 31 | expect(row).toContain(sizeWords(p.size)); |
| 32 | 32 | } |
| 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); | |
| 34 | 34 | expect(row).not.toContain("Paid"); |
| 35 | 35 | expect(planWords(FREE).price).toBe("Free"); |
| 36 | expect(planWords(SMALL).price).toBe("$19 a month"); | |
| 36 | expect(planWords(SMALL).price).toBe("$19.00 / month"); | |
| 37 | 37 | }); |
| 38 | 38 | |
| 39 | 39 | 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", | ||
| 82 | 82 | for (const p of DEFAULT_PLANS) expect(section).toContain(p.name); |
| 83 | 83 | expect(section).toContain('href="#start-forge"'); |
| 84 | 84 | expect(section).not.toContain("/pricing"); |
| 85 | expect(section).toContain("$19 a month"); | |
| 85 | expect(section).toContain("$19.00 / month"); | |
| 86 | 86 | expect(section).not.toContain("Paid"); |
| 87 | 87 | expect(section).not.toContain("Get Free"); |
| 88 | 88 | 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 | ||
| 123 | 123 | test("the terminal's Get your own forge: plans, the pointer to /forges/new and self-hosting", () => { |
| 124 | 124 | const lines = getForgeLines(app).join("\n"); |
| 125 | 125 | 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"); | |
| 127 | 127 | expect(lines).not.toContain("Paid"); |
| 128 | 128 | expect(lines).toContain("/forges/new"); |
| 129 | 129 | expect(lines).toContain("git clone"); |
| @@ -160,7 +160,7 @@ test("with buy links set the plans show price, credit, Get anchors and the after | ||
| 160 | 160 | put("signup", "closed"); |
| 161 | 161 | put("billing.links", JSON.stringify({ small: "https://buy.example/s", medium: "https://buy.example/m", large: "https://buy.example/l" })); |
| 162 | 162 | 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"]) | |
| 164 | 164 | expect(section).toContain(t); |
| 165 | 165 | for (const n of ["Small", "Medium", "Large"]) expect(section).toContain(`>Get ${n}</a>`); |
| 166 | 166 | expect(section).not.toContain("Get Free"); |
| @@ -174,9 +174,9 @@ test("changing a price in the plans setting changes the page", async () => { | ||
| 174 | 174 | put("billing.links", JSON.stringify({ small: "https://buy.example/s" })); |
| 175 | 175 | put("plans", JSON.stringify(DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: 23, creditUsd: 7 } : p)))); |
| 176 | 176 | const section = await yours(); |
| 177 | expect(section).toContain("$23 a month"); | |
| 177 | expect(section).toContain("$23.00 / month"); | |
| 178 | 178 | 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"); | |
| 180 | 180 | }); |
| 181 | 181 | |
| 182 | 182 | 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 | ||
| 46 | 46 | setPlans(app.db, DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: price } : p)), actor); |
| 47 | 47 | const text = await (await fetch(`${servers.url}/pricing`)).text(); |
| 48 | 48 | 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`); | |
| 50 | 50 | const placed = await placeOrder(app, { name, plan: "small", email: "[email protected]", address: `addr-${price}` }, new URL(servers.url)); |
| 51 | 51 | expect(placed.ok).toBe(true); |
| 52 | 52 | 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 }> => { | ||
| 39 | 39 | test("the line is the cheapest paid plan's price, in the head's one sub, above the order form", async () => { |
| 40 | 40 | const { body, line } = await firstLine(); |
| 41 | 41 | 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.`); | |
| 43 | 43 | expect(body).not.toContain('class="lead"'); |
| 44 | 44 | expect(body.indexOf("page-head-sub")).toBeLessThan(body.indexOf('id="order"')); |
| 45 | 45 | }); |
| 46 | 46 | |
| 47 | 47 | test("when the plans change the line follows", async () => { |
| 48 | 48 | 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"); | |
| 50 | 50 | expect(priceLine([])).toBe("A forge is free"); |
| 51 | 51 | }); |
| 52 | 52 |
test/pricing-order.test.ts +2 −2
| @@ -101,7 +101,7 @@ describe("/pricing", () => { | ||
| 101 | 101 | const res = await fetch(`${base}/pricing`); |
| 102 | 102 | expect(res.status).toBe(200); |
| 103 | 103 | const text = await res.text(); |
| 104 | expect(text).toContain("$19 a month"); | |
| 104 | expect(text).toContain("$19.00 / month"); | |
| 105 | 105 | expect(text).toContain("Start my forge"); |
| 106 | 106 | expect(res.headers.get("content-security-policy")).toBeTruthy(); |
| 107 | 107 | }); |
| @@ -198,7 +198,7 @@ describe("/pricing", () => { | ||
| 198 | 198 | expect(text).toContain("ask the operator · for organizations"); |
| 199 | 199 | expect(text).toContain('href="https://www.espodev.com"'); |
| 200 | 200 | expect(text).not.toContain("not on sale"); |
| 201 | expect(text).toContain("$19 a month"); | |
| 201 | expect(text).toContain("$19.00 / month"); | |
| 202 | 202 | expect((await fetch(`${base}/pricing/order`, form({ name: "nope", plan: "small", email: "[email protected]" }))).status).toBe(409); |
| 203 | 203 | useCheckout(app, fake); |
| 204 | 204 | }); |
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", | ||
| 32 | 32 | const start = text.indexOf(`data-plan="${p.key}"`); |
| 33 | 33 | expect(start).toBeGreaterThan(-1); |
| 34 | 34 | 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`); | |
| 36 | 36 | if (p.priceUsd === 0) expect(card).toContain(`Crew credit for ${asksWords(api.startCreditUsd)}, once, to start`); |
| 37 | 37 | else if (p.creditUsd > 0) expect(card).toContain(`Crew credit for ${asksWords(p.creditUsd)} each month`); |
| 38 | 38 | 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 | ||
| 44 | 44 | const text = await (await fetch(`${servers.url}/pricing`)).text(); |
| 45 | 45 | const rows = text.split('class="status-row" data-plan="').slice(1); |
| 46 | 46 | expect(rows.length).toBeGreaterThanOrEqual(2); |
| 47 | const paid = rows.filter((r) => /a month/.test(r)); | |
| 47 | const paid = rows.filter((r) => / month/.test(r)); | |
| 48 | 48 | expect(paid.length).toBeGreaterThan(0); |
| 49 | 49 | for (const r of paid) expect(r).toMatch(/name="plan"\s+value="[a-z]+"/); |
| 50 | 50 | expect(text).toContain('action="/pricing/order"'); |
test/tui-plans.test.ts +1 −1
| @@ -80,7 +80,7 @@ describe("plans in the terminal", () => { | ||
| 80 | 80 | test("lists each plan with size, price, credit and forges", async () => { |
| 81 | 81 | const h = boot("alice"); |
| 82 | 82 | 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"); | |
| 84 | 84 | expect(h.text()).toContain("large"); |
| 85 | 85 | h.stop(); |
| 86 | 86 | }); |
test/tui-pricing.test.ts +4 −3
| @@ -10,6 +10,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { childDirOf } from "../src/actions/spawn.ts"; |
| 11 | 11 | import { deliverLink, NO_PROVIDER, reconcileOrder } from "../src/actions/order.ts"; |
| 12 | 12 | import { useCheckout, type CheckoutProvider } from "../src/billing/checkout.ts"; |
| 13 | import { centsOfUsd, perMonthWords } from "../src/billing/money.ts"; | |
| 13 | 14 | import { getOrder, MAX_PENDING_PER_ADDRESS, pendingFrom } from "../src/billing/orders.ts"; |
| 14 | 15 | import { createUser } from "../src/core/users.ts"; |
| 15 | 16 | import { bucketOf } from "../src/http/peer.ts"; |
| @@ -98,7 +99,7 @@ test("the plans are listed with their prices", async () => { | ||
| 98 | 99 | const h = f.open("203.0.113.1"); |
| 99 | 100 | await settleApp(h.tui); |
| 100 | 101 | 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`); | |
| 102 | 103 | }); |
| 103 | 104 | |
| 104 | 105 | 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 | ||
| 106 | 107 | const lowest = Math.min(...getPlans(f.app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd)); |
| 107 | 108 | const h = f.open("203.0.113.7"); |
| 108 | 109 | 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.`); | |
| 110 | 111 | const g = await fixture({ sell: false }); |
| 111 | 112 | const k = g.open("203.0.113.8"); |
| 112 | 113 | await settleApp(k.tui); |
| @@ -324,7 +325,7 @@ test("the terminal prints the receipt's four facts on every ready branch, the cl | ||
| 324 | 325 | const f = await fixture(); |
| 325 | 326 | const small = getPlans(f.app.db).find((p) => p.priceUsd > 0)!; |
| 326 | 327 | 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}`]; | |
| 328 | 329 | // The claim link branch. |
| 329 | 330 | const a = await ordered(f, "203.0.113.20", "receipt-link"); |
| 330 | 331 | f.paid.add(a.session); |
new above
offline