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
@@ -18,10 +18,10 @@
18
18
  * - AC-5, as #8232 rewrites it (spec
19
19
  * docs/specs/8232-member-settings-account-general-and-spec.md D2–D7, D9;
20
20
  * its AC-2 and AC-7): General no longer links to the hub's settings.
21
- * Where the hub answers the member routes, the name, photo and deletion
22
- * go through the member API with the Bearer credential, and a save
23
- * re-seals the session cookie; where it answers none (the fixture's 404),
24
- * the name is read-only and no deletion path is offered. Billing says
21
+ * Where the hub answers the member routes, the name and photo go through
22
+ * the member API with the Bearer credential, and a save re-seals the
23
+ * session cookie; where it answers none (the fixture's 404), the name is
24
+ * read-only. (The deletion request left Privacy in #11164.) Billing says
25
25
  * there is no subscription without reading `subscription.me`.
26
26
  * - #8217 AC-1 (spec docs/specs/8217-spoke-billing-spoke-checkout-reads-spec.md
27
27
  * D10–D12): Billing reads the seam's `loadSpokeBilling` — the plan, the
@@ -31,16 +31,17 @@
31
31
  * `subscription.me` or `member.billing` itself. `openBillingPortal`
32
32
  * redirects to the loader's portal URL, and to nothing without one.
33
33
  * - #8431 AC-4 (spec docs/specs/8431-account-security-tab-human-sign-spec.md
34
- * D1–D3): Security says the hub manages sign-in and links to the hub's
35
- * own Security page, offers no password control and never reads the
36
- * seam's accounts; Log out POSTs the spoke's sign-out endpoint, never
37
- * Better Auth, and lands on `/account` only when it succeeded.
34
+ * D1–D3), as #11162 rewrites it: Security's Log out POSTs the spoke's
35
+ * sign-out endpoint, never Better Auth, and lands on `/account` only
36
+ * when it succeeded. The panel itself — the Password row read from the
37
+ * hub, in place of the retired "managed at <hub>" pointer — is pinned
38
+ * beside the route, in `security/__tests__/hub-variant.test.tsx`.
38
39
  */
39
40
  import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
40
41
  import { tmpdir } from "node:os";
41
42
  import { join } from "node:path";
42
43
 
43
- import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
44
+ import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
44
45
 
45
46
  jest.mock("next-intl/server", () => {
46
47
  const msgs: unknown = require("../../../../../messages/en.json");
@@ -54,13 +55,16 @@ jest.mock("next-intl/server", () => {
54
55
  getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
55
56
  const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
56
57
  const messages = dig(msgs, ns);
57
- return (key: string, values?: Record<string, unknown>): string => {
58
+ const t = (key: string, values?: Record<string, unknown>): string => {
58
59
  const value = dig(messages, key);
59
60
  if (typeof value !== "string") return `${ns}.${key}`;
60
61
  return value.replace(/\{(\w+)\}/g, (m, name: string) =>
61
62
  values && name in values ? String(values[name]) : m,
62
63
  );
63
64
  };
65
+ // #11164: Privacy's lead is a `t.rich` message with a `<policy>` tag.
66
+ const { withRich } = require("./rich-translator") as typeof import("./rich-translator");
67
+ return withRich(t, (key: string) => dig(messages, key), ns);
64
68
  },
65
69
  };
66
70
  });
@@ -105,9 +109,13 @@ const mockMemberRead = jest.fn();
105
109
  const mockMemberPurchases = jest.fn();
106
110
  const mockMemberAppointments = jest.fn();
107
111
  const mockUpdateProfile = jest.fn();
108
- const mockRequestDeletion = jest.fn();
112
+ const mockMemberProfile = jest.fn();
113
+ const mockMemberContact = jest.fn();
114
+ const mockUpdateContact = jest.fn();
109
115
  const mockHubMe = jest.fn();
110
116
  const mockMemberBilling = jest.fn();
117
+ const mockMemberBillingPortal = jest.fn();
118
+ const mockOfferingsShown = jest.fn();
111
119
  const mockPortalSession = jest.fn();
112
120
  jest.mock("@working-theory/api-client", () => ({
113
121
  __esModule: true,
@@ -122,6 +130,10 @@ jest.mock("@working-theory/api-client", () => ({
122
130
  member: {
123
131
  pieces: (...args: unknown[]) => mockMemberRead(...args),
124
132
  messages: (...args: unknown[]) => mockMemberRead(...args),
133
+ // #11157 — the member's own sent requests, read like the other member kinds.
134
+ requests: (...args: unknown[]) => mockMemberRead(...args),
135
+ // #11150 — the onboarding-steps read.
136
+ welcome: (...args: unknown[]) => mockMemberRead(...args),
125
137
  purchases: (...args: unknown[]) => mockMemberPurchases(...args),
126
138
  appointments: (...args: unknown[]) => mockMemberAppointments(...args),
127
139
  // #10826 D7 — the user-magnet results read; 404 here (no workspace module).
@@ -132,10 +144,17 @@ jest.mock("@working-theory/api-client", () => ({
132
144
  body: { ok: false, error: { code: "not_found", message: "Not found" } },
133
145
  }),
134
146
  updateProfile: (...args: unknown[]) => mockUpdateProfile(...args),
135
- requestDeletion: (...args: unknown[]) => mockRequestDeletion(...args),
136
- // #8217 — only the rendered billing action reads it; billing-source.ts never does.
147
+ // #11167 — the member profile read General's photo comes from, and the
148
+ // contact read and write the account name follows.
149
+ profile: (...args: unknown[]) => mockMemberProfile(...args),
150
+ contact: (...args: unknown[]) => mockMemberContact(...args),
151
+ updateContact: (...args: unknown[]) => mockUpdateContact(...args),
152
+ // #11165 — the hub's read of the member's plan, History and portal.
137
153
  billing: (...args: unknown[]) => mockMemberBilling(...args),
154
+ billingPortal: (...args: unknown[]) => mockMemberBillingPortal(...args),
138
155
  },
156
+ // #11165 — the shown set's base plan, Upgrade target and offer; unconnected here.
157
+ offerings: { shown: (...args: unknown[]) => mockOfferingsShown(...args) },
139
158
  visitorForwardHeaders: () => null,
140
159
  hubSignIn: { me: (...args: unknown[]) => mockHubMe(...args) },
141
160
  }));
@@ -205,10 +224,14 @@ beforeEach(() => {
205
224
  mockMemberPurchases.mockReset().mockResolvedValue(notFound);
206
225
  mockMemberAppointments.mockReset().mockResolvedValue(notFound);
207
226
  mockUpdateProfile.mockReset();
208
- mockRequestDeletion.mockReset();
227
+ mockMemberProfile.mockReset().mockResolvedValue(notFound);
228
+ mockMemberContact.mockReset().mockResolvedValue(notFound);
229
+ mockUpdateContact.mockReset().mockResolvedValue(notFound);
209
230
  mockHubMe.mockReset();
210
231
  mockLoadSpokeBilling.mockReset().mockResolvedValue(null);
211
- mockMemberBilling.mockReset();
232
+ mockMemberBilling.mockReset().mockResolvedValue(notFound);
233
+ mockMemberBillingPortal.mockReset().mockResolvedValue(notFound);
234
+ mockOfferingsShown.mockReset().mockResolvedValue({ ok: true, body: { status: "unconnected" } });
212
235
  mockPortalSession.mockReset();
213
236
  mockRedirect.mockReset();
214
237
  mockCookieSet.mockReset();
@@ -255,27 +278,88 @@ describe("AC-5 — General and Billing on a hub-mode spoke (#8232)", () => {
255
278
  mockMemberRead.mockResolvedValue({ ok: true, body: [] });
256
279
  });
257
280
 
258
- it("renders the name and photo form, with no link to the hub's settings", async () => {
281
+ it("renders the photo form with the hub's photo and no Name field, with no link to the hub's settings (#11167)", async () => {
282
+ // The session carries no photo (C5); the member profile read, with the
283
+ // Bearer credential, brings the hub's (#11167 ruling 4).
284
+ mockMemberProfile.mockResolvedValue({
285
+ ok: true,
286
+ body: { name: "Ada Lovelace", image: "https://lh3.googleusercontent.com/a/ada" },
287
+ });
259
288
  await renderGeneral();
260
289
  expect(screen.getByTestId("account-general-form")).toBeInTheDocument();
261
- expect(screen.getByLabelText("Name")).toHaveValue("Ada Lovelace");
262
- // No hub read carries the photo, so the field starts empty (C5).
263
- expect(screen.getByLabelText("Photo")).toHaveValue("");
290
+ expect(screen.queryByLabelText("Name")).not.toBeInTheDocument();
291
+ expect(screen.getByLabelText("Photo")).toHaveValue("https://lh3.googleusercontent.com/a/ada");
292
+ expect(mockMemberProfile).toHaveBeenCalledWith(bearer);
264
293
  expect(screen.queryByTestId("account-settings-manage-on-hub")).not.toBeInTheDocument();
265
294
  expect(screen.queryByTestId("account-privacy-manage-on-hub")).not.toBeInTheDocument();
266
295
  expect(document.querySelector(`a[href^="${HUB}"]`)).toBeNull();
267
296
  });
268
297
 
269
- it("saves the name through member.updateProfile with the Bearer credential, then re-seals the session", async () => {
270
- mockUpdateProfile.mockResolvedValue({ ok: true, body: { name: "Ada King", image: null } });
271
- mockHubMe.mockResolvedValue({ ok: true, body: { user: { ...USER, name: "Ada King" }, billingCustomerId: null } });
298
+ it("a hub whose member profile read fails leaves the photo field empty", async () => {
272
299
  await renderGeneral();
273
- fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Ada King" } });
300
+ expect(screen.getByLabelText("Photo")).toHaveValue("");
301
+ });
302
+
303
+ it("saves the photo alone through member.updateProfile with the Bearer credential; no re-seal, the session carries no photo", async () => {
304
+ const photo = "https://cdn.example.com/ada.png";
305
+ mockUpdateProfile.mockResolvedValue({ ok: true, body: { name: "Ada Lovelace", image: photo } });
306
+ await renderGeneral();
307
+ fireEvent.change(screen.getByLabelText("Photo"), { target: { value: photo } });
274
308
  await act(async () => {
275
309
  fireEvent.click(screen.getByTestId("account-general-save"));
276
310
  });
277
- expect(mockUpdateProfile).toHaveBeenCalledWith({ name: "Ada King" }, bearer);
311
+ expect(mockUpdateProfile).toHaveBeenCalledWith({ image: photo }, bearer);
278
312
  expect(mockUpdateUser).not.toHaveBeenCalled();
313
+ expect(mockHubMe).not.toHaveBeenCalled();
314
+ expect(mockCookieSet).not.toHaveBeenCalled();
315
+ });
316
+
317
+ it("a contact save that derives the account name writes it through member.updateProfile with the Bearer credential, then re-seals the session", async () => {
318
+ const { saveContact } = await import("../general/contact-actions");
319
+ // The hub's stored "Ada Lovelace" (read with the Bearer credential, never
320
+ // the sealed cookie's copy) is what the previous contact derived, so it
321
+ // follows the new names; a hand-set name would not (general.test.tsx).
322
+ mockMemberProfile.mockResolvedValue({ ok: true, body: { name: "Ada Lovelace", image: null } });
323
+ mockMemberContact.mockResolvedValue({
324
+ ok: true,
325
+ body: {
326
+ contact: {
327
+ givenName: "Ada",
328
+ familyName: "Lovelace",
329
+ telephone: null,
330
+ address: null,
331
+ companyName: null,
332
+ jobTitle: null,
333
+ },
334
+ },
335
+ });
336
+ mockUpdateContact.mockResolvedValue({
337
+ ok: true,
338
+ body: {
339
+ contact: {
340
+ givenName: "Ada",
341
+ familyName: "King",
342
+ telephone: null,
343
+ address: null,
344
+ companyName: null,
345
+ jobTitle: null,
346
+ },
347
+ },
348
+ });
349
+ mockUpdateProfile.mockResolvedValue({ ok: true, body: { name: "Ada King", image: null } });
350
+ mockHubMe.mockResolvedValue({ ok: true, body: { user: { ...USER, name: "Ada King" }, billingCustomerId: null } });
351
+ await expect(
352
+ saveContact({
353
+ givenName: "Ada",
354
+ familyName: "King",
355
+ telephone: null,
356
+ address: null,
357
+ companyName: null,
358
+ jobTitle: null,
359
+ }),
360
+ ).resolves.toEqual({ ok: true });
361
+ expect(mockMemberProfile).toHaveBeenCalledWith(bearer);
362
+ expect(mockUpdateProfile).toHaveBeenCalledWith({ name: "Ada King" }, bearer);
279
363
  expect(mockHubMe).toHaveBeenCalledWith(bearer);
280
364
  expect(mockCookieSet).toHaveBeenCalledTimes(1);
281
365
  const [name, value] = mockCookieSet.mock.calls[0] as [string, string];
@@ -298,32 +382,29 @@ describe("AC-5 — General and Billing on a hub-mode spoke (#8232)", () => {
298
382
  });
299
383
  });
300
384
 
301
- // #8438 D16 — Request account deletion moved to Privacy; the hub-mode
302
- // deletion coverage above moves with it, expectations unchanged.
303
- describe("Privacy's deletion block on a hub-mode spoke (moved from General, #8438 D16)", () => {
304
- async function renderPrivacy(): Promise<void> {
385
+ // #11194 — the Your data table's two member routes are hub-admitted
386
+ // (`GET /v1/member/data-export`, `POST /v1/member/stored-sessions/delete`
387
+ // in HUB_SESSION_ROUTES), so a spoke that signs in through its hub renders
388
+ // the same table as a site with its own sign-in: Export data and Delete
389
+ // stored sessions, never the #11164 unavailable line. The Support pointer
390
+ // for an account-deletion request stays off here alone: this fixture's hub
391
+ // answers no member route (`via: "none"`), where Support must not take it
392
+ // (SEC-7894-11).
393
+ describe("Privacy's Your data card on a hub-mode spoke (#11194)", () => {
394
+ it("renders the table with Export data and Delete stored sessions and no unavailable line", async () => {
305
395
  const { default: PrivacyPage } = await import("../privacy/page");
306
396
  render(await PrivacyPage({ params: Promise.resolve({ locale: "en" }) }));
307
- }
308
-
309
- it("a hub that answers the member routes: the deletion request goes through the member API and names the hub operator", async () => {
310
- mockMemberRead.mockResolvedValue({ ok: true, body: [] });
311
- mockRequestDeletion.mockResolvedValue({ ok: true, body: { sentTo: "hub-operator" } });
312
- await renderPrivacy();
313
- expect(screen.getByTestId("account-deletion-request")).toBeInTheDocument();
314
- await act(async () => {
315
- fireEvent.click(screen.getByTestId("account-deletion-request"));
316
- });
317
- expect(mockRequestDeletion).toHaveBeenCalledWith({}, bearer);
318
- await waitFor(() => expect(screen.getByRole("status")).toHaveTextContent("Sent to the hub operator."));
319
- expect(mockLeadsSubmit).not.toHaveBeenCalled();
320
- });
321
-
322
- it("a hub that answers no member route: offers no deletion path", async () => {
323
- await renderPrivacy();
324
- expect(screen.queryByTestId("account-deletion-request")).not.toBeInTheDocument();
325
- expect(screen.queryByTestId("account-deletion-support")).not.toBeInTheDocument();
326
- expect(screen.getByText("This site can't take deletion requests right now.")).toBeInTheDocument();
397
+ const table = screen.getByTestId("account-privacy-your-data");
398
+ expect(table).toHaveTextContent("Your data");
399
+ expect(table).toHaveTextContent("Export data");
400
+ expect(table).toHaveTextContent("Delete stored sessions");
401
+ expect(screen.getByTestId("account-privacy-your-data-export-button")).toHaveAttribute(
402
+ "href",
403
+ "/account/privacy/export",
404
+ );
405
+ expect(screen.getByTestId("account-privacy-your-data-delete-button")).toBeInTheDocument();
406
+ expect(screen.queryByTestId("account-privacy-your-data-account-deletion")).not.toBeInTheDocument();
407
+ expect(screen.queryByTestId("account-privacy-your-data-unavailable")).not.toBeInTheDocument();
327
408
  });
328
409
  });
329
410
 
@@ -339,14 +420,17 @@ describe("AC-5 — General and Billing on a hub-mode spoke (#8232)", () => {
339
420
  );
340
421
  });
341
422
 
342
- it("Billing says there is no subscription, with no button, without reading subscription.me", async () => {
423
+ it("Billing with nothing to show renders no plan card and no button, without reading subscription.me (#11165)", async () => {
343
424
  // The Billing route's own page, loaded with `import()`: architecture.yaml bans
344
425
  // a static import of a relative billing/ path to keep OSS code out of the
345
426
  // apps-paid/billing service's source, and this route directory shares the name.
346
427
  const { default: BillingPage } = await import("../billing/page");
347
428
  render(await BillingPage({ params: Promise.resolve({ locale: "en" }) }));
348
- expect(screen.getByTestId("account-billing-none")).toHaveTextContent("You don't have a subscription.");
429
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
430
+ expect(screen.queryByText("You don't have a subscription.")).not.toBeInTheDocument();
349
431
  expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
432
+ // Nothing to show is no card at all — never an empty shell.
433
+ expect(screen.queryByTestId("account-settings-billing-card")).not.toBeInTheDocument();
350
434
  expect(mockSubscriptionMe).not.toHaveBeenCalled();
351
435
  });
352
436
  });
@@ -370,32 +454,16 @@ describe("#8431 AC-4 — Security on a hub-mode spoke", () => {
370
454
  render(await SecurityPage({ params: Promise.resolve({ locale: "en" }) }));
371
455
  }
372
456
 
373
- it("says the hub manages sign-in and links to the hub's Security page — no password control", async () => {
374
- await renderSecurity();
375
- expect(screen.getByTestId("account-security-hub").textContent).toBe(
376
- "Your sign-in is managed at hub.example.com.",
377
- );
378
- const links = screen.getAllByTestId("account-security-hub-link");
379
- expect(links).toHaveLength(1);
380
- expect(links[0]).toHaveAttribute("href", `${HUB}/account/security`);
381
- expect(screen.getByTestId("account-security-log-out")).toBeInTheDocument();
382
- expect(screen.queryByTestId("account-security-password")).not.toBeInTheDocument();
383
- expect(screen.queryByTestId("account-security-sentence")).not.toBeInTheDocument();
384
- expect(screen.queryByText(/other devices/i)).toBeNull();
385
- expect(mockReadOwnAccounts).not.toHaveBeenCalled();
386
- });
387
-
388
- it("with the hub config absent says 'our main site' and links nowhere", async () => {
389
- delete process.env.AILK_HUB_CLIENT_SECRET;
457
+ it("renders no 'managed at <hub>' sentence and no link to the hub's Security page (#11162), and never reads the seam's accounts", async () => {
390
458
  await renderSecurity();
391
- expect(screen.getByTestId("account-security-hub").textContent).toBe(
392
- "Your sign-in is managed by our main site.",
393
- );
459
+ expect(screen.queryByTestId("account-security-hub")).not.toBeInTheDocument();
394
460
  expect(screen.queryByTestId("account-security-hub-link")).not.toBeInTheDocument();
461
+ expect(screen.queryByTestId("account-security-sentence")).not.toBeInTheDocument();
395
462
  expect(screen.getByTestId("account-security-log-out")).toBeInTheDocument();
463
+ expect(mockReadOwnAccounts).not.toHaveBeenCalled();
396
464
  });
397
465
 
398
- it("Log out POSTs the spoke's sign-out endpoint, never Better Auth, and on a 204 lands on /account", async () => {
466
+ it("Log out POSTs the spoke's sign-out endpoint, never Better Auth, and on a 204 lands on the home (#11095 D4)", async () => {
399
467
  mockFetch.mockResolvedValue({ ok: true, status: 204 });
400
468
  await renderSecurity();
401
469
  await act(async () => {
@@ -407,7 +475,7 @@ describe("#8431 AC-4 — Security on a hub-mode spoke", () => {
407
475
  credentials: "same-origin",
408
476
  });
409
477
  expect(mockSignOut).not.toHaveBeenCalled();
410
- expect(mockPush).toHaveBeenCalledWith("/account");
478
+ expect(mockPush).toHaveBeenCalledWith("/");
411
479
  });
412
480
 
413
481
  it("a refused sign-out (403) navigates nowhere and shows the error", async () => {
@@ -422,9 +490,41 @@ describe("#8431 AC-4 — Security on a hub-mode spoke", () => {
422
490
  });
423
491
  });
424
492
 
425
- describe("#8217 AC-1 — Billing on a hub-mode spoke reads the seam's spoke billing (D10–D12)", () => {
493
+ describe("#11165 AC-1, AC-4 — Billing on a hub-mode spoke reads the hub first, the spoke's own key as the fallback", () => {
426
494
  const VISA = { brand: "visa", last4: "4242", expMonth: 4, expYear: 2030 };
427
495
  const PORTAL_URL = "https://billing.stripe.com/p/session/test_fake";
496
+ const HUB_PORTAL_URL = "https://billing.stripe.com/p/session/test_hub";
497
+ const PLAN = {
498
+ name: "Essentials",
499
+ status: "active",
500
+ price: { amountMinor: 1250000, currency: "usd", interval: "month" },
501
+ renewsAt: "2026-12-01T00:00:00.000Z",
502
+ accessEndsAt: null,
503
+ card: { brand: "visa", last4: "4242" },
504
+ };
505
+ const ROW = {
506
+ id: "in_workshop",
507
+ paidAt: "2026-10-25T10:00:00.000Z",
508
+ offering: "Positioning workshop",
509
+ amountMinor: 120000,
510
+ currency: "usd",
511
+ receiptUrl: "https://invoice.stripe.com/i/acct_1/test_workshop",
512
+ };
513
+ const PURCHASE = {
514
+ id: "purchase_01920000-1109-7000-8000-000000000001",
515
+ offering: "Strategy Session",
516
+ amountMinor: 25000,
517
+ currency: "usd",
518
+ period: null,
519
+ purchasedAt: "2026-11-07T12:00:00.000Z",
520
+ };
521
+ const bearer = { headers: { authorization: `Bearer ${CREDENTIAL}` } };
522
+
523
+ /** The hub's answer: its customers and what it read for them. */
524
+ const hub = (billing: unknown) => ({
525
+ ok: true,
526
+ body: { customers: [{ customerId: "cus_A1", planOffering: null }], ...(billing === undefined ? {} : { billing }) },
527
+ });
428
528
 
429
529
  /** A `SpokeBilling` stub: what the rendered action returns. */
430
530
  function stub(read: unknown, portalUrl: string | null = PORTAL_URL) {
@@ -438,95 +538,221 @@ describe("#8217 AC-1 — Billing on a hub-mode spoke reads the seam's spoke bill
438
538
  }
439
539
 
440
540
  afterEach(() => {
441
- // Every case: billing-source.ts reads neither the hub's subscription nor its billing ids.
541
+ // Every case: a hub-mode spoke never reads the hub's cookie-session subscription.
442
542
  expect(mockSubscriptionMe).not.toHaveBeenCalled();
443
- expect(mockMemberBilling).not.toHaveBeenCalled();
444
543
  });
445
544
 
446
- it("a subscription renders the plan, the card and Manage billing", async () => {
447
- mockLoadSpokeBilling.mockResolvedValue(
448
- stub({ kind: "subscription", status: "active", planName: "Pro", paymentMethod: VISA, unreadable: false }),
449
- );
450
- await renderBilling();
451
- const card = screen.getByTestId("account-billing-card");
452
- expect(card).toHaveTextContent("Pro");
453
- expect(card).toHaveTextContent("Active");
454
- expect(card).toHaveTextContent("visa ending in 4242, expires 04/2030");
455
- expect(screen.getByTestId("account-billing-manage")).toHaveTextContent("Manage billing");
456
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
457
- expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
458
- });
545
+ describe("the hub read (source: hub)", () => {
546
+ it("renders the plan card from the hub's read — the name, the muted price, the renewal line with the card, Manage plan — and the History table, with the Bearer credential and no spoke-key read", async () => {
547
+ mockMemberBilling.mockResolvedValue(hub({ source: "hub", plan: PLAN, history: [ROW], portalAvailable: true }));
548
+ await renderBilling();
549
+ expect(mockMemberBilling).toHaveBeenCalledWith(bearer);
550
+ const card = screen.getByTestId("account-billing");
551
+ expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Essentials");
552
+ expect(within(card).getByTestId("account-billing-price")).toHaveTextContent("$12,500/mo");
553
+ expect(within(card).getByTestId("account-billing-status")).toHaveTextContent("Renews on December 1 · Visa 4242");
554
+ expect(within(card).getByTestId("account-billing-manage")).toHaveTextContent("Manage plan");
555
+ expect(screen.queryByText("Current plan")).not.toBeInTheDocument();
556
+ const history = screen.getByTestId("account-billing-history");
557
+ expect(within(history).getByRole("heading", { level: 2 })).toHaveTextContent("History");
558
+ const row = within(history).getAllByTestId("account-billing-history-row")[0]!;
559
+ expect(row).toHaveTextContent("10/25/2026");
560
+ expect(row).toHaveTextContent("Positioning workshop");
561
+ expect(row).toHaveTextContent("$1,200");
562
+ expect(within(row).getByRole("link", { name: "View" })).toHaveAttribute("href", ROW.receiptUrl);
563
+ expect(mockLoadSpokeBilling).not.toHaveBeenCalled();
564
+ expect(mockMemberPurchases).not.toHaveBeenCalled();
565
+ expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
566
+ // Two cards: the plan and History — no shell for the absent offer.
567
+ expect(screen.getAllByTestId("account-settings-billing-card")).toHaveLength(2);
568
+ });
459
569
 
460
- it("none renders the plain none line and no button", async () => {
461
- mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "none", unreadable: false }, null));
462
- await renderBilling();
463
- expect(screen.getByTestId("account-billing-none")).toHaveTextContent("You don't have a subscription.");
464
- expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
465
- expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
466
- });
570
+ it.each([
571
+ ["past_due", { ...PLAN, status: "past_due", renewsAt: null }, "Payment due · Visa 4242"],
572
+ ["canceled with an access end", { ...PLAN, status: "canceled", renewsAt: null, accessEndsAt: "2026-12-01T00:00:00.000Z" }, "Access ends December 1 · Visa 4242"],
573
+ ["no card", { ...PLAN, card: null }, "Renews on December 1"],
574
+ ["no name and no price", { ...PLAN, name: null, price: null }, "Renews on December 1 · Visa 4242"],
575
+ ])("the status line for %s", async (_label, plan, line) => {
576
+ mockMemberBilling.mockResolvedValue(hub({ source: "hub", plan, history: [], portalAvailable: true }));
577
+ await renderBilling();
578
+ expect(screen.getByTestId("account-billing-status")).toHaveTextContent(line);
579
+ if (plan.name === null) {
580
+ expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Your subscription");
581
+ expect(screen.queryByTestId("account-billing-price")).not.toBeInTheDocument();
582
+ }
583
+ });
467
584
 
468
- it.each([
469
- ["none", { kind: "none", unreadable: true }, "account-billing-card"],
470
- [
471
- "a subscription",
472
- { kind: "subscription", status: "past_due", planName: null, paymentMethod: null, unreadable: true },
473
- "account-billing-card",
474
- ],
475
- ])("unreadable: true on %s adds the unreadable line after it", async (_label, read, baseTestId) => {
476
- mockLoadSpokeBilling.mockResolvedValue(stub(read));
477
- await renderBilling();
478
- const line = screen.getByTestId("account-billing-unreadable");
479
- expect(line).toHaveTextContent("Some of your billing is with another Stripe account, so it isn't shown here.");
480
- const base = screen.getByTestId(baseTestId);
481
- expect(base.compareDocumentPosition(line) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
482
- });
585
+ it("no portal, no Manage plan", async () => {
586
+ mockMemberBilling.mockResolvedValue(hub({ source: "hub", plan: PLAN, history: [], portalAvailable: false }));
587
+ await renderBilling();
588
+ expect(screen.getByTestId("account-billing")).toBeInTheDocument();
589
+ expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
590
+ });
483
591
 
484
- it("a failed read renders the error row, never 'no subscription'", async () => {
485
- mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "failed" }));
486
- await renderBilling();
487
- expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't load your billing details.");
488
- expect(screen.queryByTestId("account-billing-none")).not.toBeInTheDocument();
489
- expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
490
- });
592
+ it("a member with no customer — no plan, no history — renders no plan card (the shown set is unconnected) and the purchase leads as History, without a receipt", async () => {
593
+ mockMemberBilling.mockResolvedValue(hub({ source: "hub", plan: null, history: [], portalAvailable: false }));
594
+ mockMemberPurchases.mockResolvedValue({ ok: true, body: { items: [PURCHASE] } });
595
+ await renderBilling();
596
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
597
+ expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
598
+ expect(mockMemberPurchases).toHaveBeenCalledWith(bearer);
599
+ const rows = screen.getAllByTestId("account-billing-history-row");
600
+ expect(rows).toHaveLength(1);
601
+ expect(rows[0]).toHaveTextContent("11/07/2026");
602
+ expect(rows[0]).toHaveTextContent("Strategy Session");
603
+ expect(rows[0]).toHaveTextContent("$250");
604
+ expect(within(rows[0]!).queryByRole("link")).not.toBeInTheDocument();
605
+ expect(mockLoadSpokeBilling).not.toHaveBeenCalled();
606
+ });
491
607
 
492
- it("a loader that fails to load renders the error row", async () => {
493
- const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
494
- mockLoadSpokeBilling.mockRejectedValue(new SyntaxError("checkout-config.ts is malformed"));
495
- await renderBilling();
496
- expect(screen.getByTestId("inbox-error")).toBeInTheDocument();
497
- expect(errorSpy.mock.calls.map((args) => args.join(" "))).toEqual([
498
- "[account] read failed source=spoke-billing errName=SyntaxError",
499
- ]);
500
- errorSpy.mockRestore();
501
- });
608
+ it("no history anywhere renders no History card; an older hub's 404 on purchases is none", async () => {
609
+ mockMemberBilling.mockResolvedValue(hub({ source: "hub", plan: PLAN, history: [], portalAvailable: true }));
610
+ await renderBilling();
611
+ expect(screen.queryByTestId("account-billing-history")).not.toBeInTheDocument();
612
+ expect(screen.queryByTestId("account-billing-history-error")).not.toBeInTheDocument();
613
+ expect(screen.getAllByTestId("account-settings-billing-card")).toHaveLength(1);
614
+ });
502
615
 
503
- it("a spoke without the action (the loader resolves null) renders none and no button", async () => {
504
- await renderBilling();
505
- expect(screen.getByTestId("account-billing-none")).toBeInTheDocument();
506
- expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
507
- expect(mockLoadSpokeBilling).toHaveBeenCalledTimes(1);
616
+ it("a failed purchases read shows the History error row, never an empty list", async () => {
617
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
618
+ mockMemberBilling.mockResolvedValue(hub({ source: "hub", plan: PLAN, history: [], portalAvailable: true }));
619
+ mockMemberPurchases.mockResolvedValue({ ok: false, status: 502, body: {} });
620
+ await renderBilling();
621
+ expect(screen.getByTestId("account-billing-history-error")).toHaveTextContent("We couldn't load your purchases.");
622
+ expect(screen.queryByTestId("account-billing-history-row")).not.toBeInTheDocument();
623
+ errorSpy.mockRestore();
624
+ });
625
+
626
+ it("source: failed renders the error row, never 'no subscription', and never the spoke's own key", async () => {
627
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
628
+ mockMemberBilling.mockResolvedValue(hub({ source: "failed" }));
629
+ await renderBilling();
630
+ expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't load your billing details.");
631
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
632
+ expect(mockLoadSpokeBilling).not.toHaveBeenCalled();
633
+ errorSpy.mockRestore();
634
+ });
635
+
636
+ it("a 500 from the hub, or a throw, renders the error row", async () => {
637
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
638
+ mockMemberBilling.mockResolvedValue({ ok: false, status: 500, body: {} });
639
+ await renderBilling();
640
+ expect(screen.getByTestId("inbox-error")).toBeInTheDocument();
641
+ expect(mockLoadSpokeBilling).not.toHaveBeenCalled();
642
+ errorSpy.mockRestore();
643
+ });
508
644
  });
509
645
 
510
- it("openBillingPortal redirects to the loader's portal URL", async () => {
511
- const billing = stub({ kind: "none", unreadable: false });
512
- mockLoadSpokeBilling.mockResolvedValue(billing);
513
- await openBillingPortal();
514
- expect(billing.portalUrl).toHaveBeenCalledWith();
515
- expect(mockRedirect).toHaveBeenCalledTimes(1);
516
- expect(mockRedirect).toHaveBeenCalledWith(PORTAL_URL);
517
- expect(mockPortalSession).not.toHaveBeenCalled();
646
+ describe("the spoke-key fallback (source: none, an older hub, a 404)", () => {
647
+ it.each([
648
+ ["source: none — no Organization connection", () => mockMemberBilling.mockResolvedValue(hub({ source: "none" }))],
649
+ ["an older hub with no billing key", () => mockMemberBilling.mockResolvedValue(hub(undefined))],
650
+ ["a 404", () => mockMemberBilling.mockResolvedValue(notFound)],
651
+ ])("%s: a subscription read with the spoke's own key renders the plan, the card and Manage plan, with no price or renewal", async (_label, arrange) => {
652
+ arrange();
653
+ mockLoadSpokeBilling.mockResolvedValue(
654
+ stub({ kind: "subscription", status: "active", planName: "Pro", paymentMethod: VISA, unreadable: false }),
655
+ );
656
+ await renderBilling();
657
+ const card = screen.getByTestId("account-billing");
658
+ expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Pro");
659
+ expect(within(card).getByTestId("account-billing-status")).toHaveTextContent("Active · Visa 4242");
660
+ expect(within(card).queryByTestId("account-billing-price")).not.toBeInTheDocument();
661
+ expect(screen.getByTestId("account-billing-manage")).toHaveTextContent("Manage plan");
662
+ expect(mockLoadSpokeBilling).toHaveBeenCalledTimes(1);
663
+ expect(mockMemberPurchases).toHaveBeenCalledWith(bearer);
664
+ });
665
+
666
+ it("none renders no plan card and no button", async () => {
667
+ mockMemberBilling.mockResolvedValue(hub({ source: "none" }));
668
+ mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "none", unreadable: false }, null));
669
+ await renderBilling();
670
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
671
+ expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
672
+ expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
673
+ });
674
+
675
+ it.each([
676
+ ["none", { kind: "none", unreadable: true }, "account-settings-billing"],
677
+ [
678
+ "a subscription",
679
+ { kind: "subscription", status: "past_due", planName: null, paymentMethod: null, unreadable: true },
680
+ "account-billing",
681
+ ],
682
+ ])("unreadable: true on %s adds the unreadable line", async (_label, read, baseTestId) => {
683
+ mockMemberBilling.mockResolvedValue(hub({ source: "none" }));
684
+ mockLoadSpokeBilling.mockResolvedValue(stub(read));
685
+ await renderBilling();
686
+ const line = screen.getByTestId("account-billing-unreadable");
687
+ expect(line).toHaveTextContent("Some of your billing is with another Stripe account, so it isn't shown here.");
688
+ expect(screen.getByTestId(baseTestId)).toBeInTheDocument();
689
+ });
690
+
691
+ it("a failed own-key read renders the error row, never 'no subscription'", async () => {
692
+ mockMemberBilling.mockResolvedValue(hub({ source: "none" }));
693
+ mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "failed" }));
694
+ await renderBilling();
695
+ expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't load your billing details.");
696
+ expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
697
+ });
698
+
699
+ it("a loader that fails to load renders the error row", async () => {
700
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
701
+ mockMemberBilling.mockResolvedValue(hub({ source: "none" }));
702
+ mockLoadSpokeBilling.mockRejectedValue(new SyntaxError("checkout-config.ts is malformed"));
703
+ await renderBilling();
704
+ expect(screen.getByTestId("inbox-error")).toBeInTheDocument();
705
+ expect(errorSpy.mock.calls.map((args) => args.join(" "))).toEqual([
706
+ "[account] read failed source=spoke-billing errName=SyntaxError",
707
+ ]);
708
+ errorSpy.mockRestore();
709
+ });
710
+
711
+ it("a spoke without the action (the loader resolves null) and no purchases renders no plan card and no History", async () => {
712
+ mockMemberBilling.mockResolvedValue(hub({ source: "none" }));
713
+ await renderBilling();
714
+ expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
715
+ expect(screen.queryByTestId("account-billing-history")).not.toBeInTheDocument();
716
+ expect(mockLoadSpokeBilling).toHaveBeenCalledTimes(1);
717
+ });
518
718
  });
519
719
 
520
- it.each([
521
- ["the loader's portal is null", () => mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "none", unreadable: false }, null))],
522
- ["there is no loader", () => mockLoadSpokeBilling.mockResolvedValue(null)],
523
- ["the loader fails to load", () => mockLoadSpokeBilling.mockRejectedValue(new Error("load failed"))],
524
- ])("openBillingPortal redirects nowhere when %s", async (_label, arrange) => {
525
- const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
526
- arrange();
527
- await openBillingPortal();
528
- expect(mockRedirect).not.toHaveBeenCalled();
529
- expect(mockPortalSession).not.toHaveBeenCalled();
530
- errorSpy.mockRestore();
720
+ describe("Manage plan — openBillingPortal", () => {
721
+ it("redirects to the hub's portal session, minted with the Bearer credential", async () => {
722
+ mockMemberBillingPortal.mockResolvedValue({ ok: true, body: { url: HUB_PORTAL_URL } });
723
+ mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "none", unreadable: false }));
724
+ await openBillingPortal();
725
+ expect(mockMemberBillingPortal).toHaveBeenCalledWith(bearer);
726
+ expect(mockRedirect).toHaveBeenCalledTimes(1);
727
+ expect(mockRedirect).toHaveBeenCalledWith(HUB_PORTAL_URL);
728
+ expect(mockLoadSpokeBilling).not.toHaveBeenCalled();
729
+ expect(mockPortalSession).not.toHaveBeenCalled();
730
+ });
731
+
732
+ it("a 404 from the hub (no portal there) falls back to the loader's portal URL", async () => {
733
+ const billing = stub({ kind: "none", unreadable: false });
734
+ mockLoadSpokeBilling.mockResolvedValue(billing);
735
+ await openBillingPortal();
736
+ expect(billing.portalUrl).toHaveBeenCalledWith();
737
+ expect(mockRedirect).toHaveBeenCalledWith(PORTAL_URL);
738
+ expect(mockPortalSession).not.toHaveBeenCalled();
739
+ });
740
+
741
+ it.each([
742
+ ["the hub refuses with a 500", () => mockMemberBillingPortal.mockResolvedValue({ ok: false, status: 500, body: {} })],
743
+ ["the hub answers with a URL off Stripe", () => mockMemberBillingPortal.mockResolvedValue({ ok: true, body: { url: "https://evil.example/p" } })],
744
+ ["the hub answers with an http: URL", () => mockMemberBillingPortal.mockResolvedValue({ ok: true, body: { url: "http://billing.stripe.com/p" } })],
745
+ ["the hub call throws", () => mockMemberBillingPortal.mockRejectedValue(new TypeError("fetch failed"))],
746
+ ["the loader's portal is null", () => mockLoadSpokeBilling.mockResolvedValue(stub({ kind: "none", unreadable: false }, null))],
747
+ ["there is no loader", () => mockLoadSpokeBilling.mockResolvedValue(null)],
748
+ ["the loader fails to load", () => mockLoadSpokeBilling.mockRejectedValue(new Error("load failed"))],
749
+ ])("openBillingPortal redirects nowhere when %s", async (_label, arrange) => {
750
+ const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
751
+ arrange();
752
+ await openBillingPortal();
753
+ expect(mockRedirect).not.toHaveBeenCalled();
754
+ expect(mockPortalSession).not.toHaveBeenCalled();
755
+ errorSpy.mockRestore();
756
+ });
531
757
  });
532
758
  });