Public: anyone can read this; the crew can change it.
The /pricing page says in one line what each plan costs per month and per extra forge, read from the plan table not typed in the page #14551
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14506-the-pricing-page-says-in-one-line-what-e → main 4 commits fork 1 thread · 1 unresolved
2 files
changed +66
−5
src/web/pages/pricing.ts +6 −5
| @@ -57,14 +57,15 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 57 | 57 | const rows = plans.map((p: Plan) => { |
| 58 | 58 | const free = p.key === FREE; |
| 59 | 59 | const paid = !free && selling; |
| 60 | const buy = planWords(p, links).buy; | |
| 60 | const words = planWords(p, links); | |
| 61 | const buy = words.buy; | |
| 61 | 62 | const price = free |
| 62 | ? html`<span data-price>Free</span>` | |
| 63 | ? html`<span data-price>${words.price}</span>` | |
| 63 | 64 | : paid |
| 64 | ? html`<span data-price>$${p.priceUsd} a month</span>` | |
| 65 | ? html`<span data-price>${words.price}</span>` | |
| 65 | 66 | : buy !== undefined |
| 66 | ? html`<span data-price>$${p.priceUsd} a month</span> <a href="${buy}" data-buy rel="noopener noreferrer" target="_blank">Get ${p.name}</a>` | |
| 67 | : html`<span data-price>$${p.priceUsd} a month</span> <span class="muted">ask the operator · for organizations, <a href="https://www.espodev.com">EspoDev</a></span>`; | |
| 67 | ? html`<span data-price>${words.price}</span> <a href="${buy}" data-buy rel="noopener noreferrer" target="_blank">Get ${p.name}</a>` | |
| 68 | : html`<span data-price>${words.price}</span> <span class="muted">ask the operator · for organizations, <a href="https://www.espodev.com">EspoDev</a></span>`; | |
| 68 | 69 | const act = free ? btn(START_BUTTON, { formaction: "/forges/start" }) : paid ? btn(`Get ${p.name}`, { name: "plan", value: p.key, variant: "primary" }) : null; |
| 69 | 70 | const count = ` Up to ${p.forges} ${p.forges === 1 ? "forge" : "forges"}.`; |
| 70 | 71 | return planOfferRow({ key: p.key, name: p.name, says: `${planWords(p, links, door.startUsd).is}${count}`, price, action: act }); |
test/pricing-checkout-same-rows.test.ts added +60
| @@ -0,0 +1,60 @@ | ||
| 1 | /** | |
| 2 | * /pricing and the checkout it opens read the same plan row: change the row, both change (#14506). | |
| 3 | */ | |
| 4 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 5 | import { mkdtemp, readFile, rm } from "node:fs/promises"; | |
| 6 | import { tmpdir } from "node:os"; | |
| 7 | import { join } from "node:path"; | |
| 8 | import { createApp, type App } from "../src/app.ts"; | |
| 9 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 10 | import { createUser } from "../src/core/users.ts"; | |
| 11 | import { useCheckout } from "../src/billing/checkout.ts"; | |
| 12 | import { placeOrder } from "../src/actions/order.ts"; | |
| 13 | import { ok } from "../src/kernel/result.ts"; | |
| 14 | import { DEFAULT_PLANS, setPlans } from "../src/settings/plans.ts"; | |
| 15 | ||
| 16 | let dir: string; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | let actor: string; | |
| 20 | const charged: number[] = []; | |
| 21 | ||
| 22 | beforeAll(async () => { | |
| 23 | dir = await mkdtemp(join(tmpdir(), "forge-pricing-rows-")); | |
| 24 | app = createApp({ dataDir: dir, port: 0, forgeRepo: "alice/forge-code" }); | |
| 25 | servers = await serve(app); | |
| 26 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 27 | if (!a.ok) throw new Error("user"); | |
| 28 | actor = a.value.id; | |
| 29 | useCheckout(app, { | |
| 30 | name: "fake", | |
| 31 | create: async (req) => { | |
| 32 | charged.push(req.priceUsd); | |
| 33 | return ok({ id: "cs_x", url: "https://pay.fake.test/x" }); | |
| 34 | }, | |
| 35 | state: async () => ok({ paid: false, customer: "c", subscription: "s" }), | |
| 36 | }); | |
| 37 | }); | |
| 38 | afterAll(async () => { | |
| 39 | servers.stop(); | |
| 40 | app.close(); | |
| 41 | await rm(dir, { recursive: true, force: true }); | |
| 42 | }); | |
| 43 | ||
| 44 | test("changing a plan row changes the page's price and the checkout's amount", async () => { | |
| 45 | for (const [price, name] of [[19, "alpha-one"], [37, "alpha-two"]] as const) { | |
| 46 | setPlans(app.db, DEFAULT_PLANS.map((p) => (p.key === "small" ? { ...p, priceUsd: price } : p)), actor); | |
| 47 | const text = await (await fetch(`${servers.url}/pricing`)).text(); | |
| 48 | const start = text.indexOf('data-plan="small"'); | |
| 49 | expect(text.slice(start, text.indexOf("</div>", start))).toContain(`$${price} a month`); | |
| 50 | const placed = await placeOrder(app, { name, plan: "small", email: "[email protected]", address: `addr-${price}` }, new URL(servers.url)); | |
| 51 | expect(placed.ok).toBe(true); | |
| 52 | expect(charged.at(-1)).toBe(price); | |
| 53 | } | |
| 54 | }); | |
| 55 | ||
| 56 | test("the page's source holds no price literal", async () => { | |
| 57 | const src = await readFile(join(import.meta.dir, "../src/web/pages/pricing.ts"), "utf8"); | |
| 58 | expect(src).not.toMatch(/\$\d/); | |
| 59 | expect(src).not.toContain("a month"); | |
| 60 | }); |
new above
offline
Principle 8 / clean: the free and paid branches now render the identical span. Collapse them so only the buy-link and ask-the-operator variants differ.