create-ailk 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/add-route.js +15 -0
  2. package/dist/body-heading.d.ts +2 -1
  3. package/dist/body-heading.js +31 -3
  4. package/dist/module-architecture.js +0 -3
  5. package/dist/remove-module.js +13 -4
  6. package/dist/routes.d.ts +7 -0
  7. package/dist/routes.js +1 -1
  8. package/dist/site-roster.js +7 -1
  9. package/dist/surfaces.d.ts +2 -0
  10. package/dist/surfaces.js +59 -172
  11. package/package.json +3 -3
  12. package/templates/apps/web/CLAUDE.md +7 -1
  13. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
  14. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
  15. package/templates/apps/web/app/[locale]/layout.tsx +1 -1
  16. package/templates/apps/web/i18n/request.ts +5 -1
  17. package/templates/apps/web/jest.config.cjs +6 -0
  18. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  19. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  20. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  21. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  22. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  23. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  24. package/templates/apps/web/lib/pricing-page.ts +3 -3
  25. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +1 -1
  26. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +1 -1
  27. package/templates/apps/web/lib/site-header.ts +1 -1
  28. package/templates/apps/web/messages/en.json +0 -119
  29. package/templates/apps/web/next.config.mjs +7 -0
  30. package/templates/apps/web/package.json +1 -0
  31. package/templates/apps/web/site-pages.config.tsx +85 -0
  32. package/templates/tools/body-heading.ts +30 -3
  33. package/versions.json +50 -49
  34. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  35. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  36. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  37. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  38. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  39. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  40. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  41. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  42. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  43. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  44. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  45. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  46. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  47. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  48. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  49. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  50. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  51. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  52. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  53. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  54. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  55. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  56. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  57. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  58. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  59. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  60. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  61. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  62. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  63. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  64. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  65. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  66. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  67. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  68. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  69. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  70. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  71. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  72. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  73. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  74. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  75. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  76. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  77. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  78. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  79. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  80. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  81. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  82. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  83. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  84. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  85. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  86. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  87. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  88. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  89. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  90. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  91. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  92. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  93. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  94. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  95. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  96. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  97. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  98. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  99. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  100. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  101. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  102. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  103. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  104. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  105. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  106. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  107. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  108. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  109. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  110. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  111. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  112. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  113. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  114. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  115. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  116. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  117. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  118. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  119. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  120. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  121. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  122. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  123. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  124. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  125. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  126. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  127. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  128. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  129. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  130. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  131. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  132. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  133. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  134. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  135. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  136. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  137. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  138. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  139. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  140. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  141. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  142. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  143. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  144. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  145. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  146. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  147. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  148. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  149. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  150. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  151. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  152. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  153. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  155. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  156. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  157. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  158. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  159. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  160. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  161. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  162. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  163. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  164. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  165. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  166. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  167. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  168. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  169. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  170. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  171. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  172. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  173. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  174. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  175. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  176. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  177. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  178. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  179. package/templates/apps/web/lib/hub-children.tsx +0 -351
  180. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  181. package/templates/apps/web/lib/posting-title.ts +0 -39
  182. package/templates/apps/web/lib/route-family.ts +0 -69
  183. package/templates/apps/web/lib/service-listing.ts +0 -89
  184. package/templates/apps/web/lib/template-listing.ts +0 -169
  185. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  186. package/templates/apps/web/src/lib/lead-write.ts +0 -90
  187. /package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +0 -0
@@ -1,497 +0,0 @@
1
- /**
2
- * The job page's apply action (#8746 D4, D5; AC-5): a submission writes one
3
- * lead through the site's lead writer with source `flow:job-application`,
4
- * `name` = first + last, and the posting's slug as the hidden `job` value.
5
- */
6
-
7
- import {
8
- __resetRateLimit,
9
- checkRateLimit,
10
- } from "../../../../src/lib/rate-limit";
11
- import { captureLeadAction } from "../[slug]/apply.actions";
12
-
13
- // #9255 — the write bot check's verdict. `checkBotId` reads Vercel's
14
- // request context, which jest has none of, so every case decides it here.
15
- const checkBotIdMock = jest.fn();
16
- jest.mock("botid/server", () => ({
17
- checkBotId: (...args: unknown[]) => checkBotIdMock(...args),
18
- }));
19
-
20
- jest.mock("@working-theory/api-client", () => ({
21
- leads: { submit: jest.fn() },
22
- visitorForwardHeaders: jest.requireActual("@working-theory/api-client")
23
- .visitorForwardHeaders,
24
- }));
25
-
26
- jest.mock("next/headers", () => ({
27
- __esModule: true,
28
- headers: jest.fn().mockResolvedValue({ get: () => null }),
29
- cookies: jest.fn().mockResolvedValue({ get: () => undefined }),
30
- }));
31
-
32
- const mockGetLocale = jest.fn();
33
- const mockGetTranslations = jest.fn();
34
- jest.mock("next-intl/server", () => ({
35
- getLocale: (...args: unknown[]) => mockGetLocale(...args),
36
- getTranslations: (...args: unknown[]) => mockGetTranslations(...args),
37
- }));
38
-
39
- const mockInviteHref = jest.fn();
40
- // eslint-disable-next-line no-restricted-syntax -- accountInviteHref reads the generated topology (build output); this file asserts the action's own decision
41
- jest.mock("../../../../lib/account-invite", () => ({
42
- accountInviteHref: (...args: unknown[]) => mockInviteHref(...args),
43
- }));
44
-
45
- import { leads } from "@working-theory/api-client";
46
- import { headers } from "next/headers";
47
- const mockSubmit = leads.submit as jest.Mock;
48
- const mockHeaders = headers as jest.Mock;
49
-
50
- const JOB = "content-strategist";
51
-
52
- function form(fields: Record<string, string>): FormData {
53
- const fd = new FormData();
54
- for (const [key, value] of Object.entries(fields)) fd.append(key, value);
55
- return fd;
56
- }
57
-
58
- const VALID = {
59
- first_name: "Ada",
60
- last_name: "Lovelace",
61
- email: "ada@example.com",
62
- consent: "true",
63
- };
64
-
65
- type SubmitBody = {
66
- source: string;
67
- email: string;
68
- consent?: boolean;
69
- payload: Record<string, unknown>;
70
- };
71
- const submitted = (): SubmitBody => mockSubmit.mock.calls[0][0] as SubmitBody;
72
-
73
- beforeEach(() => {
74
- mockSubmit.mockResolvedValue({ ok: true, status: 201, body: { ok: true } });
75
- mockGetLocale.mockResolvedValue("en");
76
- mockGetTranslations.mockResolvedValue((key: string) =>
77
- key === "trackInAccount" ? "Track this in your account" : key,
78
- );
79
- mockInviteHref.mockReturnValue("/sign-in?next=%2Faccount&email=ada%40example.com");
80
- });
81
-
82
- afterEach(() => {
83
- jest.clearAllMocks();
84
- mockHeaders.mockResolvedValue({ get: () => null });
85
- __resetRateLimit();
86
- delete process.env.AILK_LEAD_SITE;
87
- });
88
-
89
- describe("captureLeadAction on a job page (#8746 AC-5)", () => {
90
- // On Vercel, where the edge-set address is read (#9967 D1); the bot check
91
- // has its own suite below.
92
- const LIMIT_ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK"] as const;
93
- const priorLimitEnv = new Map(
94
- LIMIT_ENV_KEYS.map((name) => [name, process.env[name]]),
95
- );
96
- beforeEach(() => {
97
- process.env.VERCEL = "1";
98
- process.env.AILK_BOT_CHECK = "off";
99
- });
100
- afterEach(() => {
101
- for (const [name, value] of priorLimitEnv) {
102
- if (value === undefined) delete process.env[name];
103
- else process.env[name] = value;
104
- }
105
- });
106
-
107
- it("writes one flow:job-application lead with name = first + last and the hidden job slug", async () => {
108
- const result = await captureLeadAction(JOB, null, form(VALID));
109
-
110
- expect(result).toEqual({ kind: "success" });
111
- expect(mockSubmit).toHaveBeenCalledTimes(1);
112
- const body = submitted();
113
- expect(body.source).toBe("flow:job-application");
114
- expect(body.email).toBe("ada@example.com");
115
- expect(body.payload).toEqual({
116
- name: "Ada Lovelace",
117
- first_name: "Ada",
118
- last_name: "Lovelace",
119
- job: JOB,
120
- page: "careers",
121
- });
122
- expect(body).not.toHaveProperty("siteId");
123
- });
124
-
125
- it("sends the accepted terms as the body's top-level consent: true, never inside payload (#9130)", async () => {
126
- await captureLeadAction(JOB, null, form(VALID));
127
-
128
- const body = submitted();
129
- expect(body.consent).toBe(true);
130
- expect(body.payload).not.toHaveProperty("consent");
131
- });
132
-
133
- it("carries phone and a LinkedIn URL, a bare domain gaining https://", async () => {
134
- await captureLeadAction(
135
- JOB,
136
- null,
137
- form({
138
- ...VALID,
139
- phone: "+1 555 0100",
140
- linkedin_url: "linkedin.com/in/ada",
141
- }),
142
- );
143
- expect(submitted().payload).toMatchObject({
144
- phone: "+1 555 0100",
145
- linkedin_url: "https://linkedin.com/in/ada",
146
- });
147
- });
148
-
149
- it("keeps an extra field the owner added to the magnet, and no field overrides job, name or source", async () => {
150
- await captureLeadAction(
151
- JOB,
152
- null,
153
- form({
154
- ...VALID,
155
- cover_letter: "Hello",
156
- job: "other-job",
157
- name: "Mallory",
158
- source: "web",
159
- }),
160
- );
161
- const body = submitted();
162
- expect(body.source).toBe("flow:job-application");
163
- expect(body.payload).toMatchObject({
164
- cover_letter: "Hello",
165
- job: JOB,
166
- name: "Ada Lovelace",
167
- });
168
- });
169
-
170
- it.each([
171
- ["first_name", { ...VALID, first_name: " " }],
172
- ["last_name", { ...VALID, last_name: "" }],
173
- ["email", { ...VALID, email: "not-an-email" }],
174
- ["linkedin_url", { ...VALID, linkedin_url: "not a url" }],
175
- ["linkedin_url", { ...VALID, linkedin_url: "javascript:alert(1)" }],
176
- [
177
- "linkedin_url",
178
- { ...VALID, linkedin_url: "https://linkedin.com@evil.example/in/ada" },
179
- ],
180
- ["consent", { ...VALID, consent: "" }],
181
- ])(
182
- "refuses a bad %s with a field error and sends nothing",
183
- async (field, fields) => {
184
- const result = await captureLeadAction(JOB, null, form(fields));
185
- expect(result).toMatchObject({
186
- kind: "error",
187
- fieldErrors: { [field]: expect.any(String) },
188
- });
189
- expect(mockSubmit).not.toHaveBeenCalled();
190
- },
191
- );
192
-
193
- it("refuses a job value that is not a slug, sending nothing", async () => {
194
- const result = await captureLeadAction("../../etc", null, form(VALID));
195
- expect(result).toMatchObject({ kind: "error" });
196
- expect(mockSubmit).not.toHaveBeenCalled();
197
- });
198
-
199
- it.each([[["eng-lead"]], [123]])(
200
- "refuses a bound job of the wrong type (%p), sending nothing",
201
- async (job) => {
202
- // eslint-disable-next-line no-restricted-syntax -- a tampered bound argument is exactly a value of the wrong type
203
- const tampered = job as unknown as string;
204
- const result = await captureLeadAction(tampered, null, form(VALID));
205
- expect(result).toMatchObject({ kind: "error" });
206
- expect(mockSubmit).not.toHaveBeenCalled();
207
- },
208
- );
209
-
210
- it("reads host:port without a scheme as a bare domain", async () => {
211
- await captureLeadAction(
212
- JOB,
213
- null,
214
- form({ ...VALID, linkedin_url: "www.linkedin.com:443/in/ada" }),
215
- );
216
- expect(submitted().payload).toMatchObject({
217
- linkedin_url: "https://www.linkedin.com:443/in/ada",
218
- });
219
- });
220
-
221
- it("shares /contact's per-visitor bucket", async () => {
222
- mockHeaders.mockResolvedValue({
223
- get: (name: string) =>
224
- name === "x-vercel-forwarded-for" ? "203.0.113.7" : null,
225
- });
226
- for (let i = 0; i < 30; i += 1)
227
- checkRateLimit("contact:203.0.113.7", 30, 10 * 60 * 1000);
228
- expect(await captureLeadAction(JOB, null, form(VALID))).toMatchObject({
229
- kind: "error",
230
- });
231
- expect(mockSubmit).not.toHaveBeenCalled();
232
- });
233
-
234
- it("answers a filled honeypot as success and sends nothing", async () => {
235
- const result = await captureLeadAction(
236
- JOB,
237
- null,
238
- form({ ...VALID, ailk_hp: "bot" }),
239
- );
240
- expect(result).toEqual({ kind: "success" });
241
- expect(mockSubmit).not.toHaveBeenCalled();
242
- });
243
-
244
- it("maps lead_capture_not_configured and an unreachable API to unavailable", async () => {
245
- mockSubmit.mockResolvedValueOnce({
246
- ok: false,
247
- status: 503,
248
- body: { error: "lead_capture_not_configured" },
249
- });
250
- expect(await captureLeadAction(JOB, null, form(VALID))).toEqual({
251
- kind: "unavailable",
252
- });
253
- mockSubmit.mockRejectedValueOnce(new Error("fetch failed"));
254
- expect(await captureLeadAction(JOB, null, form(VALID))).toEqual({
255
- kind: "unavailable",
256
- });
257
- });
258
-
259
- it("answers any other refusal with the generic error", async () => {
260
- mockSubmit.mockResolvedValueOnce({
261
- ok: false,
262
- status: 400,
263
- body: { error: "invalid" },
264
- });
265
- expect(await captureLeadAction(JOB, null, form(VALID))).toMatchObject({
266
- kind: "error",
267
- message: expect.any(String),
268
- });
269
- });
270
-
271
- it("limits one visitor to 30 applications per 10 minutes", async () => {
272
- mockHeaders.mockResolvedValue({
273
- get: (name: string) =>
274
- name === "x-vercel-forwarded-for" ? "203.0.113.9" : null,
275
- });
276
- for (let i = 0; i < 30; i += 1) {
277
- expect(await captureLeadAction(JOB, null, form(VALID))).toEqual({
278
- kind: "success",
279
- });
280
- }
281
- expect(await captureLeadAction(JOB, null, form(VALID))).toMatchObject({
282
- kind: "error",
283
- });
284
- expect(mockSubmit).toHaveBeenCalledTimes(30);
285
- });
286
-
287
- it("charges a visitor with no readable address /contact's shared bucket, never skips it (#9967)", async () => {
288
- // A client-sent x-forwarded-for is no address: it changes on every post.
289
- let n = 0;
290
- mockHeaders.mockImplementation(async () => {
291
- n += 1;
292
- return {
293
- get: (name: string) =>
294
- name === "x-forwarded-for" ? `10.0.${n >> 8}.${n & 255}` : null,
295
- };
296
- });
297
- for (let i = 0; i < 300; i += 1) {
298
- expect(await captureLeadAction(JOB, null, form(VALID))).toEqual({
299
- kind: "success",
300
- });
301
- }
302
- expect(await captureLeadAction(JOB, null, form(VALID))).toMatchObject({
303
- kind: "error",
304
- });
305
- expect(mockSubmit).toHaveBeenCalledTimes(300);
306
- });
307
- });
308
-
309
- describe("the thank-you's account link (#8771 AC-6)", () => {
310
- const invite = () =>
311
- mockSubmit.mockResolvedValue({
312
- ok: true,
313
- status: 201,
314
- body: { ok: true, next: { completion: "invite" } },
315
- });
316
-
317
- it("an invite answer returns the prefilled link and label", async () => {
318
- invite();
319
-
320
- const result = await captureLeadAction(JOB, null, form(VALID));
321
-
322
- expect(result).toEqual({
323
- kind: "success",
324
- next: {
325
- href: "/sign-in?next=%2Faccount&email=ada%40example.com",
326
- label: "Track this in your account",
327
- },
328
- });
329
- expect(mockInviteHref).toHaveBeenCalledWith("en", "ada@example.com");
330
- });
331
-
332
- it.each([
333
- ["no next", { ok: true }],
334
- ["a checkout next", { ok: true, next: { completion: "checkout", checkoutOffering: "retainer" } }],
335
- ])("%s: exactly { kind: 'success' }", async (_name, body) => {
336
- mockSubmit.mockResolvedValue({ ok: true, status: 201, body });
337
-
338
- await expect(captureLeadAction(JOB, null, form(VALID))).resolves.toEqual({ kind: "success" });
339
- expect(mockInviteHref).not.toHaveBeenCalled();
340
- });
341
-
342
- it("a site with no sign-in (href null) is exactly { kind: 'success' }", async () => {
343
- invite();
344
- mockInviteHref.mockReturnValue(null);
345
- await expect(captureLeadAction(JOB, null, form(VALID))).resolves.toEqual({ kind: "success" });
346
- });
347
-
348
- it.each([
349
- ["getLocale", () => mockGetLocale.mockRejectedValue(new Error("x"))],
350
- ["accountInviteHref", () => mockInviteHref.mockImplementation(() => { throw new Error("x"); })],
351
- ["getTranslations", () => mockGetTranslations.mockRejectedValue(new Error("x"))],
352
- ])("a throw from %s after the write is still a success", async (_name, arm) => {
353
- invite();
354
- arm();
355
- await expect(captureLeadAction(JOB, null, form(VALID))).resolves.toEqual({ kind: "success" });
356
- expect(mockSubmit).toHaveBeenCalledTimes(1);
357
- });
358
-
359
- it("a filled honeypot is exactly { kind: 'success' } and writes nothing", async () => {
360
- const result = await captureLeadAction(JOB, null, form({ ...VALID, ailk_hp: "http://x" }));
361
- expect(result).toEqual({ kind: "success" });
362
- expect(mockSubmit).not.toHaveBeenCalled();
363
- });
364
- });
365
-
366
- // #9255 D4 — the write bot check runs after the honeypot, the consent and
367
- // the schema, immediately before the write (spec
368
- // docs/specs/9255-an-edge-bot-challenge-in-spec.md §5.1 AC-2).
369
- describe("captureLeadAction on a job page — the write bot check (#9255)", () => {
370
- const BOT = { isHuman: false, isBot: true, isVerifiedBot: false, bypassed: false };
371
- const HUMAN = { ...BOT, isHuman: true, isBot: false };
372
- const BOT_ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK", "AILK_BOOKING_BOT_CHECK"] as const;
373
- const priorBotEnv = new Map(BOT_ENV_KEYS.map((name) => [name, process.env[name]]));
374
-
375
- let botLogSpies: jest.SpyInstance[] = [];
376
-
377
- beforeEach(() => {
378
- checkBotIdMock.mockReset();
379
- for (const name of BOT_ENV_KEYS) delete process.env[name];
380
- process.env.VERCEL = "1";
381
- botLogSpies = [
382
- jest.spyOn(console, "warn").mockImplementation(() => undefined),
383
- jest.spyOn(console, "error").mockImplementation(() => undefined),
384
- ];
385
- });
386
-
387
- afterEach(() => {
388
- for (const [name, value] of priorBotEnv) {
389
- if (value === undefined) delete process.env[name];
390
- else process.env[name] = value;
391
- }
392
- for (const spy of botLogSpies) spy.mockRestore();
393
- });
394
-
395
- it("a bot gets the generic error, and nothing is sent", async () => {
396
- checkBotIdMock.mockResolvedValue(BOT);
397
- expect(await captureLeadAction(JOB, null, form(VALID))).toStrictEqual({
398
- kind: "error",
399
- message: "Something went wrong, please try again.",
400
- });
401
- expect(checkBotIdMock).toHaveBeenCalledTimes(1);
402
- expect(mockSubmit).not.toHaveBeenCalled();
403
- });
404
-
405
- it("a check that fails is unavailable, and nothing is sent", async () => {
406
- checkBotIdMock.mockRejectedValue(new Error("boom"));
407
- expect(await captureLeadAction(JOB, null, form(VALID))).toStrictEqual({ kind: "unavailable" });
408
- expect(mockSubmit).not.toHaveBeenCalled();
409
- });
410
-
411
- it("a human sends exactly what the check off sends", async () => {
412
- checkBotIdMock.mockResolvedValue(HUMAN);
413
- delete process.env.VERCEL;
414
- await captureLeadAction(JOB, null, form(VALID));
415
- process.env.VERCEL = "1";
416
- expect(await captureLeadAction(JOB, null, form(VALID))).toEqual({ kind: "success" });
417
- expect(checkBotIdMock).toHaveBeenCalledTimes(1);
418
- expect(mockSubmit).toHaveBeenCalledTimes(2);
419
- expect(mockSubmit.mock.calls[1]).toEqual(mockSubmit.mock.calls[0]);
420
- });
421
-
422
- it("a filled honeypot answers success with no check", async () => {
423
- checkBotIdMock.mockResolvedValue(BOT);
424
- expect(await captureLeadAction(JOB, null, form({ ...VALID, ailk_hp: "spam" }))).toEqual({
425
- kind: "success",
426
- });
427
- expect(checkBotIdMock).not.toHaveBeenCalled();
428
- });
429
-
430
- it("a post without consent answers the consent error with no check", async () => {
431
- checkBotIdMock.mockResolvedValue(BOT);
432
- const { consent: _consent, ...unticked } = VALID;
433
- expect(await captureLeadAction(JOB, null, form(unticked))).toEqual({
434
- kind: "error",
435
- fieldErrors: { consent: expect.any(String) },
436
- });
437
- expect(checkBotIdMock).not.toHaveBeenCalled();
438
- });
439
- });
440
-
441
- describe("captureLeadAction records the posting's named flow (#10054 D6, AC-7)", () => {
442
- const ENV_KEYS = ["VERCEL", "AILK_BOT_CHECK"] as const;
443
- const prior = new Map(ENV_KEYS.map((name) => [name, process.env[name]]));
444
- beforeEach(() => {
445
- process.env.VERCEL = "1";
446
- process.env.AILK_BOT_CHECK = "off";
447
- });
448
- afterEach(() => {
449
- for (const [name, value] of prior) {
450
- if (value === undefined) delete process.env[name];
451
- else process.env[name] = value;
452
- }
453
- });
454
-
455
- const NAMED = { job: "writer", flow: "writer-application" };
456
-
457
- it("writes applicationFlow beside job, keeping the Job application source and consent", async () => {
458
- expect(await captureLeadAction(NAMED, null, form(VALID))).toEqual({ kind: "success" });
459
- const body = submitted();
460
- expect(body.source).toBe("flow:job-application");
461
- expect(body.consent).toBe(true);
462
- expect(body.payload).toEqual({
463
- name: "Ada Lovelace",
464
- first_name: "Ada",
465
- last_name: "Lovelace",
466
- job: "writer",
467
- applicationFlow: "writer-application",
468
- page: "careers",
469
- });
470
- });
471
-
472
- it("a form field named applicationFlow does not override it", async () => {
473
- await captureLeadAction(NAMED, null, form({ ...VALID, applicationFlow: "other-flow" }));
474
- expect(submitted().payload["applicationFlow"]).toBe("writer-application");
475
- });
476
-
477
- it("a string posting writes no applicationFlow, even from a form field", async () => {
478
- await captureLeadAction(JOB, null, form({ ...VALID, applicationFlow: "other-flow" }));
479
- expect(submitted().payload).not.toHaveProperty("applicationFlow");
480
- });
481
-
482
- it.each([
483
- [{ job: "writer", flow: "Bad Flow" }],
484
- [{ job: "Bad", flow: "x" }],
485
- [{ job: "writer", flow: "a".repeat(60) }],
486
- [{ job: "writer" }],
487
- ])("%p answers the generic error with nothing sent", async (posting) => {
488
- const result = await captureLeadAction(
489
- // eslint-disable-next-line no-restricted-syntax -- a malformed bound posting is exactly a value of the wrong shape
490
- posting as unknown as { job: string; flow: string },
491
- null,
492
- form(VALID),
493
- );
494
- expect(result).toMatchObject({ kind: "error", message: expect.any(String) });
495
- expect(mockSubmit).not.toHaveBeenCalled();
496
- });
497
- });
@@ -1,172 +0,0 @@
1
- /**
2
- * /careers in sections mode (#8849 D10, AC-4): one generated `items` section
3
- * from the JobPosting records, first, searchable and filterable by employment
4
- * type and location, the facets read from the postings' first-class
5
- * frontmatter fields.
6
- *
7
- * `renderPage` is spied on, so each case reads the input the page hands it and
8
- * resolves the sections through the page's own `getPageSections`.
9
- */
10
- import React from "react";
11
- import { render, screen } from "@testing-library/react";
12
- import * as pageRenderer from "@working-theory/page-renderer";
13
-
14
- jest.mock("next/navigation", () => ({
15
- __esModule: true,
16
- notFound: jest.fn(() => {
17
- throw new Error("NEXT_NOT_FOUND");
18
- }),
19
- }));
20
-
21
- jest.mock("next-mdx-remote/rsc", () => ({
22
- __esModule: true,
23
- MDXRemote: ({ source }: { source: string }) =>
24
- React.createElement("div", { "data-testid": "mdx-rendered" }, source),
25
- }));
26
-
27
- import CareersPage from "../page";
28
-
29
- type Input = Parameters<typeof pageRenderer.renderPage>[0];
30
- type Section = Awaited<ReturnType<typeof pageRenderer.getPageSections>>[number];
31
- type GetMdxSource = typeof pageRenderer.getMdxSource;
32
- type Source = NonNullable<Awaited<ReturnType<GetMdxSource>>>;
33
- type Frontmatter = Source["frontmatter"];
34
-
35
- const SEED: Source = {
36
- frontmatter: {
37
- type: "CareersList",
38
- slug: "careers",
39
- title: "Careers",
40
- description: "Open roles.",
41
- },
42
- body: "",
43
- };
44
-
45
- const HOW_WE_WORK: Section = {
46
- type: "content-block",
47
- id: "how-we-work",
48
- data: { headline: "How we work", body: "Async." },
49
- };
50
-
51
- const POSTINGS: Record<string, Frontmatter> = {
52
- writer: {
53
- type: "JobPosting",
54
- slug: "writer",
55
- title: "Writer",
56
- description: "Write for us.",
57
- employmentType: "FULL_TIME",
58
- remote: true,
59
- location: "Remote (US)",
60
- publishedAt: "2026-10-01",
61
- },
62
- editor: {
63
- type: "JobPosting",
64
- slug: "editor",
65
- title: "Editor",
66
- description: "Edit for us.",
67
- employmentType: "PART_TIME",
68
- location: "Austin, TX",
69
- publishedAt: "2026-09-01",
70
- },
71
- };
72
-
73
- function sourceFor(postings: Record<string, Frontmatter>) {
74
- return jest.fn<ReturnType<GetMdxSource>, Parameters<GetMdxSource>>(
75
- async (type, slug) => {
76
- if (type === "CareersList") return SEED;
77
- const frontmatter = postings[slug];
78
- return frontmatter ? { frontmatter, body: "" } : null;
79
- },
80
- );
81
- }
82
-
83
- /** Render /careers and return renderPage's input and its resolved sections. */
84
- async function renderHub(
85
- slugs: string[],
86
- postings: Record<string, Frontmatter> = POSTINGS,
87
- ): Promise<{ input: Input; sections: Section[] }> {
88
- const spy = jest.spyOn(pageRenderer, "renderPage");
89
- await CareersPage({
90
- params: Promise.resolve({ locale: "en" }),
91
- getMdxSource: sourceFor(postings),
92
- getMdxSlugs: jest.fn().mockResolvedValue(slugs),
93
- getPageSections: jest.fn().mockResolvedValue([HOW_WE_WORK]),
94
- });
95
- const input = spy.mock.calls[0]![0];
96
- spy.mockRestore();
97
- const sections = await input.getPageSections!(SEED.frontmatter);
98
- return { input, sections };
99
- }
100
-
101
- /** The generated section's data, narrowed to the `items` shape. */
102
- function generated(sections: Section[]) {
103
- const first = sections[0]!;
104
- if (first.type !== "items") throw new Error(`expected items, got ${first.type}`);
105
- return first.data;
106
- }
107
-
108
- describe("/careers renders the generated, filterable grid (#8849 D10, AC-4)", () => {
109
- it("renders in sections mode, the generated section first", async () => {
110
- const { input, sections } = await renderHub(["editor", "writer"]);
111
- expect(input.bodyMode).toBeUndefined();
112
- expect(input.translationsNamespace).toBe("careers");
113
- expect(sections.map((section) => section.id)).toEqual([
114
- "open-positions",
115
- "how-we-work",
116
- ]);
117
- expect(sections[0]!.type).toBe("items");
118
- });
119
-
120
- it("builds one card per posting, newest first, with the facets from the frontmatter", async () => {
121
- const { sections } = await renderHub(["editor", "writer"]);
122
- const data = generated(sections);
123
- expect(data.items.map((item) => item.title)).toEqual(["Writer", "Editor"]);
124
- expect(data.items.map((item) => item.eyebrow)).toEqual([
125
- "Full-time · Remote (US)",
126
- "Part-time · Austin, TX",
127
- ]);
128
- expect(data.items.map((item) => item.link?.href)).toEqual([
129
- "/careers/writer",
130
- "/careers/editor",
131
- ]);
132
- expect(data.items.map((item) => item.facets)).toEqual([
133
- { type: "Full-time", location: "Remote (US)" },
134
- { type: "Part-time", location: "Austin, TX" },
135
- ]);
136
- expect(data.filter?.facets?.map((facet) => facet.key)).toEqual([
137
- "type",
138
- "location",
139
- ]);
140
- expect(data.filter?.countText.other).toBe("{count} open positions");
141
- });
142
-
143
- it("reads no facet from schema.mainEntity", async () => {
144
- const { sections } = await renderHub(["override"], {
145
- override: {
146
- type: "JobPosting",
147
- slug: "override",
148
- title: "Override",
149
- description: "Typed only in the override.",
150
- schema: { mainEntity: { employmentType: "FULL_TIME" } },
151
- },
152
- });
153
- const item = generated(sections).items[0]!;
154
- expect(item.facets).toBeUndefined();
155
- expect(item.eyebrow).toBeUndefined();
156
- });
157
-
158
- it("with no postings, renders the declared sections alone", async () => {
159
- const { sections } = await renderHub([]);
160
- expect(sections.map((section) => section.id)).toEqual(["how-we-work"]);
161
- });
162
-
163
- it("with no seed, renders the careers empty state", async () => {
164
- const element = await CareersPage({
165
- params: Promise.resolve({ locale: "en" }),
166
- getMdxSource: jest.fn().mockResolvedValue(null),
167
- getMdxSlugs: jest.fn().mockResolvedValue(["writer"]),
168
- });
169
- render(element);
170
- expect(screen.getByTestId("section-empty-state")).toBeTruthy();
171
- });
172
- });