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

The owner's payments are rows on one page: date, amount, plan, status word #13242

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13093-the-owner-s-payments-are-rows-on-one-pag → main 8 commits fork 4 threads · 4 unresolved

  • Merged. scout/13093-the-owner-s-payments-are-rows-on-one-pag was merged into main as c3dea30.

Review

Sign in to review this change.
12 files changed +334 −7
docs/design/attention-budget.json +4 −4
@@ -109,13 +109,13 @@
109109 },
110110 "settings": {
111111 "390": {
112 "words": 143,
113 "blocks": 31,
112 "words": 144,
113 "blocks": 32,
114114 "colours": 1
115115 },
116116 "1280": {
117 "words": 143,
118 "blocks": 31,
117 "words": 144,
118 "blocks": 32,
119119 "colours": 1
120120 },
121121 "note": "143 words since 68efd9dd (2026-11-13, a hosted forge asks its host for a name its gate refused): that change added two words to this first view."
docs/design/audit.md +1
@@ -118,6 +118,7 @@ Machine routes are not pages and have no entry: `/audit.csv`,
118118 - `/settings/everyday` — `pages/everyday.ts` · an admin makes the everyday account with a passkey, or keeps working as admin · `/settings` (the pair, once made) · none seen.
119119 - `/settings/billing` — `pages/billing.ts` · each forge's plan, granted by hand · `/settings/economics` · none seen.
120120 - `/settings/billing/change` — `pages/billing.ts` · one forge's plan change before it is confirmed: from, to, the cents a month and the day it starts · `/settings/billing` · none seen.
121 - `/settings/payments` — `pages/payments.ts` · the payments recorded for the forges you claimed, newest first: date, amount, plan, status word · `/settings/billing` (plans, not payments) · none seen.
121122 - `/settings/economics` — `pages/economics.ts` · the profit slider's position and the margin, with the policy in words · `/admin/limits`, `/settings/capacity` · none seen.
122123 - `/settings/hosted-forges` — `pages/hosted-forges.ts` · what the forges hosted here may reach: one sentence with a switch, the names for every forge, each forge's grants and asks · `/forges` (the same asks and grants, on each forge's row) · none seen.
123124 - `/settings/capacity` — `pages/capacity.ts` · how many runs and checks go at once · `/admin/limits`, `/settings/usage` · none seen.
docs/features/billing.md +1
@@ -25,3 +25,4 @@ Each invoice the verified Stripe webhook tells of is one `payment` row (`src/bil
2525 - **Refunds:** only a charge refunded in full marks the invoice `refunded`; a partial refund leaves it. A refund seen before its invoice is kept and applied when the row arrives. A refunded row stays refunded. A charge not tied to an invoice changes nothing and is not audited.
2626 - **Retries:** the row is written in the same transaction as the event id; if the write fails the id is not kept and Stripe retries.
2727 - **Where to see it:** Settings → Billing, "Payments kept" (count and refunded); the terminal's Billing screen shows the newest payment on each forge's line.
28 - **The owner's payments:** `/settings/payments` (linked from Settings) and the terminal's **Payments** palette entry (`src/tui/screens/payments.ts`) list what was charged for the forges the person claimed, newest first: status word, date, amount in its currency and the forge's plan now (the store keeps no plan per payment). Both read `paymentsFor` in `src/web/pages/payments.ts`, so each shows only the person's own forges. At most 100 rows; past that a sentence says older ones are not listed. Try it: sign in, Settings → Payments. Pinned by `test/payments-page.test.ts` and `test/payments-tui.test.ts`.
src/http/route_marks.ts +1
@@ -275,6 +275,7 @@ export const ROUTES: Readonly<Record<string, Mark>> = {
275275 "/settings/everyday/options": "admin",
276276 "/settings/everyday/switch": "open",
277277 "/settings/everyday/keep": "open",
278 "/settings/payments": "open",
278279 "/settings/shells": "open",
279280 "/settings/shells/stop-idle": "open",
280281 "/settings/shells/:id/stop": "open",
src/http/settings_routes.ts +2
@@ -19,6 +19,7 @@ import { teamPage, teamSet, teamsPage, teamsStream } from "../web/pages/teams.ts
1919 import { telemetryPage, telemetrySet } from "../web/pages/telemetry.ts";
2020 import { flagsPage, flagsSet } from "../web/pages/flags.ts";
2121 import { appTemplatesPage, appTemplatesSet } from "../web/pages/app_templates.ts";
22 import { paymentsPage } from "../web/pages/payments.ts";
2223 import { billingPage, billingChange, billingGrant, billingSetLinks, billingSetPortal, billingMakeCode, billingRevokeCode, stripeConnect, stripeDisconnect, stripeSecret, orderRetry } from "../web/pages/billing.ts";
2324 import { economicsPage, economicsSet } from "../web/pages/economics.ts";
2425 import { trustedAdd, trustedPage, trustedRemove, trustedRevert, trustedStop } from "../web/pages/trusted.ts";
@@ -172,6 +173,7 @@ export function settingsRoutes(router: Router<Handler>, knownPatterns: () => rea
172173 router.add("POST", "/settings/everyday/switch", everydaySwitch);
173174 router.add("POST", "/settings/everyday/keep", everydayKeep);
174175 router.add("GET", "/settings/appearance", appearancePage);
176 router.add("GET", "/settings/payments", paymentsPage);
175177 router.add("GET", "/settings/shells", shellsPage);
176178 router.add("POST", "/settings/shells/stop-idle", shellsStopIdle);
177179 router.add("POST", "/settings/shells/:id/stop", shellStop);
src/tui/screens/entries.ts +2
@@ -20,6 +20,7 @@ import { entry as dotfiles } from "./dotfiles.ts";
2020 import { entry as devices } from "./devices.ts";
2121 import { entry as bets } from "./bets.ts";
2222 import { entry as bills } from "./bills.ts";
23 import { entry as payments } from "./payments.ts";
2324 import { entry as billing } from "./billing.ts";
2425 import { entry as lapsed } from "./lapsed.ts";
2526 import { entry as codes } from "./codes.ts";
@@ -127,6 +128,7 @@ export interface PaletteEntry {
127128 /** In the order the palette offers them; an entry follows the ones it names in `after`. */
128129 export const ENTRIES: readonly PaletteEntry[] = [
129130 bills,
131 payments,
130132 sentinel,
131133 boards,
132134 drift,
src/tui/screens/payments.ts added +55
@@ -0,0 +1,55 @@
1 /**
2 * The owner's payments in the terminal (#13093): the same rows as `/settings/payments`, from the
3 * same `paymentsFor`, so the gate is the page's: only the forges this person claimed, a guest sees
4 * nothing. Status word first, then date, amount and the forge's plan now.
5 */
6
7 import { amountWords, paymentsFor, PAYMENTS_CAP } from "../../web/pages/payments.ts";
8 import type { Ctx, Screen } from "../app/app.ts";
9 import { binding } from "../app/keys.ts";
10 import { style } from "../term/style.ts";
11 import type { Session } from "../session.ts";
12 import { Scroll } from "./common.ts";
13 import type { PaletteEntry } from "./entries.ts";
14
15 const WORDS = { paid: "Paid", refunded: "Refunded", failed: "Failed" } as const;
16
17 /** One line per payment, newest first; one sentence when there is none or the cap was hit. */
18 export function paymentLines(session: Session): string[] {
19 const { rows, more } = paymentsFor(session.app, session.user?.kind === "user" ? session.user : undefined);
20 if (rows.length === 0) return ["No payment has been recorded for you yet. Plans and prices are on /pricing."];
21 const lines = rows.map((p) => `${WORDS[p.status].padEnd(9)} ${p.at.slice(0, 10)} ${amountWords(p.amountMinor, p.currency)} ${p.plan}`);
22 return more ? [...lines, `Showing the newest ${PAYMENTS_CAP}; older payments are kept but not listed.`] : lines;
23 }
24
25 export function paymentsScreen(session: Session, ctx: Ctx): Screen {
26 const scroll = new Scroll();
27 const lines = paymentLines(session);
28 return {
29 title: "Payments",
30 keys: [binding(["j", "k"], "scroll"), binding(["esc"], "back")],
31 render(area, s) {
32 const c = ctx.theme.c;
33 const from = scroll.window(area.h, lines.length);
34 for (let i = 0; i < area.h; i++) {
35 const line = lines[from + i];
36 if (line !== undefined) s.text(area.x + 1, area.y + i, line, style(c.fg, c.bg), area.x + area.w);
37 }
38 },
39 key(e) {
40 if (e.key === "esc" || e.key === "q") {
41 ctx.pop();
42 return true;
43 }
44 return scroll.key(e, lines.length);
45 },
46 };
47 }
48
49 export const entry: PaletteEntry = {
50 id: "payments",
51 title: "Payments",
52 hint: "what was charged for the forges you claimed",
53 offered: (session) => session.user !== undefined && session.user.kind === "user",
54 run: (session, ctx) => ctx.push(paymentsScreen(session, ctx)),
55 };
src/web/pages/bills.ts +7 −3
@@ -25,12 +25,16 @@ export const billNames = (app: App, user: User): string[] =>
2525 .filter((r) => r.made && claimsBill(user, r.billTo))
2626 .map((r) => r.name);
2727
28 /** A block for the settings page; nothing when this person claimed no forge. */
29 export function billsBlock(app: App, user: User): Html | null {
28 /**
29 * A block for the settings page: each claimed forge's bill, and for everyone the way to payments.
30 */
31 export function billsBlock(app: App, user: User): Html {
3032 const names = billNames(app, user);
31 if (names.length === 0) return null;
33 const link = html`<p><a href="/settings/payments">Payments</a></p>`;
34 if (names.length === 0) return link;
3235 return html`<section class="settings-block" data-bills>
outdated

The link only appears when the person has claimed forges in this block; make it reachable for every signed-in owner so the empty state can be seen from the product.

3336 <h2>Your forges' bills</h2>
3437 ${names.map((n) => html`<h3>${n}</h3>${billRow(n)}`)}
38 ${link}
3539 </section>`;
3640 }
src/web/pages/payments.ts added +81
@@ -0,0 +1,81 @@
1 /**
2 * `/settings/payments` (#13093): the payments the billing store recorded for the forges this
3 * person claimed, newest first: date, amount, plan, status word. Read only. An amount is the
4 * stored integer minor units shown in its currency; nothing is recomputed or rewritten.
5 */
6
7 import type { App } from "../../app.ts";
8 import type { User } from "../../core/users.ts";
9 import { listPayments, type Payment } from "../../billing/payments.ts";
10 import { getStored } from "../../billing/store.ts";
11 import { getPlan } from "../../settings/plans.ts";
12 import type { Ctx } from "../../http/context.ts";
13 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
14 import { signInFirst } from "../chrome.ts";
15 import { html, type Html } from "../html.ts";
16 import { page } from "../layout.ts";
17 import { billNames } from "./bills.ts";
18
19 const STATUS_WORDS = { paid: "Paid", refunded: "Refunded", failed: "Failed" } as const;
20
21 /**
22 * "$19.99" from 1999 and "usd"; the currency's own minor-unit digits; the code itself when unknown.
23 */
24 export function amountWords(minor: number, currency: string): string {
25 try {
26 const code = currency.toUpperCase();
27 const f = new Intl.NumberFormat("en-US", { style: "currency", currency: code });
28 const digits = f.resolvedOptions().maximumFractionDigits ?? 2;
29 return f.format(minor / 10 ** digits);
30 } catch {
31 return `${minor} ${currency.toUpperCase()} (minor units)`;
32 }
33 }
34
35 interface Line extends Payment {
36 /** The forge's plan now: the store keeps no plan per payment. */
37 readonly plan: string;
38 }
39
40 /** The most rows listed; a person with more is told so. */
41 export const PAYMENTS_CAP = 100;
42
43 /** This person's payments, newest first: those of every forge they claimed, once each. */
44 export function paymentsFor(app: App, user: User | undefined): { rows: Line[]; more: boolean } {
45 if (user === undefined) return { rows: [], more: false };
46 const seen = new Map<string, Line>();
outdated

listPayments(..., 100) silently drops older payments with no paging or note. Say so on the page when the cap is reached, or page it.

47 for (const forge of billNames(app, user)) {
48 const e = getStored(app.db, forge);
49 if (e === undefined || e.customerId === "") continue;
50 const plan = getPlan(app.db, e.plan)?.name ?? e.plan;
51 for (const p of listPayments(app.db, e.customerId, PAYMENTS_CAP + 1)) if (!seen.has(p.id)) seen.set(p.id, { ...p, plan });
outdated

Principles 2 and 7: amount, plan and status are packed into one dd with middots. Give each fact its own place (status word first as text) so the row reads as a row; also the plan shown is the forge current plan, not the plan at payment time, which is misleading for older rows.

52 }
53 const all = [...seen.values()].sort((a, b) => (a.at === b.at ? (a.id < b.id ? 1 : -1) : a.at < b.at ? 1 : -1));
54 return { rows: all.slice(0, PAYMENTS_CAP), more: all.length > PAYMENTS_CAP };
55 }
56
57 const line = (p: Line): Html =>
58 html`<tr data-payment="${p.status}"><td>${STATUS_WORDS[p.status]}</td><td><time datetime="${p.at}">${p.at.slice(0, 10)}</time></td><td>${amountWords(p.amountMinor, p.currency)}</td><td>${p.plan}</td></tr>`;
59
60 // GET /settings/payments
61 export function paymentsPage(ctx: Ctx): Response {
62 if (ctx.auth.user === undefined) return signInFirst(ctx);
63 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
outdated

Principle 1: the page head is a bare h1 with no sentence saying what the page is for. Also the whole response is about 12 KB, over the 10 KB the issue sets (box 3).

64 const rendering = performance.now();
65 const { rows, more } = paymentsFor(ctx.app, ctx.auth.user);
66 const body =
67 rows.length === 0
68 ? html`<p>No payment has been recorded for you yet. Plans and prices are on <a href="/pricing">/pricing</a>.</p>`
69 : html`<table class="table" data-dense data-payments><thead><tr><th>Status</th><th>Date</th><th>Amount</th><th>Plan now</th></tr></thead><tbody>${rows.map(line)}</tbody></table>${more ? html`<p data-payments-more>Showing the newest ${PAYMENTS_CAP}; older payments are kept but not listed.</p>` : null}`;
70 const res = page({
71 ctx,
72 title: "Payments",
73 tight: true,
74 // A lean shell: a person comes here from Settings and goes back to it, so the bar holds that
75 // one link.
76 tools: html`<a class="small" href="/settings">Settings</a>`,
77 body: html`<div class="page-head"><h1>Payments</h1></div><p>What was charged for the forges you claimed, newest first. Plan now is the forge's plan today.</p>${body}`,
78 });
79 notePhase(ctx.request, "render", performance.now() - rendering);
80 return res;
81 }
test/palette-roster.test.ts +2
@@ -183,6 +183,7 @@ test("a site-admin person is offered the whole roster", () => {
183183 ["money", "Money", "this month's cost, revenue and gap, and the last 30 days"],
184184 ["app-templates", "App templates", "the repositories New app offers; mark or unmark one"],
185185 ["devices", "Devices", "LAN printers: model, state, supplies; declare or remove one"],
186 ["payments", "Payments", "what was charged for the forges you claimed"],
186187 ["edge-only-accounts", "Edge-only accounts", "who would be locked out if the platform edge sign-in went off"],
187188 ["way-back-links", "Way-back links", "a link that signs in an account the edge made, once the edge is gone"],
188189 ["traffic-sources", "Traffic sources", "where people come from and where they go, for the forge"],
@@ -381,6 +382,7 @@ test("a member person is offered the signed-in roster without the admin entries"
381382 ["proposal-tokens", "Proposal tokens", "mint, list and revoke what a child proposes with"],
382383 ["model", "Model budget", "what your crew may spend, and add your own subscription"],
383384 ["can", "What I can do", "your role and what it allows here"],
385 ["payments", "Payments", "what was charged for the forges you claimed"],
384386 ["bugs", "Bugs", "open bugs and the bug clock"],
385387 ["health-voice", "Health — spoken", "how the forge is, in two plain sentences"],
386388 ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"],
test/payments-page.test.ts added +114
@@ -0,0 +1,114 @@
1 // /settings/payments lists the recorded payments of the forges a person claimed (#13093).
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp } from "../src/app.ts";
7 import { putEntitlement } from "../src/billing/store.ts";
8 import { recordPayment } from "../src/billing/payments.ts";
9 import { createSession } from "../src/core/sessions.ts";
10 import { createUser } from "../src/core/users.ts";
11 import { serve } from "../src/http/server.ts";
12 import { amountWords } from "../src/web/pages/payments.ts";
13 import { servedRows, dropServed } from "../src/spawn/clients.ts";
14
15 let dir = "", app: ReturnType<typeof createApp>, servers: Awaited<ReturnType<typeof serve>>;
16 let bob = "", stranger = "", nobody = "";
17
18 async function person(name: string): Promise<{ id: string; cookie: string }> {
19 const made = await createUser(app.db, { origin: "seed", trusted: true, username: name, email: `${name}@forge.local`, password: "a-good-passphrase", isAdmin: false });
20 if (!made.ok) throw new Error(made.error);
21 return { id: made.value.id, cookie: `forge_session=${createSession(app.db, made.value.id).token}` };
22 }
23 async function claimed(name: string, body: string, email: string, owner: string): Promise<void> {
24 await writeFile(join(dir, "spawn", `${name}.json`), JSON.stringify({ name, bodyId: body, done: true, ownerId: owner }));
25 const child = createApp({ dataDir: join(dir, "children", body) });
26 const made = await createUser(child.db, { origin: "seed", trusted: true, username: name, email, password: "a-good-passphrase", isAdmin: true });
27 if (!made.ok) throw new Error(made.error);
28 child.close();
29 }
30 const pay = (id: string, customer: string, amount: number, currency: string, status: "paid" | "failed" | "refunded", at: string) =>
31 recordPayment(app.db, { kind: "upsert", payment: { id, subscriptionId: undefined, customerId: customer, amountMinor: amount, currency, status, at } });
32
33 beforeAll(async () => {
34 dir = await mkdtemp(join(process.env.TMPDIR ?? tmpdir(), "payments-page-"));
35 app = createApp({ dataDir: dir, port: 0 });
36 const a = await person("alice");
37 bob = (await person("bob")).cookie;
38 stranger = (await person("carol")).cookie;
39 nobody = (await person("dora")).cookie;
40 await mkdir(join(dir, "spawn"), { recursive: true });
41 await claimed("acme", "b1", "[email protected]", a.id);
42 await claimed("beta", "b2", "[email protected]", a.id);
43 putEntitlement(app.db, { forge: "acme", plan: "small", status: "active", customerId: "cus_bob", source: "stripe" }, "small", a.id);
44 putEntitlement(app.db, { forge: "beta", plan: "small", status: "active", customerId: "cus_carol", source: "stripe" }, "small", a.id);
45 pay("in_1", "cus_bob", 1999, "usd", "paid", "2026-10-01T00:00:00.000Z");
46 pay("in_2", "cus_bob", 500, "eur", "refunded", "2026-11-01T00:00:00.000Z");
47 pay("in_3", "cus_bob", 1500, "jpy", "failed", "2026-09-01T00:00:00.000Z");
48 pay("in_4", "cus_carol", 7777, "usd", "paid", "2026-10-15T00:00:00.000Z");
49 servers = await serve(app);
50 dropServed(app);
51 await servedRows(app);
52 });
53 afterAll(async () => {
54 servers.stop();
55 app.close();
56 await rm(dir, { recursive: true, force: true });
57 });
58
59 const get = (cookie?: string) => fetch(`${servers.url}/settings/payments`, { headers: cookie ? { cookie } : {} });
60
61 test("paid, refunded and failed show newest first with amount, plan and status word", async () => {
62 const res = await get(bob);
63 expect(res.status).toBe(200);
64 const text = await res.text();
65 expect(new TextEncoder().encode(text).length).toBeLessThan(10_000);
66 const refunded = text.indexOf("2026-11-01"), paid = text.indexOf("2026-10-01"), failed = text.indexOf("2026-09-01");
67 expect(refunded).toBeGreaterThan(0);
68 expect(refunded).toBeLessThan(paid);
69 expect(paid).toBeLessThan(failed);
70 expect(text).toContain("$19.99");
71 expect(text).toContain("€5.00");
72 expect(text).toContain("¥1,500");
73 expect(text).toContain('data-payment="refunded"');
74 expect(text).toContain("Refunded");
75 expect(text).toContain("Failed");
76 expect(text).toContain("Paid");
77 });
78
79 test("a second account never sees another's rows", async () => {
80 const mine = await (await get(stranger)).text();
81 expect(mine).toContain("$77.77");
82 expect(mine).not.toContain("$19.99");
83 expect(await (await get(bob)).text()).not.toContain("$77.77");
84 });
85
86 test("no payments: one sentence and the /pricing link; signed out is sent to sign in", async () => {
87 const text = await (await get(nobody)).text();
88 expect(text).toContain("No payment has been recorded for you yet.");
89 expect(text).toContain('href="/pricing"');
90 expect(text).not.toContain("data-payments");
91 const out = await fetch(`${servers.url}/settings/payments`, { redirect: "manual" });
92 expect(out.status).toBe(303);
93 expect(out.headers.get("location")).toStartWith("/signin");
94 });
95
96 test("past the cap the page says older payments are not listed", async () => {
97 for (let i = 0; i < 101; i++) pay(`in_many${i}`, "cus_many", 100, "usd", "paid", new Date(Date.UTC(2025, 0, 1 + i)).toISOString());
98 await claimed("many", "b3", "[email protected]", "u");
99 putEntitlement(app.db, { forge: "many", plan: "small", status: "active", customerId: "cus_many", source: "stripe" }, "small", "u");
100 const erin = (await person("erin")).cookie;
101 dropServed(app);
102 await servedRows(app);
103 const text = await (await get(erin)).text();
104 expect(text.match(/data-payment="paid"/g)).toHaveLength(100);
105 expect(text).toContain("data-payments-more");
106 expect(await (await get(bob)).text()).not.toContain("data-payments-more");
107 });
108
109 test("the settings page links to it for a person with no forge too, and a currency the platform does not know is shown as sent", async () => {
110 expect(await (await fetch(`${servers.url}/settings`, { headers: { cookie: bob } })).text()).toContain('href="/settings/payments"');
111 expect(await (await fetch(`${servers.url}/settings`, { headers: { cookie: nobody } })).text()).toContain('href="/settings/payments"');
112 expect(amountWords(1999, "usd")).toBe("$19.99");
113 expect(amountWords(5, "zzzz")).toBe("5 ZZZZ (minor units)");
114 });
test/payments-tui.test.ts added +64
@@ -0,0 +1,64 @@
1 // The terminal's Payments screen shows the owner their rows and a guest nothing (#13093).
2 import { afterAll, beforeAll, expect, test } from "bun:test";
3 import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp } from "../src/app.ts";
7 import { putEntitlement } from "../src/billing/store.ts";
8 import { recordPayment } from "../src/billing/payments.ts";
9 import { createUser, getUserByName } from "../src/core/users.ts";
10 import { serve } from "../src/http/server.ts";
11 import { dropServed, servedRows } from "../src/spawn/clients.ts";
12 import { Session } from "../src/tui/session.ts";
13 import { entry, paymentLines } from "../src/tui/screens/payments.ts";
14
15 let dir = "", app: ReturnType<typeof createApp>, servers: Awaited<ReturnType<typeof serve>>;
16
17 async function user(db: ReturnType<typeof createApp>["db"], name: string): Promise<string> {
18 const made = await createUser(db, { origin: "seed", trusted: true, username: name, email: `${name}@forge.local`, password: "a-good-passphrase", isAdmin: false });
19 if (!made.ok) throw new Error(made.error);
20 return made.value.id;
21 }
22 async function claimed(name: string, body: string, email: string, owner: string): Promise<void> {
23 await writeFile(join(dir, "spawn", `${name}.json`), JSON.stringify({ name, bodyId: body, done: true, ownerId: owner }));
24 const child = createApp({ dataDir: join(dir, "children", body) });
25 const made = await createUser(child.db, { origin: "seed", trusted: true, username: name, email, password: "a-good-passphrase", isAdmin: true });
26 if (!made.ok) throw new Error(made.error);
27 child.close();
28 }
29 const pay = (id: string, customer: string, amount: number, at: string) =>
30 recordPayment(app.db, { kind: "upsert", payment: { id, subscriptionId: undefined, customerId: customer, amountMinor: amount, currency: "usd", status: "paid", at } });
31 const as = (name: string) => new Session(app, { user: getUserByName(app.db, name)!, sshUsername: name, remoteAddress: "127.0.0.1" });
32
33 beforeAll(async () => {
34 dir = await mkdtemp(join(process.env.TMPDIR ?? tmpdir(), "payments-tui-"));
35 app = createApp({ dataDir: dir, port: 0 });
36 const alice = await user(app.db, "alice");
37 await user(app.db, "bob");
38 await user(app.db, "carol");
39 await mkdir(join(dir, "spawn"), { recursive: true });
40 await claimed("acme", "b1", "[email protected]", alice);
41 await claimed("beta", "b2", "[email protected]", alice);
42 putEntitlement(app.db, { forge: "acme", plan: "small", status: "active", customerId: "cus_bob", source: "stripe" }, "small", alice);
43 putEntitlement(app.db, { forge: "beta", plan: "small", status: "active", customerId: "cus_carol", source: "stripe" }, "small", alice);
44 pay("in_1", "cus_bob", 1999, "2026-10-01T00:00:00.000Z");
45 pay("in_4", "cus_carol", 7777, "2026-10-15T00:00:00.000Z");
46 servers = await serve(app);
47 dropServed(app);
48 await servedRows(app);
49 });
50 afterAll(async () => {
51 servers.stop();
52 app.close();
53 await rm(dir, { recursive: true, force: true });
54 });
55
56 test("the owner sees only their rows, and a guest sees nothing", () => {
57 const bob = paymentLines(as("bob")).join("\n");
58 expect(bob).toContain("$19.99");
59 expect(bob).not.toContain("$77.77");
60 const guest = new Session(app, { user: undefined, sshUsername: "guest", remoteAddress: "127.0.0.1" });
61 expect(paymentLines(guest)).toEqual(["No payment has been recorded for you yet. Plans and prices are on /pricing."]);
62 expect(entry.offered(guest)).toBe(false);
63 expect(entry.offered(as("bob"))).toBe(true);
64 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs