create-ailk 0.36.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +20 -2
  2. package/component-catalog.json +40 -1
  3. package/component-catalog.md +7 -5
  4. package/dist/add-route.d.ts +5 -0
  5. package/dist/add-route.js +10 -2
  6. package/dist/surfaces.js +60 -19
  7. package/dist/sync-routes.d.ts +15 -1
  8. package/dist/sync-routes.js +58 -6
  9. package/dist/template-record.d.ts +11 -0
  10. package/dist/template-record.js +18 -0
  11. package/dist/update.d.ts +33 -1
  12. package/dist/update.js +439 -56
  13. package/package.json +3 -3
  14. package/templates/.env.example +17 -0
  15. package/templates/apps/api/.env.example +38 -0
  16. package/templates/apps/api/CLAUDE.md +3 -0
  17. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  18. package/templates/apps/mcp/CLAUDE.md +1 -1
  19. package/templates/apps/web/CLAUDE.md +28 -1
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  22. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  38. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  39. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  40. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  41. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  42. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  45. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  46. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  47. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  50. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  54. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  56. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  59. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  60. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  62. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  63. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  64. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  65. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  70. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  71. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  72. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  73. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  75. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  76. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  77. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  79. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  80. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  81. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  82. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  83. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  84. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  85. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  86. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  87. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  88. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  89. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  90. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  91. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  92. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  93. package/templates/apps/web/lib/account-config.ts +132 -8
  94. package/templates/apps/web/lib/auth-routes.ts +11 -6
  95. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  96. package/templates/apps/web/messages/en.json +156 -80
  97. package/versions.json +48 -48
  98. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  99. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  101. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -1,23 +1,32 @@
1
1
  /**
2
2
  * Tests for /[locale]/account/billing — User settings › Billing (#8232, spec
3
- * docs/specs/8232-member-settings-account-general-and-spec.md D1, D9; AC-2).
4
- * The single-site render: `subscription.me` is the mocked boundary.
3
+ * docs/specs/8232-member-settings-account-general-and-spec.md D1, D9; #11165,
4
+ * the card shape of 2026-11-08). The single-site render: `subscription.me`
5
+ * and `offerings.shown` are the mocked boundaries (the shown set reaches the
6
+ * page through `/pricing`'s shared 15 s reader, so each case moves `Date.now`
7
+ * past its window).
5
8
  *
6
9
  * Covers:
7
- * (a) a subscription shows the plan, the status, the card and Manage in
8
- * Stripe; (b) no Manage without a portal; (c) `status: null` and each
9
- * of 401, 403 and 404 say plainly there is no subscription, with no
10
- * button; (d) a 500 or a throw shows the error row, never "no
11
- * subscription"; (e) a contributed billing section renders after every
12
- * one of these; (f) the read asks for `include: "billing"`.
13
- * #9401 AC-9 (spec docs/specs/9401-show-a-buyer-s-ailk-spec.md D7): a
14
- * section the site adds to `siteBillingSections` renders after the
15
- * modules' `accountBillingSections`, each under its `ctx.t(title)`.
16
- * #8217 AC-1 (spec docs/specs/8217-spoke-billing-spoke-checkout-reads-spec.md
17
- * D10, D11): `openBillingPortal()` mints the portal through
18
- * `billingPortalUrl()` — the hub's route, once, with the cookie init — and
19
- * redirects to it; a non-2xx or a throw redirects nowhere. The single site
20
- * never shows the unreadable line.
10
+ * #11165 AC-1 (B1) — a subscription renders the plan card: the name, the
11
+ * status line with the card ("Active · Visa 4242", "Payment due",
12
+ * "Access ends <Month D>"), Manage plan; no "Current plan" heading; no
13
+ * Manage without a portal.
14
+ * #11165 AC-2 (B2) — with no subscription (`status: null`, 401, 403, 404)
15
+ * the shown set's lowest-priced live plan is the card, with its Stripe
16
+ * description or the fallback line and Upgrade to the next live plan by
17
+ * price — Essentials → Growth on a three-plan set; one plan has no
18
+ * Upgrade; a set with no live plan, an unconnected site or an expired
19
+ * set renders no plan card; "You don't have a subscription." is gone.
20
+ * #11165 AC-3 (A) — the first live Offer renders above the plan card with
21
+ * Claim offer to the Offerings checkout carrying its promotion code;
22
+ * none without one. (The dismissal is `OfferCard`'s own suite.)
23
+ * #11165 AC-4 (C) — a single site reads no History and renders no card.
24
+ * (d) a 500 or a throw shows the error row, never a plan card; (e) a
25
+ * contributed billing section renders after the base content; (f) the
26
+ * read asks for `include: "billing"`.
27
+ * #9401 AC-9: a section the site adds renders after the modules'.
28
+ * #8217 AC-1 (D10, D11): `openBillingPortal()` mints the portal through
29
+ * the hub's route, once, with the cookie init, and redirects there.
21
30
  */
22
31
  import { render, screen, within } from "@testing-library/react";
23
32
 
@@ -33,13 +42,16 @@ jest.mock("next-intl/server", () => {
33
42
  getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
34
43
  const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
35
44
  const messages = dig(msgs, ns);
36
- return (key: string, values?: Record<string, unknown>): string => {
45
+ const t = (key: string, values?: Record<string, unknown>): string => {
37
46
  const value = dig(messages, key);
38
47
  if (typeof value !== "string") return `${ns}.${key}`;
39
48
  return value.replace(/\{(\w+)\}/g, (m, name: string) =>
40
49
  values && name in values ? String(values[name]) : m,
41
50
  );
42
51
  };
52
+ // #11175: the dated messages carry a `<date>` tag and render through `t.rich`.
53
+ const { withRich } = require("./rich-translator") as typeof import("./rich-translator");
54
+ return withRich(t, (key: string) => dig(messages, key), ns);
43
55
  },
44
56
  };
45
57
  });
@@ -60,6 +72,8 @@ jest.mock("../../../../../auth", () => ({
60
72
  const mockSubscriptionMe = jest.fn();
61
73
  const mockPortalSession = jest.fn();
62
74
  const mockMemberPurchases = jest.fn();
75
+ const mockMemberBilling = jest.fn();
76
+ const mockOfferingsShown = jest.fn();
63
77
  jest.mock("@working-theory/api-client", () => ({
64
78
  __esModule: true,
65
79
  waitlistSignups: { me: jest.fn() },
@@ -69,7 +83,12 @@ jest.mock("@working-theory/api-client", () => ({
69
83
  portalSession: (...args: unknown[]) => mockPortalSession(...args),
70
84
  },
71
85
  leads: { submit: jest.fn() },
72
- member: { purchases: (...args: unknown[]) => mockMemberPurchases(...args) },
86
+ member: {
87
+ purchases: (...args: unknown[]) => mockMemberPurchases(...args),
88
+ billing: (...args: unknown[]) => mockMemberBilling(...args),
89
+ billingPortal: jest.fn(),
90
+ },
91
+ offerings: { shown: (...args: unknown[]) => mockOfferingsShown(...args) },
73
92
  hubSignIn: { me: jest.fn() },
74
93
  visitorForwardHeaders: () => null,
75
94
  }));
@@ -83,6 +102,7 @@ jest.mock("next/navigation", () => ({
83
102
  }));
84
103
 
85
104
  import type { AccountBillingSection } from "@working-theory/templates/account";
105
+ import type { OfferingsProduct, WorkspaceShownSetWire } from "@working-theory/validation";
86
106
 
87
107
  import { accountBillingSections } from "../../../../../lib/account-config";
88
108
  import { siteBillingSections } from "../../../../../lib/site-contributions";
@@ -113,11 +133,76 @@ const ACTIVE = {
113
133
  };
114
134
 
115
135
  const answer = (body: Record<string, unknown>) => ({ ok: true, body: { ...ACTIVE, ...body } });
136
+ const noSubscription = () => mockSubscriptionMe.mockResolvedValue(answer({ status: null }));
137
+
138
+ // ─── The shown set: the Sam Henry workspace's three plans and one offer ──────
139
+
140
+ function plan(slug: string, name: string, amount: number, extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
141
+ return {
142
+ productId: `prod_${slug.replace(/-/g, "")}`,
143
+ plan: slug,
144
+ name,
145
+ description: null,
146
+ marketingFeatures: [],
147
+ unitLabel: null,
148
+ note: null,
149
+ termsNote: null,
150
+ ailkGroup: "plan",
151
+ ailkOrder: null,
152
+ prices: [
153
+ {
154
+ priceId: `price_${slug.replace(/-/g, "")}_monthly`,
155
+ lookupKey: `${slug}_monthly`,
156
+ plan: slug,
157
+ period: "monthly",
158
+ interval: "month",
159
+ amount,
160
+ currency: "usd",
161
+ },
162
+ ],
163
+ recommended: false,
164
+ ...extra,
165
+ };
166
+ }
167
+
168
+ const OFFER: OfferingsProduct = {
169
+ ...plan("welcome", "Two weeks of Growth, on us", 0),
170
+ productId: "prod_welcome",
171
+ description: "Try the Growth plan for two weeks before you commit.",
172
+ ailkGroup: "offer",
173
+ prices: [
174
+ { priceId: "price_welcome_once", lookupKey: "welcome_once", plan: "welcome", period: "once", interval: null, amount: 0, currency: "usd" },
175
+ ],
176
+ image: "https://files.stripe.com/links/offer.png",
177
+ promotionCode: "WELCOME20",
178
+ };
179
+
180
+ /** Growth listed before Essentials, so the order under test is the price's, not the snapshot's. */
181
+ function threePlans(offerings: OfferingsProduct[] = [plan("growth", "Growth", 2_500_000), plan("essentials", "Essentials", 1_250_000), plan("scale", "Scale", 5_000_000)]): WorkspaceShownSetWire {
182
+ return {
183
+ productIds: offerings.map((o) => o.productId),
184
+ recommended: { plan: null, addon: null },
185
+ offerings,
186
+ state: "current",
187
+ snapshotAt: "2026-11-08T00:00:00.000Z",
188
+ };
189
+ }
190
+
191
+ const shown = (shownSet: WorkspaceShownSetWire) => mockOfferingsShown.mockResolvedValue({ ok: true, body: { status: "shown", shownSet } });
192
+
193
+ // /pricing's reader shares one read per instance for 15 s; each case starts
194
+ // past the last one's window, so its own answer is read.
195
+ let clock = Date.UTC(2026, 10, 8);
196
+ jest.spyOn(Date, "now").mockImplementation(() => clock);
116
197
 
117
198
  beforeEach(() => {
118
199
  mockGetSession.mockReset().mockResolvedValue(SESSION);
119
200
  mockSubscriptionMe.mockReset().mockResolvedValue(answer({}));
120
201
  mockPortalSession.mockReset();
202
+ mockMemberPurchases.mockReset();
203
+ mockMemberBilling.mockReset();
204
+ mockOfferingsShown.mockReset().mockResolvedValue({ ok: true, body: { status: "unconnected" } });
205
+ clock += 60_000;
121
206
  mockRedirect.mockReset();
122
207
  });
123
208
 
@@ -127,9 +212,10 @@ async function renderPage(locale = "en"): Promise<void> {
127
212
  }
128
213
 
129
214
  describe("the frame (D7)", () => {
130
- it("renders in the settings frame with Billing current", async () => {
215
+ it("renders in the settings frame with Billing current and the new lead", async () => {
131
216
  await renderPage();
132
217
  expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Billing");
218
+ expect(screen.getByText("Your plan, purchases and payment method.")).toBeInTheDocument();
133
219
  expect(screen.getByTestId("account-settings-back")).toHaveAttribute("href", "/account");
134
220
  expect(screen.getByTestId("account-settings-rail-billing")).toHaveAttribute("aria-current", "page");
135
221
  expect(screen.getByTestId("account-settings-rail-general")).not.toHaveAttribute("aria-current");
@@ -150,102 +236,190 @@ describe("the standalone shape (#8430)", () => {
150
236
  });
151
237
  });
152
238
 
153
- describe("AC-5 — Billing as the current-plan card (D8)", () => {
154
- it("(a) shows the plan, the status, the card and Manage billing under the Current plan heading", async () => {
239
+ describe("#11165 AC-1 (B1) — a subscription is the plan card", () => {
240
+ it("shows the plan name, the status line with the card, and Manage plan — and no 'Current plan' heading", async () => {
155
241
  await renderPage();
156
- expect(screen.getByText("Current plan")).toBeInTheDocument();
157
- const card = screen.getByTestId("account-billing-card");
242
+ const card = screen.getByTestId("account-billing");
243
+ expect(within(card).getByRole("heading", { level: 2 })).toHaveTextContent("Pro");
158
244
  expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Pro");
159
- expect(within(card).getByTestId("account-billing-status")).toHaveTextContent("Active");
160
- expect(within(card).getByTestId("account-billing-payment")).toHaveTextContent(
161
- "visa ending in 4242, expires 04/2027",
162
- );
163
- expect(screen.getByTestId("account-billing-manage")).toHaveTextContent("Manage billing");
164
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
245
+ expect(within(card).getByTestId("account-billing-status")).toHaveTextContent("Active · Visa 4242");
246
+ expect(within(card).getByTestId("account-billing-payment")).toHaveTextContent("Visa 4242");
247
+ expect(screen.getByTestId("account-billing-manage")).toHaveTextContent("Manage plan");
248
+ expect(screen.queryByText("Current plan")).not.toBeInTheDocument();
249
+ expect(screen.queryByText("You don't have a subscription.")).not.toBeInTheDocument();
165
250
  expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
251
+ // The single site's read carries no price or renewal date (#8171's fields only).
252
+ expect(within(card).queryByTestId("account-billing-price")).not.toBeInTheDocument();
253
+ // Exactly one card on the pane: no empty shell for the absent offer or History.
254
+ expect(screen.getAllByTestId("account-settings-billing-card")).toHaveLength(1);
166
255
  });
167
256
 
168
- it("(a) no plan name reads as 'Your subscription', and no card as 'No card on file'", async () => {
169
- mockSubscriptionMe.mockResolvedValue(
170
- answer({ status: "past_due", planName: null, paymentMethod: null }),
171
- );
257
+ it("no plan name reads as 'Your subscription', and no card leaves the status alone", async () => {
258
+ mockSubscriptionMe.mockResolvedValue(answer({ status: "past_due", planName: null, paymentMethod: null }));
172
259
  await renderPage();
173
260
  expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Your subscription");
174
261
  expect(screen.getByTestId("account-billing-status")).toHaveTextContent("Payment due");
175
- expect(screen.getByTestId("account-billing-payment")).toHaveTextContent("No card on file");
262
+ expect(screen.queryByTestId("account-billing-payment")).not.toBeInTheDocument();
176
263
  });
177
264
 
178
- it("(a) an older API without the billing fields still renders the status", async () => {
265
+ it("an older API without the billing fields still renders the status", async () => {
179
266
  mockSubscriptionMe.mockResolvedValue({
180
267
  ok: true,
181
268
  body: { actionRequired: false, status: "trialing", accessRevokesAt: null, portalAvailable: false },
182
269
  });
183
270
  await renderPage();
184
271
  expect(screen.getByTestId("account-billing-status")).toHaveTextContent("Trial");
185
- expect(screen.getByTestId("account-billing-payment")).toHaveTextContent("No card on file");
186
272
  });
187
273
 
188
- it("(a) appends when access ends, when set", async () => {
274
+ it("canceled with an access end reads 'Access ends <Month D>' in a <time>", async () => {
189
275
  mockSubscriptionMe.mockResolvedValue(
190
276
  answer({ status: "canceled", accessRevokesAt: "2026-10-20T00:00:00.000Z" }),
191
277
  );
192
278
  await renderPage();
193
279
  const status = screen.getByTestId("account-billing-status");
194
- expect(status).toHaveTextContent("Canceled");
195
- expect(status).toHaveTextContent("Access ends");
280
+ expect(status).toHaveTextContent("Access ends October 20 · Visa 4242");
281
+ expect(within(status).getByText("October 20")).toHaveAttribute("dateTime", "2026-10-20T00:00:00.000Z");
196
282
  });
197
283
 
198
- it("(b) no portal, no Manage button", async () => {
284
+ it("no portal, no Manage plan", async () => {
199
285
  mockSubscriptionMe.mockResolvedValue(answer({ portalAvailable: false }));
200
286
  await renderPage();
201
- expect(screen.getByTestId("account-billing-card")).toBeInTheDocument();
287
+ expect(screen.getByTestId("account-billing")).toBeInTheDocument();
202
288
  expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
203
289
  });
204
290
 
205
- it("(c) status: null renders the same card shape with the plain line and no button — even with a portal", async () => {
206
- mockSubscriptionMe.mockResolvedValue(answer({ status: null, portalAvailable: true }));
291
+ it("(f) the read asks for the billing fields with the caller's cookie", async () => {
292
+ await renderPage();
293
+ expect(mockSubscriptionMe).toHaveBeenCalledWith(
294
+ { headers: { cookie: "session=abc" } },
295
+ { include: "billing" },
296
+ );
297
+ });
298
+ });
299
+
300
+ describe("#11165 AC-2 (B2) — no subscription is the base plan with Upgrade", () => {
301
+ it("renders the lowest-priced live plan — Essentials, its price muted, the fallback line — with Upgrade to the next by price, Growth", async () => {
302
+ noSubscription();
303
+ shown(threePlans());
207
304
  await renderPage();
208
- expect(screen.getByTestId("account-billing-none")).toHaveTextContent("You don't have a subscription.");
305
+ const card = screen.getByTestId("account-billing");
306
+ expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Essentials");
307
+ expect(within(card).getByTestId("account-billing-price")).toHaveTextContent("$12,500/mo");
308
+ expect(within(card).getByTestId("account-billing-description")).toHaveTextContent(
309
+ "Entry-level plan with access to 1, 2, 3, and more.",
310
+ );
311
+ const upgrade = within(card).getByTestId("account-billing-upgrade");
312
+ expect(upgrade).toHaveTextContent("Upgrade");
313
+ expect(upgrade).toHaveAttribute("href", "/api/offerings/checkout/growth_monthly");
209
314
  expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
210
- expect(screen.queryByTestId("account-billing-plan")).not.toBeInTheDocument();
211
315
  expect(screen.queryByTestId("account-billing-status")).not.toBeInTheDocument();
212
- expect(screen.queryByTestId("account-billing-payment")).not.toBeInTheDocument();
316
+ expect(screen.queryByText("You don't have a subscription.")).not.toBeInTheDocument();
317
+ });
318
+
319
+ it("the Stripe product's description wins over the fallback line", async () => {
320
+ noSubscription();
321
+ shown(threePlans([plan("essentials", "Essentials", 1_250_000, { description: "Two sites, one seat." })]));
322
+ await renderPage();
323
+ expect(screen.getByTestId("account-billing-description")).toHaveTextContent("Two sites, one seat.");
324
+ // One plan: nothing above it, so no Upgrade.
325
+ expect(screen.queryByTestId("account-billing-upgrade")).not.toBeInTheDocument();
213
326
  });
214
327
 
215
- it.each([401, 403, 404])("(c) a %i says there is no subscription, with no button", async (status) => {
328
+ it.each([401, 403, 404])("a %i is no subscription: the base plan, never an error row", async (status) => {
216
329
  mockSubscriptionMe.mockResolvedValue({ ok: false, status, body: {} });
330
+ shown(threePlans());
217
331
  await renderPage();
218
- expect(screen.getByTestId("account-billing-none")).toBeInTheDocument();
219
- expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
332
+ expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Essentials");
333
+ expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
334
+ });
335
+
336
+ it.each([
337
+ ["an unconnected site", () => undefined],
338
+ ["an empty answer", () => mockOfferingsShown.mockResolvedValue({ ok: true, body: { status: "empty" } })],
339
+ ["a failed read", () => mockOfferingsShown.mockRejectedValue(new TypeError("fetch failed"))],
340
+ ["a shown set with no live plan", () => shown(threePlans([{ ...plan("seo", "SEO audit", 1000), ailkGroup: "addon" }]))],
341
+ ["an expired set", () => shown({ ...threePlans(), state: "expired", offerings: [] })],
342
+ ])("with no subscription and %s there is no plan card at all", async (_label, arrange) => {
343
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
344
+ noSubscription();
345
+ arrange();
346
+ await renderPage();
347
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
348
+ expect(screen.queryByTestId("account-billing-upgrade")).not.toBeInTheDocument();
220
349
  expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
350
+ // Nothing to show is no card at all — never an empty shell.
351
+ expect(screen.queryByTestId("account-settings-billing-card")).not.toBeInTheDocument();
352
+ errorSpy.mockRestore();
353
+ });
354
+ });
355
+
356
+ describe("#11165 AC-3 (A) — the offer card", () => {
357
+ it("renders the first live Offer above the plan card: its name, description, image and Claim offer with its promotion code", async () => {
358
+ noSubscription();
359
+ shown(threePlans([plan("essentials", "Essentials", 1_250_000), OFFER]));
360
+ await renderPage();
361
+ const offer = screen.getByTestId("account-billing-offer");
362
+ expect(within(offer).getByRole("heading", { level: 2 })).toHaveTextContent("Two weeks of Growth, on us");
363
+ expect(within(offer).getByTestId("account-billing-offer-description")).toHaveTextContent(
364
+ "Try the Growth plan for two weeks before you commit.",
365
+ );
366
+ expect(within(offer).getByRole("img", { name: "Two weeks of Growth, on us" })).toHaveAttribute(
367
+ "src",
368
+ "https://files.stripe.com/links/offer.png",
369
+ );
370
+ expect(within(offer).getByTestId("account-billing-offer-claim")).toHaveAttribute(
371
+ "href",
372
+ "/api/offerings/checkout/welcome_once?promo=WELCOME20",
373
+ );
374
+ expect(within(offer).getByRole("button", { name: "Dismiss offer" })).toBeInTheDocument();
375
+ const card = screen.getByTestId("account-billing");
376
+ expect(offer.compareDocumentPosition(card) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
377
+ // Two cards — the offer's own and the plan's — and the offer's is the first.
378
+ const cards = screen.getAllByTestId("account-settings-billing-card");
379
+ expect(cards).toHaveLength(2);
380
+ expect(cards[0]).toContainElement(offer);
221
381
  });
222
382
 
223
- it("(g) through D6, the member card renders the shared CurrentPlanCard — exactly one card", async () => {
383
+ it("renders beside a subscription too, and none when the shown set has no offer", async () => {
384
+ shown(threePlans([plan("essentials", "Essentials", 1_250_000), OFFER]));
224
385
  await renderPage();
225
- expect(screen.getAllByTestId("account-billing-card")).toHaveLength(1);
386
+ expect(screen.getByTestId("account-billing-offer")).toBeInTheDocument();
387
+ expect(screen.getByTestId("account-billing-manage")).toBeInTheDocument();
226
388
  });
227
389
 
228
- it("(d) a 500 shows the error row with Retry, not 'no subscription'", async () => {
390
+ it("none when the shown set has no offer — and no shell for it", async () => {
391
+ shown(threePlans());
392
+ await renderPage();
393
+ expect(screen.queryByTestId("account-billing-offer")).not.toBeInTheDocument();
394
+ expect(screen.getAllByTestId("account-settings-billing-card")).toHaveLength(1);
395
+ });
396
+ });
397
+
398
+ describe("(d) — a failed read is the error row, never a plan card", () => {
399
+ it("a 500 shows the error row with Retry", async () => {
229
400
  mockSubscriptionMe.mockResolvedValue({ ok: false, status: 500, body: {} });
401
+ shown(threePlans());
230
402
  await renderPage();
231
403
  expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't load your billing details.");
232
404
  expect(screen.getByTestId("inbox-retry")).toBeInTheDocument();
233
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
405
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
234
406
  });
235
407
 
236
- it("(d) a throw shows the error row, not 'no subscription'", async () => {
408
+ it("a throw shows the error row", async () => {
237
409
  mockSubscriptionMe.mockRejectedValue(new TypeError("fetch failed"));
238
410
  await renderPage();
239
411
  expect(screen.getByTestId("inbox-error")).toBeInTheDocument();
240
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
412
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
241
413
  });
414
+ });
242
415
 
243
- it("(f) the read asks for the billing fields with the caller's cookie", async () => {
416
+ describe("#11165 AC-4 (C) — no History on a single site", () => {
417
+ it("never reads member.purchases or member.billing, and renders no History card or purchases list", async () => {
244
418
  await renderPage();
245
- expect(mockSubscriptionMe).toHaveBeenCalledWith(
246
- { headers: { cookie: "session=abc" } },
247
- { include: "billing" },
248
- );
419
+ expect(mockMemberPurchases).not.toHaveBeenCalled();
420
+ expect(mockMemberBilling).not.toHaveBeenCalled();
421
+ expect(screen.queryByTestId("account-billing-history")).not.toBeInTheDocument();
422
+ expect(screen.queryByText("Purchases")).not.toBeInTheDocument();
249
423
  });
250
424
  });
251
425
 
@@ -265,9 +439,9 @@ describe("AC-2 (e) — contributed billing sections render after the base conten
265
439
  });
266
440
 
267
441
  const states: [string, () => void, string][] = [
268
- ["a subscription", () => undefined, "account-billing-card"],
269
- ["no subscription", () => mockSubscriptionMe.mockResolvedValue(answer({ status: null })), "account-billing-card"],
270
- ["a 404", () => mockSubscriptionMe.mockResolvedValue({ ok: false, status: 404, body: {} }), "account-billing-card"],
442
+ ["a subscription", () => undefined, "account-billing"],
443
+ ["no subscription", () => { noSubscription(); shown(threePlans()); }, "account-billing"],
444
+ ["a 404", () => { mockSubscriptionMe.mockResolvedValue({ ok: false, status: 404, body: {} }); shown(threePlans()); }, "account-billing"],
271
445
  ["a failed read", () => mockSubscriptionMe.mockResolvedValue({ ok: false, status: 500, body: {} }), "inbox-error"],
272
446
  ];
273
447
 
@@ -284,7 +458,7 @@ describe("AC-2 (e) — contributed billing sections render after the base conten
284
458
  describe("#9401 AC-9 — a site's own section renders after the modules' (D7)", () => {
285
459
  const moduleSection: AccountBillingSection = {
286
460
  id: "module",
287
- title: "settings.billing.currentPlan",
461
+ title: "settings.billing.history",
288
462
  render: () => <p data-testid="module-body">Module</p>,
289
463
  };
290
464
  const siteSection: AccountBillingSection = {
@@ -309,13 +483,13 @@ describe("#9401 AC-9 — a site's own section renders after the modules' (D7)",
309
483
  const site = screen.getByTestId("account-settings-site");
310
484
  expect(within(contributed).getByTestId("module-body")).toBeInTheDocument();
311
485
  expect(within(site).getByTestId("site-body")).toBeInTheDocument();
312
- expect(within(contributed).getByRole("heading", { level: 2 })).toHaveTextContent("Current plan");
486
+ expect(within(contributed).getByRole("heading", { level: 2 })).toHaveTextContent("History");
313
487
  expect(within(site).getByRole("heading", { level: 2 })).toHaveTextContent("Billing");
314
488
  expect(contributed.compareDocumentPosition(site) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
315
489
  });
316
490
  });
317
491
 
318
- describe("#8217 AC-1 — the single site's Manage billing (D10, D11)", () => {
492
+ describe("#8217 AC-1 — the single site's Manage plan (D10, D11)", () => {
319
493
  const PORTAL_URL = "https://billing.stripe.com/p/session/test_single_site";
320
494
 
321
495
  it("mints the portal once through the hub's route with the cookie init, then redirects there", async () => {
@@ -339,13 +513,3 @@ describe("#8217 AC-1 — the single site's Manage billing (D10, D11)", () => {
339
513
  errorSpy.mockRestore();
340
514
  });
341
515
  });
342
-
343
- // #11096 D9 — the Purchases list is a hub-sign-in spoke's; a hub's own Billing
344
- // never reads it.
345
- describe("#11096 — no Purchases list on a hub", () => {
346
- it("never reads member.purchases and renders no Purchases section", async () => {
347
- await renderPage();
348
- expect(mockMemberPurchases).not.toHaveBeenCalled();
349
- expect(screen.queryByTestId("account-billing-purchases")).not.toBeInTheDocument();
350
- });
351
- });