create-ailk 0.39.0 → 0.40.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/component-catalog.json +1 -1
- package/component-catalog.md +1 -1
- package/dist/add-route.js +15 -0
- package/dist/body-heading.d.ts +2 -1
- package/dist/body-heading.js +31 -3
- package/dist/module-architecture.js +0 -3
- package/dist/remove-module.js +13 -4
- package/dist/routes.d.ts +7 -0
- package/dist/routes.js +1 -1
- package/dist/site-roster.js +7 -1
- package/dist/surfaces.d.ts +2 -0
- package/dist/surfaces.js +59 -172
- package/package.json +3 -3
- package/templates/apps/web/CLAUDE.md +19 -2
- package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
- package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
- package/templates/apps/web/app/[locale]/layout.tsx +42 -25
- package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
- package/templates/apps/web/app/api/revalidate/route.ts +45 -4
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +53 -0
- package/templates/apps/web/app/llms.txt/route.ts +5 -2
- package/templates/apps/web/i18n/request.ts +5 -1
- package/templates/apps/web/jest.config.cjs +6 -0
- package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +239 -0
- package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
- package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +115 -3
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
- package/templates/apps/web/lib/hub-site-config.ts +151 -0
- package/templates/apps/web/lib/in-page-magnet.ts +2 -2
- package/templates/apps/web/lib/pricing-page.ts +3 -3
- package/templates/apps/web/lib/profile-back-link.ts +49 -12
- package/templates/apps/web/lib/served-pages.ts +144 -39
- package/templates/apps/web/lib/site-brand.tsx +66 -0
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +25 -5
- package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +21 -5
- package/templates/apps/web/lib/site-header.ts +1 -1
- package/templates/apps/web/lib/site-identity.ts +38 -2
- package/templates/apps/web/messages/en.json +3 -119
- package/templates/apps/web/next.config.mjs +7 -0
- package/templates/apps/web/package.json +1 -0
- package/templates/apps/web/site-pages.config.tsx +85 -0
- package/templates/tools/body-heading.ts +30 -3
- package/versions.json +50 -49
- package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
- package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
- package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
- package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
- package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
- package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
- package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
- package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
- package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
- package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
- package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
- package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
- package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
- package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
- package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
- package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
- package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
- package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
- package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
- package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
- package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
- package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
- package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
- package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
- package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
- package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
- package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
- package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
- package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
- package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
- package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
- package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
- package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
- package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
- package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
- package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
- package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
- package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
- package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
- package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
- package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/page.tsx +0 -147
- package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
- package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
- package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
- package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
- package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
- package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
- package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
- package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
- package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
- package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
- package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
- package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
- package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
- package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
- package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
- package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
- package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
- package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
- package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
- package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
- package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
- package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
- package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
- package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
- package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
- package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
- package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
- package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
- package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
- package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
- package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
- package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
- package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
- package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
- package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
- package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
- package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
- package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
- package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
- package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
- package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
- package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
- package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
- package/templates/apps/web/lib/hub-children.tsx +0 -351
- package/templates/apps/web/lib/meet-placeholder.ts +0 -5
- package/templates/apps/web/lib/posting-title.ts +0 -39
- package/templates/apps/web/lib/route-family.ts +0 -69
- package/templates/apps/web/lib/service-listing.ts +0 -89
- package/templates/apps/web/lib/template-listing.ts +0 -169
- package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
- package/templates/apps/web/src/lib/lead-write.ts +0 -90
|
@@ -1,1122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for captureLeadAction Server Action.
|
|
3
|
-
*
|
|
4
|
-
* Acceptance criteria verified here:
|
|
5
|
-
* - captureLeadAction(prevState, validFormData) calls api-client leads.submit
|
|
6
|
-
* and returns success state
|
|
7
|
-
* - captureLeadAction(prevState, invalidFormData) returns Zod validation errors
|
|
8
|
-
* without calling api-client
|
|
9
|
-
* - captureLeadAction returns generic error on API failure
|
|
10
|
-
* - Parity: captureLeadAction is paired with ailkCaptureLead per ADR 0013
|
|
11
|
-
* - #8747: the lead is marked payload.site / payload.page and sends no
|
|
12
|
-
* siteId; a per-visitor limit runs before the write; an unreachable API is
|
|
13
|
-
* `unavailable`; the built-in form's source is `contact-form`
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { __resetRateLimit } from "../../../../src/lib/rate-limit";
|
|
17
|
-
import { captureLeadAction } from "../contact.actions.js";
|
|
18
|
-
|
|
19
|
-
// Mock @working-theory/api-client. `visitorForwardHeaders` stays real (#7394)
|
|
20
|
-
// so AC-9 compares the action's `init` with the helper's own output.
|
|
21
|
-
// #9255 — the write bot check's verdict. `checkBotId` reads Vercel's
|
|
22
|
-
// request context, which jest has none of, so every case decides it here.
|
|
23
|
-
const checkBotIdMock = jest.fn();
|
|
24
|
-
jest.mock("botid/server", () => ({
|
|
25
|
-
checkBotId: (...args: unknown[]) => checkBotIdMock(...args),
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
29
|
-
leads: {
|
|
30
|
-
submit: jest.fn(),
|
|
31
|
-
},
|
|
32
|
-
// #9171 — a `checkout` magnet's lookup key comes from the shown set.
|
|
33
|
-
offerings: {
|
|
34
|
-
shown: jest.fn(),
|
|
35
|
-
},
|
|
36
|
-
visitorForwardHeaders: jest.requireActual("@working-theory/api-client")
|
|
37
|
-
.visitorForwardHeaders,
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
// next/headers' `headers()` is request-scoped in Next; outside it, it is
|
|
41
|
-
// mocked here the way flow.actions.test.ts does (#7394 AC-9).
|
|
42
|
-
jest.mock("next/headers", () => ({
|
|
43
|
-
__esModule: true,
|
|
44
|
-
headers: jest.fn().mockResolvedValue({ get: () => null }),
|
|
45
|
-
}));
|
|
46
|
-
|
|
47
|
-
// #8757 D8 — the thank-you's account link reads the request's locale and the
|
|
48
|
-
// `contact` messages through next-intl, and the generated sign-in provider.
|
|
49
|
-
// Both are mocked here, per case.
|
|
50
|
-
jest.mock("next-intl/server", () => {
|
|
51
|
-
const messages = require("../../../../messages/en.json") as {
|
|
52
|
-
contact: Record<string, unknown>;
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
__esModule: true,
|
|
56
|
-
getLocale: jest.fn().mockResolvedValue("en"),
|
|
57
|
-
getTranslations: jest.fn(async (namespace: string) => {
|
|
58
|
-
if (namespace !== "contact") throw new Error(`unexpected namespace ${namespace}`);
|
|
59
|
-
return (key: string) => {
|
|
60
|
-
const value = messages.contact[key];
|
|
61
|
-
return typeof value === "string" ? value : `contact.${key}`;
|
|
62
|
-
};
|
|
63
|
-
}),
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// #9171 — a `checkout` magnet never calls Next's `redirect()`: a Server
|
|
68
|
-
// Action redirect is fetched as RSC, which the buy route refuses. The mock
|
|
69
|
-
// throws NEXT_REDIRECT as Next does, so a stray call fails its case.
|
|
70
|
-
const mockRedirect = jest.fn((url: string): never => {
|
|
71
|
-
throw new Error(`NEXT_REDIRECT:${url}`);
|
|
72
|
-
});
|
|
73
|
-
jest.mock("next/navigation", () => ({
|
|
74
|
-
__esModule: true,
|
|
75
|
-
redirect: (url: string) => mockRedirect(url),
|
|
76
|
-
}));
|
|
77
|
-
|
|
78
|
-
let mockSignInProvider: "site" | "hub" | "none" = "site";
|
|
79
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: SIGN_IN_PROVIDER is a generated per-build constant (#8757 D8), not a runtime input; no env or HTTP surface selects it.
|
|
80
|
-
jest.mock("../../../../lib/topology.generated", () => ({
|
|
81
|
-
__esModule: true,
|
|
82
|
-
get SIGN_IN_PROVIDER() {
|
|
83
|
-
return mockSignInProvider;
|
|
84
|
-
},
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
import { leads, offerings, visitorForwardHeaders } from "@working-theory/api-client";
|
|
88
|
-
import { workspaceShownSetSchema } from "@working-theory/validation";
|
|
89
|
-
import { headers } from "next/headers";
|
|
90
|
-
const mockSubmit = leads.submit as jest.Mock;
|
|
91
|
-
const mockShown = offerings.shown as jest.Mock;
|
|
92
|
-
const mockHeaders = headers as jest.Mock;
|
|
93
|
-
|
|
94
|
-
afterEach(() => {
|
|
95
|
-
jest.clearAllMocks();
|
|
96
|
-
mockHeaders.mockResolvedValue({ get: () => null });
|
|
97
|
-
__resetRateLimit();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
function makeFormData(fields: Record<string, string>): FormData {
|
|
101
|
-
const fd = new FormData();
|
|
102
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
103
|
-
fd.append(key, value);
|
|
104
|
-
}
|
|
105
|
-
return fd;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const VALID_FIELDS = {
|
|
109
|
-
name: "Jane Smith",
|
|
110
|
-
email: "jane@example.com",
|
|
111
|
-
message: "I am interested in your services.",
|
|
112
|
-
// #8661 D8 — the terms box is checked on the server too.
|
|
113
|
-
consent: "true",
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const INITIAL_STATE = null;
|
|
117
|
-
|
|
118
|
-
describe("captureLeadAction — valid input", () => {
|
|
119
|
-
it("#8847 D7 — the success state carries the posted name, for the ending's {name}", async () => {
|
|
120
|
-
mockSubmit.mockResolvedValueOnce({
|
|
121
|
-
ok: true,
|
|
122
|
-
body: { id: "lead_abc123", persisted: "db" },
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
126
|
-
|
|
127
|
-
expect(result).toStrictEqual({ kind: "success", name: "Jane Smith" });
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("returns success state when api-client responds ok", async () => {
|
|
131
|
-
mockSubmit.mockResolvedValueOnce({
|
|
132
|
-
ok: true,
|
|
133
|
-
body: { id: "lead_abc123", persisted: "db" },
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const result = await captureLeadAction(
|
|
137
|
-
INITIAL_STATE,
|
|
138
|
-
makeFormData(VALID_FIELDS),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
expect(result).toMatchObject({ kind: "success" });
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("calls leads.submit with mapped payload from formData", async () => {
|
|
145
|
-
mockSubmit.mockResolvedValueOnce({
|
|
146
|
-
ok: true,
|
|
147
|
-
body: { id: "lead_abc123", persisted: "db" },
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
151
|
-
|
|
152
|
-
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
153
|
-
const body = mockSubmit.mock.calls[0][0] as {
|
|
154
|
-
email: string;
|
|
155
|
-
payload: { name: string; message?: string };
|
|
156
|
-
};
|
|
157
|
-
expect(body.email).toBe("jane@example.com");
|
|
158
|
-
expect(body.payload.name).toBe("Jane Smith");
|
|
159
|
-
expect(body.payload.message).toBe("I am interested in your services.");
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe("captureLeadAction — invalid input (Zod errors)", () => {
|
|
164
|
-
it("returns field errors when email is invalid without calling api-client", async () => {
|
|
165
|
-
const result = await captureLeadAction(
|
|
166
|
-
INITIAL_STATE,
|
|
167
|
-
makeFormData({ name: "Jane", email: "not-an-email" }),
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
expect(result).toMatchObject({
|
|
171
|
-
kind: "error",
|
|
172
|
-
fieldErrors: expect.any(Object),
|
|
173
|
-
});
|
|
174
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("returns field errors when name is missing", async () => {
|
|
178
|
-
const result = await captureLeadAction(
|
|
179
|
-
INITIAL_STATE,
|
|
180
|
-
makeFormData({ name: "", email: "jane@example.com" }),
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
expect(result).toMatchObject({
|
|
184
|
-
kind: "error",
|
|
185
|
-
fieldErrors: expect.any(Object),
|
|
186
|
-
});
|
|
187
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("returns field errors when email is missing", async () => {
|
|
191
|
-
const result = await captureLeadAction(
|
|
192
|
-
INITIAL_STATE,
|
|
193
|
-
makeFormData({ name: "Jane", email: "" }),
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
expect(result).toMatchObject({
|
|
197
|
-
kind: "error",
|
|
198
|
-
fieldErrors: expect.any(Object),
|
|
199
|
-
});
|
|
200
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe("captureLeadAction — API error", () => {
|
|
205
|
-
it("returns generic error when api-client responds not ok", async () => {
|
|
206
|
-
mockSubmit.mockResolvedValueOnce({
|
|
207
|
-
ok: false,
|
|
208
|
-
status: 500,
|
|
209
|
-
body: { error: "internal_error" },
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
const result = await captureLeadAction(
|
|
213
|
-
INITIAL_STATE,
|
|
214
|
-
makeFormData(VALID_FIELDS),
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
expect(result).toMatchObject({
|
|
218
|
-
kind: "error",
|
|
219
|
-
message: expect.any(String),
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// #4042 — a thrown submit leaves a server-side trace; #8747 — it is the
|
|
224
|
-
// API being unreachable, so the visitor is shown the contact email.
|
|
225
|
-
it("a thrown submit is logged with no submitted field, and is unavailable", async () => {
|
|
226
|
-
mockSubmit.mockRejectedValueOnce(new Error("Network error"));
|
|
227
|
-
const consoleErrorSpy = jest
|
|
228
|
-
.spyOn(console, "error")
|
|
229
|
-
.mockImplementation(() => undefined);
|
|
230
|
-
|
|
231
|
-
const result = await captureLeadAction(
|
|
232
|
-
INITIAL_STATE,
|
|
233
|
-
makeFormData(VALID_FIELDS),
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
expect(consoleErrorSpy).toHaveBeenCalled();
|
|
237
|
-
const loggedArgs = consoleErrorSpy.mock.calls.flat();
|
|
238
|
-
for (const value of Object.values(VALID_FIELDS)) {
|
|
239
|
-
for (const arg of loggedArgs) {
|
|
240
|
-
expect(String(arg)).not.toContain(value);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
expect(result).toEqual({ kind: "unavailable" });
|
|
244
|
-
|
|
245
|
-
consoleErrorSpy.mockRestore();
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
// ─── #6730 D8 — honest outcomes and declared extra fields ────────────────────
|
|
250
|
-
|
|
251
|
-
describe("captureLeadAction — outcome mapping (#6730)", () => {
|
|
252
|
-
it("503 lead_capture_not_configured → unavailable", async () => {
|
|
253
|
-
mockSubmit.mockResolvedValueOnce({
|
|
254
|
-
ok: false,
|
|
255
|
-
status: 503,
|
|
256
|
-
body: { error: "lead_capture_not_configured", message: "Lead capture is not configured." },
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
260
|
-
|
|
261
|
-
expect(result).toEqual({ kind: "unavailable" });
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("503 delivery_failed → the generic error, never success", async () => {
|
|
265
|
-
mockSubmit.mockResolvedValueOnce({
|
|
266
|
-
ok: false,
|
|
267
|
-
status: 503,
|
|
268
|
-
body: { error: "delivery_failed", message: "The message could not be delivered." },
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
272
|
-
|
|
273
|
-
expect(result).toMatchObject({ kind: "error" });
|
|
274
|
-
expect(result).not.toMatchObject({ kind: "success" });
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it.each([400, 429, 500, 503])("a non-2xx (%s) is never success", async (status) => {
|
|
278
|
-
mockSubmit.mockResolvedValueOnce({ ok: false, status, body: { error: "x" } });
|
|
279
|
-
|
|
280
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
281
|
-
|
|
282
|
-
expect(result?.kind).toBe("error");
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("201 → success", async () => {
|
|
286
|
-
mockSubmit.mockResolvedValueOnce({
|
|
287
|
-
ok: true,
|
|
288
|
-
body: { id: "email-1-abcdef12", persisted: "email" },
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
292
|
-
|
|
293
|
-
expect(result).toEqual({ kind: "success", name: expect.any(String) });
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe("captureLeadAction — declared extra fields (#6730 D8a)", () => {
|
|
298
|
-
it("carries an extra string field (e.g. a select) into payload", async () => {
|
|
299
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
300
|
-
|
|
301
|
-
await captureLeadAction(INITIAL_STATE, makeFormData({ ...VALID_FIELDS, plan: "pro" }));
|
|
302
|
-
|
|
303
|
-
const body = mockSubmit.mock.calls[0][0] as { payload: Record<string, unknown> };
|
|
304
|
-
expect(body.payload.plan).toBe("pro");
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("never copies reserved or Next-internal fields into payload", async () => {
|
|
308
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
309
|
-
|
|
310
|
-
await captureLeadAction(
|
|
311
|
-
INITIAL_STATE,
|
|
312
|
-
makeFormData({
|
|
313
|
-
...VALID_FIELDS,
|
|
314
|
-
consent: "true",
|
|
315
|
-
ailk_hp: "",
|
|
316
|
-
source: "conversational-intake",
|
|
317
|
-
$ACTION_ID_abc: "",
|
|
318
|
-
}),
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
const body = mockSubmit.mock.calls[0][0] as {
|
|
322
|
-
source: string;
|
|
323
|
-
payload: Record<string, unknown>;
|
|
324
|
-
};
|
|
325
|
-
expect(Object.keys(body.payload).sort()).toEqual(["message", "name", "page"]);
|
|
326
|
-
expect(body.source).toBe("conversational-intake");
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it("more than 20 extra keys → a form error, no API call", async () => {
|
|
330
|
-
const extras = Object.fromEntries(
|
|
331
|
-
Array.from({ length: 21 }, (_, i) => [`extra${i}`, "x"]),
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
const result = await captureLeadAction(
|
|
335
|
-
INITIAL_STATE,
|
|
336
|
-
makeFormData({ ...VALID_FIELDS, ...extras }),
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
expect(result).toMatchObject({ kind: "error" });
|
|
340
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it("an extra value over 2000 characters → a form error, no API call", async () => {
|
|
344
|
-
const result = await captureLeadAction(
|
|
345
|
-
INITIAL_STATE,
|
|
346
|
-
makeFormData({ ...VALID_FIELDS, notes: "x".repeat(2001) }),
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
expect(result).toMatchObject({ kind: "error" });
|
|
350
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
describe("captureLeadAction — honeypot (#6730)", () => {
|
|
355
|
-
it("a filled honeypot → success, and nothing is sent", async () => {
|
|
356
|
-
const result = await captureLeadAction(
|
|
357
|
-
INITIAL_STATE,
|
|
358
|
-
makeFormData({ ...VALID_FIELDS, ailk_hp: "https://spam.example" }),
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
expect(result).toEqual({ kind: "success" });
|
|
362
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
it("a declared `website` field is an ordinary field, carried into payload", async () => {
|
|
366
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
367
|
-
|
|
368
|
-
await captureLeadAction(
|
|
369
|
-
INITIAL_STATE,
|
|
370
|
-
makeFormData({ ...VALID_FIELDS, website: "https://acme.example" }),
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
const body = mockSubmit.mock.calls[0][0] as { payload: Record<string, unknown> };
|
|
374
|
-
expect(body.payload.website).toBe("https://acme.example");
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// #7394 AC-9 — a spoke forwards its visitor to the hub's leads rate limit.
|
|
379
|
-
describe("captureLeadAction — visitor forwarding (#7394)", () => {
|
|
380
|
-
const FORWARD_KEY = "0123456789abcdef".repeat(4); // gitleaks:allow — test fixture, not a credential (#7394)
|
|
381
|
-
const ENV_KEYS = ["AILK_VISITOR_FORWARD_KEY", "AILK_API_URL"] as const;
|
|
382
|
-
const priorEnv = new Map(ENV_KEYS.map((name) => [name, process.env[name]]));
|
|
383
|
-
|
|
384
|
-
beforeEach(() => {
|
|
385
|
-
process.env.AILK_VISITOR_FORWARD_KEY = FORWARD_KEY;
|
|
386
|
-
process.env.AILK_API_URL = "https://hub.example";
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
afterAll(() => {
|
|
390
|
-
for (const [name, value] of priorEnv) {
|
|
391
|
-
if (value === undefined) delete process.env[name];
|
|
392
|
-
else process.env[name] = value;
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
it("passes the helper's two headers as init", async () => {
|
|
397
|
-
const incoming = {
|
|
398
|
-
get: (name: string) => (name === "x-forwarded-for" ? "203.0.113.5" : null),
|
|
399
|
-
};
|
|
400
|
-
mockHeaders.mockResolvedValue(incoming);
|
|
401
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
402
|
-
|
|
403
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
404
|
-
|
|
405
|
-
expect(result).toEqual({ kind: "success", name: expect.any(String) });
|
|
406
|
-
const expected = visitorForwardHeaders(incoming, FORWARD_KEY);
|
|
407
|
-
expect(expected).toEqual({
|
|
408
|
-
"x-ailk-visitor-ip": "203.0.113.5",
|
|
409
|
-
"x-ailk-visitor-forward-key": FORWARD_KEY,
|
|
410
|
-
});
|
|
411
|
-
expect(mockSubmit).toHaveBeenCalledWith(expect.any(Object), { headers: expected });
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
it("calls leads.submit with one argument when headers() throws, and still succeeds", async () => {
|
|
415
|
-
mockHeaders.mockRejectedValue(new Error("outside a request scope"));
|
|
416
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
417
|
-
|
|
418
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
419
|
-
|
|
420
|
-
expect(result).toEqual({ kind: "success", name: expect.any(String) });
|
|
421
|
-
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
422
|
-
expect(mockSubmit.mock.calls[0]).toHaveLength(1);
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
// ─── #8661 D8 — the terms box and the source stamp ──────────────────────────
|
|
427
|
-
|
|
428
|
-
describe("captureLeadAction — consent and source (#8661 D8)", () => {
|
|
429
|
-
const { consent: _consent, ...UNTICKED } = VALID_FIELDS;
|
|
430
|
-
|
|
431
|
-
it("no consent → a consent field error, and nothing is sent", async () => {
|
|
432
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(UNTICKED));
|
|
433
|
-
|
|
434
|
-
expect(result).toEqual({
|
|
435
|
-
kind: "error",
|
|
436
|
-
fieldErrors: { consent: expect.any(String) },
|
|
437
|
-
});
|
|
438
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it("no consent and no name → both errors", async () => {
|
|
442
|
-
const result = await captureLeadAction(
|
|
443
|
-
INITIAL_STATE,
|
|
444
|
-
makeFormData({ ...UNTICKED, name: "" }),
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
expect(result).toMatchObject({ kind: "error" });
|
|
448
|
-
const fieldErrors = (result as { fieldErrors: Record<string, string> }).fieldErrors;
|
|
449
|
-
expect(Object.keys(fieldErrors).sort()).toEqual(["consent", "name"]);
|
|
450
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
it("a ticked flow:contact post carries the source and the subject", async () => {
|
|
454
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
455
|
-
|
|
456
|
-
const result = await captureLeadAction(
|
|
457
|
-
INITIAL_STATE,
|
|
458
|
-
makeFormData({ ...VALID_FIELDS, source: "flow:contact", subject: "Support" }),
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
expect(result).toEqual({ kind: "success", name: expect.any(String) });
|
|
462
|
-
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
463
|
-
const body = mockSubmit.mock.calls[0][0] as {
|
|
464
|
-
source: string;
|
|
465
|
-
payload: Record<string, unknown>;
|
|
466
|
-
};
|
|
467
|
-
expect(body.source).toBe("flow:contact");
|
|
468
|
-
expect(body.payload.subject).toBe("Support");
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
it.each(["flow:other", "flow:onboarding", "admin", "WEB", "web"])(
|
|
472
|
-
"an unknown source (%s) is sent as contact-form",
|
|
473
|
-
async (source) => {
|
|
474
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
475
|
-
|
|
476
|
-
await captureLeadAction(INITIAL_STATE, makeFormData({ ...VALID_FIELDS, source }));
|
|
477
|
-
|
|
478
|
-
expect((mockSubmit.mock.calls[0][0] as { source: string }).source).toBe("contact-form");
|
|
479
|
-
},
|
|
480
|
-
);
|
|
481
|
-
|
|
482
|
-
// #8730 D2/D4 — the hidden source picks the stamp, never the gate: the
|
|
483
|
-
// intake captures consent itself and posts consent=true like the form.
|
|
484
|
-
it("source=conversational-intake without consent is refused, and nothing is sent", async () => {
|
|
485
|
-
const result = await captureLeadAction(
|
|
486
|
-
INITIAL_STATE,
|
|
487
|
-
makeFormData({ ...UNTICKED, source: "conversational-intake" }),
|
|
488
|
-
);
|
|
489
|
-
|
|
490
|
-
expect(result).toEqual({
|
|
491
|
-
kind: "error",
|
|
492
|
-
fieldErrors: { consent: expect.any(String) },
|
|
493
|
-
});
|
|
494
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
it.each(["contact-form", "conversational-intake", "flow:contact", "anything-else"])(
|
|
498
|
-
"no source value (%s) switches the check off",
|
|
499
|
-
async (source) => {
|
|
500
|
-
const result = await captureLeadAction(
|
|
501
|
-
INITIAL_STATE,
|
|
502
|
-
makeFormData({ ...UNTICKED, source }),
|
|
503
|
-
);
|
|
504
|
-
|
|
505
|
-
expect(result).toMatchObject({ kind: "error", fieldErrors: { consent: expect.any(String) } });
|
|
506
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
507
|
-
},
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
it("consent other than the string true is not acceptance", async () => {
|
|
511
|
-
const result = await captureLeadAction(
|
|
512
|
-
INITIAL_STATE,
|
|
513
|
-
makeFormData({ ...VALID_FIELDS, consent: "on" }),
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
expect(result).toMatchObject({ kind: "error", fieldErrors: { consent: expect.any(String) } });
|
|
517
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
it("an intake post with consent=true is sent as conversational-intake, carrying consent: true", async () => {
|
|
521
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
522
|
-
|
|
523
|
-
const result = await captureLeadAction(
|
|
524
|
-
INITIAL_STATE,
|
|
525
|
-
makeFormData({ ...VALID_FIELDS, source: "conversational-intake" }),
|
|
526
|
-
);
|
|
527
|
-
|
|
528
|
-
expect(result).toEqual({ kind: "success", name: expect.any(String) });
|
|
529
|
-
const body = mockSubmit.mock.calls[0][0] as { source: string; consent: unknown };
|
|
530
|
-
expect(body.source).toBe("conversational-intake");
|
|
531
|
-
expect(body.consent).toBe(true);
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
it("every accepted post tells the API the terms were accepted, top level, never in payload", async () => {
|
|
535
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
536
|
-
|
|
537
|
-
await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
538
|
-
|
|
539
|
-
const body = mockSubmit.mock.calls[0][0] as {
|
|
540
|
-
consent: unknown;
|
|
541
|
-
payload: Record<string, unknown>;
|
|
542
|
-
};
|
|
543
|
-
expect(body.consent).toBe(true);
|
|
544
|
-
expect(body.payload).not.toHaveProperty("consent");
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
it("an API 400 consent_required is shown as the consent field error", async () => {
|
|
548
|
-
mockSubmit.mockResolvedValueOnce({
|
|
549
|
-
ok: false,
|
|
550
|
-
status: 400,
|
|
551
|
-
body: { error: "consent_required", message: "Accept the terms to send a contact message." },
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
555
|
-
|
|
556
|
-
expect(result).toEqual({
|
|
557
|
-
kind: "error",
|
|
558
|
-
fieldErrors: { consent: expect.any(String) },
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
// ─── #8747 — the spoke lead writer, the per-visitor limit, an unreachable API ─
|
|
564
|
-
|
|
565
|
-
describe("captureLeadAction — the site marker (#8747)", () => {
|
|
566
|
-
const priorSite = process.env.AILK_LEAD_SITE;
|
|
567
|
-
|
|
568
|
-
afterEach(() => {
|
|
569
|
-
if (priorSite === undefined) delete process.env.AILK_LEAD_SITE;
|
|
570
|
-
else process.env.AILK_LEAD_SITE = priorSite;
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
it("marks payload.site from AILK_LEAD_SITE and payload.page as contact, and sends no siteId", async () => {
|
|
574
|
-
process.env.AILK_LEAD_SITE = "wendihenry";
|
|
575
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
576
|
-
|
|
577
|
-
await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
578
|
-
|
|
579
|
-
const body = mockSubmit.mock.calls[0][0] as Record<string, unknown> & {
|
|
580
|
-
payload: Record<string, unknown>;
|
|
581
|
-
};
|
|
582
|
-
expect(body).not.toHaveProperty("siteId");
|
|
583
|
-
expect(body.payload).toMatchObject({ site: "wendihenry", page: "contact" });
|
|
584
|
-
});
|
|
585
|
-
|
|
586
|
-
it("a form field named site or page never overrides the marker", async () => {
|
|
587
|
-
process.env.AILK_LEAD_SITE = "wendihenry";
|
|
588
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
589
|
-
|
|
590
|
-
await captureLeadAction(
|
|
591
|
-
INITIAL_STATE,
|
|
592
|
-
makeFormData({ ...VALID_FIELDS, site: "attacker", page: "checkout" }),
|
|
593
|
-
);
|
|
594
|
-
|
|
595
|
-
const body = mockSubmit.mock.calls[0][0] as { payload: Record<string, unknown> };
|
|
596
|
-
expect(body.payload.site).toBe("wendihenry");
|
|
597
|
-
expect(body.payload.page).toBe("contact");
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
it("with AILK_LEAD_SITE unset, the lead carries no site at all", async () => {
|
|
601
|
-
delete process.env.AILK_LEAD_SITE;
|
|
602
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
603
|
-
|
|
604
|
-
await captureLeadAction(INITIAL_STATE, makeFormData({ ...VALID_FIELDS, site: "attacker" }));
|
|
605
|
-
|
|
606
|
-
const body = mockSubmit.mock.calls[0][0] as { payload: Record<string, unknown> };
|
|
607
|
-
expect(body.payload).not.toHaveProperty("site");
|
|
608
|
-
expect(body.payload.page).toBe("contact");
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
describe("captureLeadAction — the built-in form's source (#8747)", () => {
|
|
613
|
-
it("a post with no source is stamped contact-form", async () => {
|
|
614
|
-
mockSubmit.mockResolvedValueOnce({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
615
|
-
|
|
616
|
-
await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
617
|
-
|
|
618
|
-
expect((mockSubmit.mock.calls[0][0] as { source: string }).source).toBe("contact-form");
|
|
619
|
-
});
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
describe("captureLeadAction — the per-visitor limit (#8747)", () => {
|
|
623
|
-
const visitor = (ip: string) => ({
|
|
624
|
-
get: (name: string) => (name === "x-vercel-forwarded-for" ? ip : null),
|
|
625
|
-
});
|
|
626
|
-
// On Vercel, where the edge-set address is read; the bot check has its own suite.
|
|
627
|
-
const ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK"] as const;
|
|
628
|
-
const priorEnv = new Map(ENV_KEYS.map((name) => [name, process.env[name]]));
|
|
629
|
-
|
|
630
|
-
beforeEach(() => {
|
|
631
|
-
process.env.VERCEL = "1";
|
|
632
|
-
process.env.AILK_BOT_CHECK = "off";
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
afterEach(() => {
|
|
636
|
-
for (const [name, value] of priorEnv) {
|
|
637
|
-
if (value === undefined) delete process.env[name];
|
|
638
|
-
else process.env[name] = value;
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
it("admits 30 posts from one visitor in ten minutes, and refuses the 31st without calling the API", async () => {
|
|
643
|
-
mockHeaders.mockResolvedValue(visitor("203.0.113.5"));
|
|
644
|
-
mockSubmit.mockResolvedValue({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
645
|
-
|
|
646
|
-
for (let i = 0; i < 30; i += 1) {
|
|
647
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toEqual({
|
|
648
|
-
kind: "success",
|
|
649
|
-
name: expect.any(String),
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
|
-
expect(mockSubmit).toHaveBeenCalledTimes(30);
|
|
653
|
-
|
|
654
|
-
const refused = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
655
|
-
|
|
656
|
-
expect(refused).toMatchObject({ kind: "error", message: expect.any(String) });
|
|
657
|
-
expect(mockSubmit).toHaveBeenCalledTimes(30);
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
it("with no readable address, every post shares one bucket at ten times the limit, never skipped (#9967)", async () => {
|
|
661
|
-
// A client-sent x-forwarded-for is no address: it changes on every post.
|
|
662
|
-
let n = 0;
|
|
663
|
-
mockHeaders.mockImplementation(async () => {
|
|
664
|
-
n += 1;
|
|
665
|
-
return { get: (name: string) => (name === "x-forwarded-for" ? `10.0.${n >> 8}.${n & 255}` : null) };
|
|
666
|
-
});
|
|
667
|
-
mockSubmit.mockResolvedValue({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
668
|
-
|
|
669
|
-
for (let i = 0; i < 300; i += 1) {
|
|
670
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toEqual({
|
|
671
|
-
kind: "success",
|
|
672
|
-
name: expect.any(String),
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
expect(mockSubmit).toHaveBeenCalledTimes(300);
|
|
676
|
-
|
|
677
|
-
const refused = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
678
|
-
|
|
679
|
-
expect(refused).toMatchObject({ kind: "error", message: expect.any(String) });
|
|
680
|
-
expect(mockSubmit).toHaveBeenCalledTimes(300);
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
it("another visitor keeps its own budget", async () => {
|
|
684
|
-
mockSubmit.mockResolvedValue({ ok: true, body: { id: "lead_1", persisted: "db" } });
|
|
685
|
-
mockHeaders.mockResolvedValue(visitor("203.0.113.5"));
|
|
686
|
-
for (let i = 0; i < 30; i += 1) {
|
|
687
|
-
await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
mockHeaders.mockResolvedValue(visitor("198.51.100.7"));
|
|
691
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toEqual({
|
|
692
|
-
kind: "success",
|
|
693
|
-
name: expect.any(String),
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
describe("captureLeadAction — an unreachable API (#8747)", () => {
|
|
699
|
-
it.each([502, 504])("a %s is unavailable", async (status) => {
|
|
700
|
-
mockSubmit.mockResolvedValueOnce({ ok: false, status, body: null });
|
|
701
|
-
|
|
702
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toEqual({
|
|
703
|
-
kind: "unavailable",
|
|
704
|
-
});
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
it("a thrown submit is unavailable", async () => {
|
|
708
|
-
mockSubmit.mockRejectedValueOnce(new TypeError("fetch failed"));
|
|
709
|
-
const spy = jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
710
|
-
|
|
711
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toEqual({
|
|
712
|
-
kind: "unavailable",
|
|
713
|
-
});
|
|
714
|
-
spy.mockRestore();
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
it.each([400, 429, 500, 501, 503])("a %s that is not lead_capture_not_configured stays the generic error", async (status) => {
|
|
718
|
-
mockSubmit.mockResolvedValueOnce({ ok: false, status, body: { error: "x" } });
|
|
719
|
-
|
|
720
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toEqual({
|
|
721
|
-
kind: "error",
|
|
722
|
-
message: expect.any(String),
|
|
723
|
-
});
|
|
724
|
-
});
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
// ── #8757 AC-5 — the thank-you carries the account link on `invite` only ───
|
|
728
|
-
|
|
729
|
-
describe("captureLeadAction — the account link (#8757 D8)", () => {
|
|
730
|
-
const { getLocale } = jest.requireMock("next-intl/server") as { getLocale: jest.Mock };
|
|
731
|
-
const INVITE_FIELDS = { ...VALID_FIELDS, email: "a@b.example" };
|
|
732
|
-
const LABEL = "Track this in your account";
|
|
733
|
-
|
|
734
|
-
function answers(next?: unknown): void {
|
|
735
|
-
mockSubmit.mockResolvedValueOnce({
|
|
736
|
-
ok: true,
|
|
737
|
-
body: {
|
|
738
|
-
id: "lead_abc123",
|
|
739
|
-
persisted: "db",
|
|
740
|
-
email: { attempted: true, sent: true },
|
|
741
|
-
...(next !== undefined && { next }),
|
|
742
|
-
},
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
afterEach(() => {
|
|
747
|
-
mockSignInProvider = "site";
|
|
748
|
-
getLocale.mockResolvedValue("en");
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
it("provider site, locale en (served bare): invite → the sign-in link with next and the email", async () => {
|
|
752
|
-
answers({ completion: "invite" });
|
|
753
|
-
|
|
754
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toEqual({
|
|
755
|
-
kind: "success",
|
|
756
|
-
name: expect.any(String),
|
|
757
|
-
next: { href: "/sign-in?next=%2Faccount&email=a%40b.example", label: LABEL },
|
|
758
|
-
});
|
|
759
|
-
});
|
|
760
|
-
|
|
761
|
-
it("provider site, locale fr: both paths carry the prefix", async () => {
|
|
762
|
-
getLocale.mockResolvedValue("fr");
|
|
763
|
-
answers({ completion: "invite" });
|
|
764
|
-
|
|
765
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toEqual({
|
|
766
|
-
kind: "success",
|
|
767
|
-
name: expect.any(String),
|
|
768
|
-
next: { href: "/fr/sign-in?next=%2Ffr%2Faccount&email=a%40b.example", label: LABEL },
|
|
769
|
-
});
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
it("no next → exactly { kind: success }", async () => {
|
|
773
|
-
answers();
|
|
774
|
-
|
|
775
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toStrictEqual({
|
|
776
|
-
kind: "success",
|
|
777
|
-
name: expect.any(String),
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
it("provider hub → the hub-session sign-in start", async () => {
|
|
782
|
-
mockSignInProvider = "hub";
|
|
783
|
-
answers({ completion: "invite" });
|
|
784
|
-
|
|
785
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toEqual({
|
|
786
|
-
kind: "success",
|
|
787
|
-
name: expect.any(String),
|
|
788
|
-
next: { href: "/api/hub-session/sign-in?next=%2Faccount&email=a%40b.example", label: LABEL },
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
it("provider none → exactly { kind: success }", async () => {
|
|
793
|
-
mockSignInProvider = "none";
|
|
794
|
-
answers({ completion: "invite" });
|
|
795
|
-
|
|
796
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toStrictEqual({
|
|
797
|
-
kind: "success",
|
|
798
|
-
name: expect.any(String),
|
|
799
|
-
});
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
it("an unreadable locale still answers success, with the default locale's link", async () => {
|
|
803
|
-
getLocale.mockRejectedValueOnce(new Error("no request scope"));
|
|
804
|
-
answers({ completion: "invite" });
|
|
805
|
-
|
|
806
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toEqual({
|
|
807
|
-
kind: "success",
|
|
808
|
-
name: expect.any(String),
|
|
809
|
-
next: { href: "/sign-in?next=%2Faccount&email=a%40b.example", label: LABEL },
|
|
810
|
-
});
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
it("a malformed next is ignored → exactly { kind: success }", async () => {
|
|
814
|
-
answers({ completion: "invite", extra: true });
|
|
815
|
-
|
|
816
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(INVITE_FIELDS))).toStrictEqual({
|
|
817
|
-
kind: "success",
|
|
818
|
-
name: expect.any(String),
|
|
819
|
-
});
|
|
820
|
-
});
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
describe("captureLeadAction — a checkout magnet answers the Offerings buy route after the write (#8757 D11, #9171)", () => {
|
|
824
|
-
// The shown-set read is shared for 15 seconds per instance, so each case
|
|
825
|
-
// starts a minute past the last one's window.
|
|
826
|
-
let clock = Date.now();
|
|
827
|
-
let now: jest.SpyInstance<number, []>;
|
|
828
|
-
beforeEach(() => {
|
|
829
|
-
clock += 60_000;
|
|
830
|
-
now = jest.spyOn(Date, "now").mockReturnValue(clock);
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
function answers(next: unknown): void {
|
|
834
|
-
mockSubmit.mockResolvedValueOnce({
|
|
835
|
-
ok: true,
|
|
836
|
-
body: { id: "lead_abc123", persisted: "db", email: { skipped: true }, next },
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
/** A shown set in `state`: one `plan` carrying a Price per `period`. */
|
|
841
|
-
function shownSet(
|
|
842
|
-
periods: readonly ("monthly" | "yearly" | "once")[],
|
|
843
|
-
plan = "retainer",
|
|
844
|
-
state = "current",
|
|
845
|
-
): unknown {
|
|
846
|
-
return workspaceShownSetSchema.partial({ workspaceId: true, organizationId: true }).parse({
|
|
847
|
-
productIds: [`prod_${plan}`],
|
|
848
|
-
recommended: { plan: null, addon: null },
|
|
849
|
-
offerings: [
|
|
850
|
-
{
|
|
851
|
-
productId: `prod_${plan}`,
|
|
852
|
-
plan,
|
|
853
|
-
name: plan,
|
|
854
|
-
description: null,
|
|
855
|
-
marketingFeatures: [],
|
|
856
|
-
unitLabel: null,
|
|
857
|
-
note: null,
|
|
858
|
-
termsNote: null,
|
|
859
|
-
ailkGroup: "plan",
|
|
860
|
-
ailkOrder: null,
|
|
861
|
-
prices: periods.map((period) => ({
|
|
862
|
-
priceId: `price_${plan}_${period}`,
|
|
863
|
-
lookupKey: `${plan}_${period}`,
|
|
864
|
-
plan,
|
|
865
|
-
period,
|
|
866
|
-
interval: { monthly: "month", yearly: "year", once: null }[period],
|
|
867
|
-
amount: 4900,
|
|
868
|
-
currency: "usd",
|
|
869
|
-
})),
|
|
870
|
-
recommended: false,
|
|
871
|
-
},
|
|
872
|
-
],
|
|
873
|
-
state,
|
|
874
|
-
snapshotAt: "2026-10-26T00:00:00.000Z",
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
afterEach(() => {
|
|
879
|
-
mockShown.mockReset();
|
|
880
|
-
now.mockRestore();
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
/** The shown-set read answers `body` (the api-client's unwrapped 2xx). */
|
|
884
|
-
function shows(body: unknown): void {
|
|
885
|
-
mockShown.mockResolvedValueOnce({ ok: true, status: 200, body });
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
it("next: checkout, retainer → the success state carries /api/offerings/checkout/retainer_monthly, after exactly one write", async () => {
|
|
889
|
-
answers({ completion: "checkout", checkoutOffering: "retainer" });
|
|
890
|
-
shows({ status: "shown", shownSet: shownSet(["monthly", "yearly"]) });
|
|
891
|
-
|
|
892
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
893
|
-
kind: "success",
|
|
894
|
-
name: "Jane Smith",
|
|
895
|
-
redirect: "/api/offerings/checkout/retainer_monthly",
|
|
896
|
-
});
|
|
897
|
-
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
898
|
-
expect(mockSubmit.mock.invocationCallOrder[0]!).toBeLessThan(
|
|
899
|
-
mockShown.mock.invocationCallOrder[0]!,
|
|
900
|
-
);
|
|
901
|
-
// The form navigates; never a Server Action redirect, and never the retired route.
|
|
902
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
903
|
-
});
|
|
904
|
-
|
|
905
|
-
it("one shown-set read serves every submit within 15 seconds", async () => {
|
|
906
|
-
const checkout = { completion: "checkout", checkoutOffering: "retainer" };
|
|
907
|
-
answers(checkout);
|
|
908
|
-
answers(checkout);
|
|
909
|
-
answers(checkout);
|
|
910
|
-
shows({ status: "shown", shownSet: shownSet(["monthly"]) });
|
|
911
|
-
shows({ status: "shown", shownSet: shownSet(["yearly"]) });
|
|
912
|
-
const submit = () => captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
913
|
-
|
|
914
|
-
expect(await submit()).toMatchObject({ redirect: "/api/offerings/checkout/retainer_monthly" });
|
|
915
|
-
now.mockReturnValue(clock + 14_999);
|
|
916
|
-
expect(await submit()).toMatchObject({ redirect: "/api/offerings/checkout/retainer_monthly" });
|
|
917
|
-
expect(mockShown).toHaveBeenCalledTimes(1);
|
|
918
|
-
now.mockReturnValue(clock + 15_000);
|
|
919
|
-
expect(await submit()).toMatchObject({ redirect: "/api/offerings/checkout/retainer_yearly" });
|
|
920
|
-
expect(mockShown).toHaveBeenCalledTimes(2);
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
it.each([
|
|
924
|
-
[["yearly", "once"], "retainer_yearly"],
|
|
925
|
-
[["once"], "retainer_once"],
|
|
926
|
-
] as const)(
|
|
927
|
-
"the key /pricing's card links first: shown %j → %s",
|
|
928
|
-
async (periods, lookupKey) => {
|
|
929
|
-
answers({ completion: "checkout", checkoutOffering: "retainer" });
|
|
930
|
-
shows({ status: "shown", shownSet: shownSet(periods) });
|
|
931
|
-
|
|
932
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toMatchObject({
|
|
933
|
-
redirect: `/api/offerings/checkout/${lookupKey}`,
|
|
934
|
-
});
|
|
935
|
-
},
|
|
936
|
-
);
|
|
937
|
-
|
|
938
|
-
it("a stored lookup key is the key itself, never `<key>_monthly` (#10823)", async () => {
|
|
939
|
-
answers({ completion: "checkout", checkoutOffering: "growth-ops-growth_yearly" });
|
|
940
|
-
shows({ status: "shown", shownSet: shownSet(["monthly", "yearly"], "growth-ops-growth") });
|
|
941
|
-
|
|
942
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
943
|
-
kind: "success",
|
|
944
|
-
name: "Jane Smith",
|
|
945
|
-
redirect: "/api/offerings/checkout/growth-ops-growth_yearly",
|
|
946
|
-
});
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
it("a stored lookup key the shown set does not show → exactly { kind: success } (#10823)", async () => {
|
|
950
|
-
answers({ completion: "checkout", checkoutOffering: "growth-ops-growth_once" });
|
|
951
|
-
shows({ status: "shown", shownSet: shownSet(["monthly", "yearly"], "growth-ops-growth") });
|
|
952
|
-
|
|
953
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
954
|
-
kind: "success",
|
|
955
|
-
name: expect.any(String),
|
|
956
|
-
});
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
it.each([
|
|
960
|
-
["a plan the shown set does not show", () => shows({ status: "shown", shownSet: shownSet(["monthly"], "growth") })],
|
|
961
|
-
["an unconnected site", () => shows({ status: "unconnected" })],
|
|
962
|
-
["a shown set that is not current", () => shows({ status: "shown", shownSet: shownSet(["monthly"], "retainer", "expired") })],
|
|
963
|
-
["a non-2xx read", () => mockShown.mockResolvedValueOnce({ ok: false, status: 503, body: null })],
|
|
964
|
-
["a thrown read", () => mockShown.mockRejectedValueOnce(new Error("network"))],
|
|
965
|
-
] as const)("%s → exactly { kind: success } and no buy route", async (_label, read) => {
|
|
966
|
-
answers({ completion: "checkout", checkoutOffering: "retainer" });
|
|
967
|
-
read();
|
|
968
|
-
|
|
969
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
970
|
-
kind: "success",
|
|
971
|
-
name: expect.any(String),
|
|
972
|
-
});
|
|
973
|
-
expect(mockSubmit).toHaveBeenCalledTimes(1);
|
|
974
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
it("a read with no answer within 5 seconds → exactly { kind: success } and no buy route", async () => {
|
|
978
|
-
jest.useFakeTimers({ doNotFake: ["nextTick", "setImmediate", "queueMicrotask", "Date"] });
|
|
979
|
-
try {
|
|
980
|
-
answers({ completion: "checkout", checkoutOffering: "retainer" });
|
|
981
|
-
mockShown.mockReturnValueOnce(new Promise(() => {}));
|
|
982
|
-
|
|
983
|
-
const result = captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
984
|
-
await jest.advanceTimersByTimeAsync(5_000);
|
|
985
|
-
expect(await result).toStrictEqual({ kind: "success", name: expect.any(String) });
|
|
986
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
987
|
-
} finally {
|
|
988
|
-
jest.useRealTimers();
|
|
989
|
-
}
|
|
990
|
-
});
|
|
991
|
-
|
|
992
|
-
it.each([
|
|
993
|
-
["a 500", { ok: false, status: 500, body: { error: "boom" } }, "error"],
|
|
994
|
-
["an unreachable API", { ok: false, status: 0, body: null }, "unavailable"],
|
|
995
|
-
[
|
|
996
|
-
"lead capture not configured",
|
|
997
|
-
{ ok: false, status: 503, body: { error: "lead_capture_not_configured" } },
|
|
998
|
-
"unavailable",
|
|
999
|
-
],
|
|
1000
|
-
] as const)("a failed write (%s) → { kind: %s } and no buy route", async (_label, response, kind) => {
|
|
1001
|
-
mockSubmit.mockResolvedValueOnce(response);
|
|
1002
|
-
|
|
1003
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
1004
|
-
expect(result).toMatchObject({ kind });
|
|
1005
|
-
expect(mockShown).not.toHaveBeenCalled();
|
|
1006
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
it("a thrown write → { kind: unavailable } and no buy route", async () => {
|
|
1010
|
-
mockSubmit.mockRejectedValueOnce(new Error("network"));
|
|
1011
|
-
|
|
1012
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
1013
|
-
expect(result).toMatchObject({ kind: "unavailable" });
|
|
1014
|
-
expect(mockShown).not.toHaveBeenCalled();
|
|
1015
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
1016
|
-
});
|
|
1017
|
-
|
|
1018
|
-
it.each(["../x", "/evil", "Retainer", "has_underscore", "a".repeat(41), ""])(
|
|
1019
|
-
"checkoutOffering %j → exactly { kind: success }, no shown-set read and no buy route",
|
|
1020
|
-
async (checkoutOffering) => {
|
|
1021
|
-
answers({ completion: "checkout", checkoutOffering });
|
|
1022
|
-
|
|
1023
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
1024
|
-
kind: "success",
|
|
1025
|
-
name: expect.any(String),
|
|
1026
|
-
});
|
|
1027
|
-
expect(mockShown).not.toHaveBeenCalled();
|
|
1028
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
1029
|
-
},
|
|
1030
|
-
);
|
|
1031
|
-
|
|
1032
|
-
it("an invite still answers the account link and no buy route", async () => {
|
|
1033
|
-
answers({ completion: "invite" });
|
|
1034
|
-
|
|
1035
|
-
const result = await captureLeadAction(
|
|
1036
|
-
INITIAL_STATE,
|
|
1037
|
-
makeFormData({ ...VALID_FIELDS, email: "a@b.example" }),
|
|
1038
|
-
);
|
|
1039
|
-
expect(result).toMatchObject({ kind: "success", next: { label: "Track this in your account" } });
|
|
1040
|
-
expect(mockShown).not.toHaveBeenCalled();
|
|
1041
|
-
expect(mockRedirect).not.toHaveBeenCalled();
|
|
1042
|
-
});
|
|
1043
|
-
});
|
|
1044
|
-
|
|
1045
|
-
// #9255 D4 — the write bot check runs after the honeypot, the consent and
|
|
1046
|
-
// the schema, immediately before the write (spec
|
|
1047
|
-
// docs/specs/9255-an-edge-bot-challenge-in-spec.md §5.1 AC-2).
|
|
1048
|
-
describe("captureLeadAction — the write bot check (#9255)", () => {
|
|
1049
|
-
const BOT = { isHuman: false, isBot: true, isVerifiedBot: false, bypassed: false };
|
|
1050
|
-
const HUMAN = { ...BOT, isHuman: true, isBot: false };
|
|
1051
|
-
const BOT_ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK", "AILK_BOOKING_BOT_CHECK"] as const;
|
|
1052
|
-
const priorBotEnv = new Map(BOT_ENV_KEYS.map((name) => [name, process.env[name]]));
|
|
1053
|
-
|
|
1054
|
-
let botLogSpies: jest.SpyInstance[] = [];
|
|
1055
|
-
|
|
1056
|
-
beforeEach(() => {
|
|
1057
|
-
checkBotIdMock.mockReset();
|
|
1058
|
-
for (const name of BOT_ENV_KEYS) delete process.env[name];
|
|
1059
|
-
process.env.VERCEL = "1";
|
|
1060
|
-
botLogSpies = [
|
|
1061
|
-
jest.spyOn(console, "warn").mockImplementation(() => undefined),
|
|
1062
|
-
jest.spyOn(console, "error").mockImplementation(() => undefined),
|
|
1063
|
-
];
|
|
1064
|
-
});
|
|
1065
|
-
|
|
1066
|
-
afterEach(() => {
|
|
1067
|
-
for (const [name, value] of priorBotEnv) {
|
|
1068
|
-
if (value === undefined) delete process.env[name];
|
|
1069
|
-
else process.env[name] = value;
|
|
1070
|
-
}
|
|
1071
|
-
for (const spy of botLogSpies) spy.mockRestore();
|
|
1072
|
-
});
|
|
1073
|
-
|
|
1074
|
-
const OK = { ok: true, body: { id: "lead_abc123", persisted: "db" } };
|
|
1075
|
-
|
|
1076
|
-
it("a bot gets the generic error, and nothing is sent", async () => {
|
|
1077
|
-
checkBotIdMock.mockResolvedValue(BOT);
|
|
1078
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
1079
|
-
expect(result).toStrictEqual({ kind: "error", message: "Something went wrong, please try again." });
|
|
1080
|
-
expect(checkBotIdMock).toHaveBeenCalledTimes(1);
|
|
1081
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
1082
|
-
});
|
|
1083
|
-
|
|
1084
|
-
it("a check that fails is unavailable, and nothing is sent", async () => {
|
|
1085
|
-
checkBotIdMock.mockRejectedValue(new Error("boom"));
|
|
1086
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
1087
|
-
expect(result).toStrictEqual({ kind: "unavailable" });
|
|
1088
|
-
expect(mockSubmit).not.toHaveBeenCalled();
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
it("a human sends exactly what the check off sends", async () => {
|
|
1092
|
-
checkBotIdMock.mockResolvedValue(HUMAN);
|
|
1093
|
-
mockSubmit.mockResolvedValue(OK);
|
|
1094
|
-
delete process.env.VERCEL;
|
|
1095
|
-
await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS));
|
|
1096
|
-
process.env.VERCEL = "1";
|
|
1097
|
-
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toMatchObject({
|
|
1098
|
-
kind: "success",
|
|
1099
|
-
});
|
|
1100
|
-
expect(checkBotIdMock).toHaveBeenCalledTimes(1);
|
|
1101
|
-
expect(mockSubmit).toHaveBeenCalledTimes(2);
|
|
1102
|
-
expect(mockSubmit.mock.calls[1]).toEqual(mockSubmit.mock.calls[0]);
|
|
1103
|
-
});
|
|
1104
|
-
|
|
1105
|
-
it("a filled honeypot answers success with no check", async () => {
|
|
1106
|
-
checkBotIdMock.mockResolvedValue(BOT);
|
|
1107
|
-
const result = await captureLeadAction(
|
|
1108
|
-
INITIAL_STATE,
|
|
1109
|
-
makeFormData({ ...VALID_FIELDS, ailk_hp: "spam" }),
|
|
1110
|
-
);
|
|
1111
|
-
expect(result).toEqual({ kind: "success" });
|
|
1112
|
-
expect(checkBotIdMock).not.toHaveBeenCalled();
|
|
1113
|
-
});
|
|
1114
|
-
|
|
1115
|
-
it("a post without consent answers the consent error with no check", async () => {
|
|
1116
|
-
checkBotIdMock.mockResolvedValue(BOT);
|
|
1117
|
-
const { consent: _consent, ...unticked } = VALID_FIELDS;
|
|
1118
|
-
const result = await captureLeadAction(INITIAL_STATE, makeFormData(unticked));
|
|
1119
|
-
expect(result).toEqual({ kind: "error", fieldErrors: { consent: expect.any(String) } });
|
|
1120
|
-
expect(checkBotIdMock).not.toHaveBeenCalled();
|
|
1121
|
-
});
|
|
1122
|
-
});
|