create-ailk 0.35.1 → 0.37.0

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 (169) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +51 -1
  3. package/component-catalog.md +8 -5
  4. package/dist/lib/env-catalog.js +8 -0
  5. package/dist/surfaces.js +66 -22
  6. package/dist/topology.d.ts +4 -4
  7. package/dist/topology.js +104 -60
  8. package/dist/update.d.ts +19 -1
  9. package/dist/update.js +293 -35
  10. package/package.json +3 -3
  11. package/templates/.env.example +38 -0
  12. package/templates/apps/api/.env.example +45 -0
  13. package/templates/apps/api/CLAUDE.md +12 -4
  14. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  15. package/templates/apps/mcp/CLAUDE.md +4 -2
  16. package/templates/apps/web/.env.example +16 -0
  17. package/templates/apps/web/CLAUDE.md +73 -5
  18. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  19. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  22. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  23. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  24. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  25. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  26. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  27. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  28. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  29. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +241 -66
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +377 -151
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  37. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  38. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  39. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  40. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  41. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  42. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  44. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  45. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  46. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +20 -4
  47. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  48. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  53. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  54. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  55. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  56. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  57. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  58. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  59. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  60. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +323 -73
  61. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +199 -43
  62. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  63. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  64. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  65. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  70. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +97 -53
  71. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  72. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +215 -0
  73. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  75. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  76. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  77. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  79. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  80. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  81. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  82. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  83. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  84. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  85. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  86. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +9 -6
  87. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  88. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  89. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  90. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  91. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  92. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  93. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  94. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  95. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  96. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +21 -22
  97. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  98. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  99. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  101. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  102. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  103. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  104. package/templates/apps/web/app/[locale]/layout.tsx +24 -75
  105. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  106. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  107. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  108. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
  109. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
  110. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  111. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  112. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  113. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  114. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  115. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  116. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  117. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  118. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  119. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  120. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  121. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +738 -7
  122. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  123. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  124. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  125. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  126. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  127. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  128. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  129. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  130. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  131. package/templates/apps/web/auth.ts +133 -6
  132. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  133. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  134. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  135. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  136. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  137. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  138. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  139. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  140. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  141. package/templates/apps/web/lib/account-config.ts +132 -8
  142. package/templates/apps/web/lib/auth-email.ts +62 -6
  143. package/templates/apps/web/lib/auth-env.ts +13 -0
  144. package/templates/apps/web/lib/auth-routes.ts +11 -6
  145. package/templates/apps/web/lib/auth-sms.ts +180 -0
  146. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  147. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  148. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  149. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  150. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  151. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  152. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  153. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  154. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  155. package/templates/apps/web/lib/site-header.ts +14 -1
  156. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  157. package/templates/apps/web/lib/topology.generated.ts +39 -0
  158. package/templates/apps/web/messages/en.json +264 -96
  159. package/templates/apps/web/middleware.ts +34 -2
  160. package/templates/apps/web/security-headers.config.ts +21 -0
  161. package/versions.json +48 -48
  162. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  163. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  164. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  165. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
  166. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  167. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  168. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  169. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -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
  });
@@ -59,6 +71,9 @@ jest.mock("../../../../../auth", () => ({
59
71
 
60
72
  const mockSubscriptionMe = jest.fn();
61
73
  const mockPortalSession = jest.fn();
74
+ const mockMemberPurchases = jest.fn();
75
+ const mockMemberBilling = jest.fn();
76
+ const mockOfferingsShown = jest.fn();
62
77
  jest.mock("@working-theory/api-client", () => ({
63
78
  __esModule: true,
64
79
  waitlistSignups: { me: jest.fn() },
@@ -68,7 +83,12 @@ jest.mock("@working-theory/api-client", () => ({
68
83
  portalSession: (...args: unknown[]) => mockPortalSession(...args),
69
84
  },
70
85
  leads: { submit: jest.fn() },
71
- member: {},
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) },
72
92
  hubSignIn: { me: jest.fn() },
73
93
  visitorForwardHeaders: () => null,
74
94
  }));
@@ -82,6 +102,7 @@ jest.mock("next/navigation", () => ({
82
102
  }));
83
103
 
84
104
  import type { AccountBillingSection } from "@working-theory/templates/account";
105
+ import type { OfferingsProduct, WorkspaceShownSetWire } from "@working-theory/validation";
85
106
 
86
107
  import { accountBillingSections } from "../../../../../lib/account-config";
87
108
  import { siteBillingSections } from "../../../../../lib/site-contributions";
@@ -112,11 +133,76 @@ const ACTIVE = {
112
133
  };
113
134
 
114
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);
115
197
 
116
198
  beforeEach(() => {
117
199
  mockGetSession.mockReset().mockResolvedValue(SESSION);
118
200
  mockSubscriptionMe.mockReset().mockResolvedValue(answer({}));
119
201
  mockPortalSession.mockReset();
202
+ mockMemberPurchases.mockReset();
203
+ mockMemberBilling.mockReset();
204
+ mockOfferingsShown.mockReset().mockResolvedValue({ ok: true, body: { status: "unconnected" } });
205
+ clock += 60_000;
120
206
  mockRedirect.mockReset();
121
207
  });
122
208
 
@@ -126,9 +212,10 @@ async function renderPage(locale = "en"): Promise<void> {
126
212
  }
127
213
 
128
214
  describe("the frame (D7)", () => {
129
- 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 () => {
130
216
  await renderPage();
131
217
  expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Billing");
218
+ expect(screen.getByText("Your plan, purchases and payment method.")).toBeInTheDocument();
132
219
  expect(screen.getByTestId("account-settings-back")).toHaveAttribute("href", "/account");
133
220
  expect(screen.getByTestId("account-settings-rail-billing")).toHaveAttribute("aria-current", "page");
134
221
  expect(screen.getByTestId("account-settings-rail-general")).not.toHaveAttribute("aria-current");
@@ -149,102 +236,190 @@ describe("the standalone shape (#8430)", () => {
149
236
  });
150
237
  });
151
238
 
152
- describe("AC-5 — Billing as the current-plan card (D8)", () => {
153
- 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 () => {
154
241
  await renderPage();
155
- expect(screen.getByText("Current plan")).toBeInTheDocument();
156
- const card = screen.getByTestId("account-billing-card");
242
+ const card = screen.getByTestId("account-billing");
243
+ expect(within(card).getByRole("heading", { level: 2 })).toHaveTextContent("Pro");
157
244
  expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Pro");
158
- expect(within(card).getByTestId("account-billing-status")).toHaveTextContent("Active");
159
- expect(within(card).getByTestId("account-billing-payment")).toHaveTextContent(
160
- "visa ending in 4242, expires 04/2027",
161
- );
162
- expect(screen.getByTestId("account-billing-manage")).toHaveTextContent("Manage billing");
163
- 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();
164
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);
165
255
  });
166
256
 
167
- it("(a) no plan name reads as 'Your subscription', and no card as 'No card on file'", async () => {
168
- mockSubscriptionMe.mockResolvedValue(
169
- answer({ status: "past_due", planName: null, paymentMethod: null }),
170
- );
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 }));
171
259
  await renderPage();
172
260
  expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Your subscription");
173
261
  expect(screen.getByTestId("account-billing-status")).toHaveTextContent("Payment due");
174
- expect(screen.getByTestId("account-billing-payment")).toHaveTextContent("No card on file");
262
+ expect(screen.queryByTestId("account-billing-payment")).not.toBeInTheDocument();
175
263
  });
176
264
 
177
- 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 () => {
178
266
  mockSubscriptionMe.mockResolvedValue({
179
267
  ok: true,
180
268
  body: { actionRequired: false, status: "trialing", accessRevokesAt: null, portalAvailable: false },
181
269
  });
182
270
  await renderPage();
183
271
  expect(screen.getByTestId("account-billing-status")).toHaveTextContent("Trial");
184
- expect(screen.getByTestId("account-billing-payment")).toHaveTextContent("No card on file");
185
272
  });
186
273
 
187
- 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 () => {
188
275
  mockSubscriptionMe.mockResolvedValue(
189
276
  answer({ status: "canceled", accessRevokesAt: "2026-10-20T00:00:00.000Z" }),
190
277
  );
191
278
  await renderPage();
192
279
  const status = screen.getByTestId("account-billing-status");
193
- expect(status).toHaveTextContent("Canceled");
194
- 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");
195
282
  });
196
283
 
197
- it("(b) no portal, no Manage button", async () => {
284
+ it("no portal, no Manage plan", async () => {
198
285
  mockSubscriptionMe.mockResolvedValue(answer({ portalAvailable: false }));
199
286
  await renderPage();
200
- expect(screen.getByTestId("account-billing-card")).toBeInTheDocument();
287
+ expect(screen.getByTestId("account-billing")).toBeInTheDocument();
201
288
  expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
202
289
  });
203
290
 
204
- it("(c) status: null renders the same card shape with the plain line and no button — even with a portal", async () => {
205
- 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());
206
304
  await renderPage();
207
- 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");
208
314
  expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
209
- expect(screen.queryByTestId("account-billing-plan")).not.toBeInTheDocument();
210
315
  expect(screen.queryByTestId("account-billing-status")).not.toBeInTheDocument();
211
- expect(screen.queryByTestId("account-billing-payment")).not.toBeInTheDocument();
316
+ expect(screen.queryByText("You don't have a subscription.")).not.toBeInTheDocument();
212
317
  });
213
318
 
214
- it.each([401, 403, 404])("(c) a %i says there is no subscription, with no button", async (status) => {
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();
326
+ });
327
+
328
+ it.each([401, 403, 404])("a %i is no subscription: the base plan, never an error row", async (status) => {
215
329
  mockSubscriptionMe.mockResolvedValue({ ok: false, status, body: {} });
330
+ shown(threePlans());
216
331
  await renderPage();
217
- expect(screen.getByTestId("account-billing-none")).toBeInTheDocument();
218
- expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
332
+ expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Essentials");
219
333
  expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
220
334
  });
221
335
 
222
- it("(g) through D6, the member card renders the shared CurrentPlanCard — exactly one card", async () => {
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();
223
346
  await renderPage();
224
- expect(screen.getAllByTestId("account-billing-card")).toHaveLength(1);
347
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
348
+ expect(screen.queryByTestId("account-billing-upgrade")).not.toBeInTheDocument();
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();
225
353
  });
354
+ });
226
355
 
227
- it("(d) a 500 shows the error row with Retry, not 'no subscription'", async () => {
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);
381
+ });
382
+
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]));
385
+ await renderPage();
386
+ expect(screen.getByTestId("account-billing-offer")).toBeInTheDocument();
387
+ expect(screen.getByTestId("account-billing-manage")).toBeInTheDocument();
388
+ });
389
+
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 () => {
228
400
  mockSubscriptionMe.mockResolvedValue({ ok: false, status: 500, body: {} });
401
+ shown(threePlans());
229
402
  await renderPage();
230
403
  expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't load your billing details.");
231
404
  expect(screen.getByTestId("inbox-retry")).toBeInTheDocument();
232
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
405
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
233
406
  });
234
407
 
235
- it("(d) a throw shows the error row, not 'no subscription'", async () => {
408
+ it("a throw shows the error row", async () => {
236
409
  mockSubscriptionMe.mockRejectedValue(new TypeError("fetch failed"));
237
410
  await renderPage();
238
411
  expect(screen.getByTestId("inbox-error")).toBeInTheDocument();
239
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
412
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
240
413
  });
414
+ });
241
415
 
242
- 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 () => {
243
418
  await renderPage();
244
- expect(mockSubscriptionMe).toHaveBeenCalledWith(
245
- { headers: { cookie: "session=abc" } },
246
- { include: "billing" },
247
- );
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();
248
423
  });
249
424
  });
250
425
 
@@ -264,9 +439,9 @@ describe("AC-2 (e) — contributed billing sections render after the base conten
264
439
  });
265
440
 
266
441
  const states: [string, () => void, string][] = [
267
- ["a subscription", () => undefined, "account-billing-card"],
268
- ["no subscription", () => mockSubscriptionMe.mockResolvedValue(answer({ status: null })), "account-billing-card"],
269
- ["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"],
270
445
  ["a failed read", () => mockSubscriptionMe.mockResolvedValue({ ok: false, status: 500, body: {} }), "inbox-error"],
271
446
  ];
272
447
 
@@ -283,7 +458,7 @@ describe("AC-2 (e) — contributed billing sections render after the base conten
283
458
  describe("#9401 AC-9 — a site's own section renders after the modules' (D7)", () => {
284
459
  const moduleSection: AccountBillingSection = {
285
460
  id: "module",
286
- title: "settings.billing.currentPlan",
461
+ title: "settings.billing.history",
287
462
  render: () => <p data-testid="module-body">Module</p>,
288
463
  };
289
464
  const siteSection: AccountBillingSection = {
@@ -308,13 +483,13 @@ describe("#9401 AC-9 — a site's own section renders after the modules' (D7)",
308
483
  const site = screen.getByTestId("account-settings-site");
309
484
  expect(within(contributed).getByTestId("module-body")).toBeInTheDocument();
310
485
  expect(within(site).getByTestId("site-body")).toBeInTheDocument();
311
- expect(within(contributed).getByRole("heading", { level: 2 })).toHaveTextContent("Current plan");
486
+ expect(within(contributed).getByRole("heading", { level: 2 })).toHaveTextContent("History");
312
487
  expect(within(site).getByRole("heading", { level: 2 })).toHaveTextContent("Billing");
313
488
  expect(contributed.compareDocumentPosition(site) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
314
489
  });
315
490
  });
316
491
 
317
- 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)", () => {
318
493
  const PORTAL_URL = "https://billing.stripe.com/p/session/test_single_site";
319
494
 
320
495
  it("mints the portal once through the hub's route with the cookie init, then redirects there", async () => {