create-ailk 0.36.0 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/component-catalog.json +40 -1
- package/component-catalog.md +7 -5
- package/dist/add-route.d.ts +5 -0
- package/dist/add-route.js +10 -2
- package/dist/surfaces.js +60 -19
- package/dist/sync-routes.d.ts +15 -1
- package/dist/sync-routes.js +58 -6
- package/dist/template-record.d.ts +11 -0
- package/dist/template-record.js +18 -0
- package/dist/update.d.ts +33 -1
- package/dist/update.js +439 -56
- package/package.json +3 -3
- package/templates/.env.example +17 -0
- package/templates/apps/api/.env.example +38 -0
- package/templates/apps/api/CLAUDE.md +3 -0
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
- package/templates/apps/mcp/CLAUDE.md +1 -1
- package/templates/apps/web/CLAUDE.md +28 -1
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
- package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
- package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
- package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
- package/templates/apps/web/lib/account-config.ts +132 -8
- package/templates/apps/web/lib/auth-routes.ts +11 -6
- package/templates/apps/web/lib/offerings-pricing.ts +4 -1
- package/templates/apps/web/messages/en.json +156 -80
- package/versions.json +48 -48
- package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
- package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
- package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
|
@@ -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
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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)
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
136
|
-
//
|
|
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
|
-
|
|
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
|
|
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.
|
|
262
|
-
|
|
263
|
-
expect(
|
|
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("
|
|
270
|
-
|
|
271
|
-
|
|
298
|
+
it("a hub whose member profile read fails leaves the photo field empty", async () => {
|
|
299
|
+
await renderGeneral();
|
|
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 } });
|
|
272
306
|
await renderGeneral();
|
|
273
|
-
fireEvent.change(screen.getByLabelText("
|
|
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({
|
|
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
|
-
// #
|
|
302
|
-
//
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
expect(
|
|
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
|
|
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.
|
|
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,29 +454,13 @@ 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("
|
|
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.
|
|
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
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 () => {
|
|
@@ -422,9 +490,41 @@ describe("#8431 AC-4 — Security on a hub-mode spoke", () => {
|
|
|
422
490
|
});
|
|
423
491
|
});
|
|
424
492
|
|
|
425
|
-
describe("#
|
|
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,148 +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:
|
|
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
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
"
|
|
472
|
-
|
|
473
|
-
|
|
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
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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
|
+
});
|
|
509
625
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
+
});
|
|
519
635
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
529
|
-
expect(mockPortalSession).not.toHaveBeenCalled();
|
|
530
|
-
errorSpy.mockRestore();
|
|
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
|
+
});
|
|
531
644
|
});
|
|
532
|
-
});
|
|
533
645
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
+
});
|
|
545
665
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
+
});
|
|
551
674
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
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();
|
|
562
689
|
});
|
|
563
|
-
});
|
|
564
690
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
+
});
|
|
573
718
|
});
|
|
574
719
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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
|
+
});
|
|
584
757
|
});
|
|
585
758
|
});
|