create-ailk 0.37.1 → 0.38.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 (230) hide show
  1. package/README.md +129 -0
  2. package/component-catalog.json +44 -6
  3. package/component-catalog.md +6 -5
  4. package/dist/add-module.js +16 -1
  5. package/dist/add-route.d.ts +2 -2
  6. package/dist/add-route.js +18 -11
  7. package/dist/cli.js +52 -0
  8. package/dist/declined-routes.d.ts +13 -0
  9. package/dist/declined-routes.js +74 -0
  10. package/dist/derive-architecture.d.ts +0 -6
  11. package/dist/derive-architecture.js +9 -15
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +3 -0
  14. package/dist/language-import.d.ts +93 -0
  15. package/dist/language-import.js +270 -43
  16. package/dist/lib/import-mdx.js +1 -1
  17. package/dist/lib/scaffold-render-sweep.d.ts +6 -3
  18. package/dist/lib/scaffold-render-sweep.js +8 -4
  19. package/dist/migrate-content.d.ts +6 -2
  20. package/dist/migrate-content.js +62 -5
  21. package/dist/module-architecture.js +139 -103
  22. package/dist/paid-sections.d.ts +13 -0
  23. package/dist/paid-sections.js +35 -5
  24. package/dist/programmatic.js +6 -16
  25. package/dist/remove-module.js +67 -0
  26. package/dist/routes.d.ts +103 -0
  27. package/dist/routes.js +708 -0
  28. package/dist/site-manifest.js +1 -1
  29. package/dist/site-roster.d.ts +2 -1
  30. package/dist/site-roster.js +30 -8
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +18 -0
  34. package/dist/surfaces.js +47 -282
  35. package/dist/sync-routes.d.ts +14 -1
  36. package/dist/sync-routes.js +86 -5
  37. package/dist/topology.d.ts +15 -1
  38. package/dist/topology.js +20 -4
  39. package/dist/update.d.ts +17 -2
  40. package/dist/update.js +480 -77
  41. package/package.json +3 -3
  42. package/templates/README.md +1 -1
  43. package/templates/apps/mcp/CLAUDE.md +5 -3
  44. package/templates/apps/web/CLAUDE.md +62 -20
  45. package/templates/apps/web/account.config.tsx +101 -0
  46. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
  47. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
  50. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
  52. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  53. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
  54. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
  55. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
  57. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
  58. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
  59. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
  60. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
  61. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
  62. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
  63. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
  64. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
  65. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
  66. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
  67. package/templates/apps/web/app/[locale]/layout.tsx +45 -28
  68. package/templates/apps/web/app/apple-icon.tsx +72 -0
  69. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  70. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  71. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  72. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  73. package/templates/apps/web/app/og/route.tsx +155 -72
  74. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  75. package/templates/apps/web/i18n/request.ts +44 -1
  76. package/templates/apps/web/jest.config.cjs +13 -1
  77. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  78. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
  79. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  80. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  81. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  82. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  83. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  84. package/templates/apps/web/lib/listings.tsx +2 -2
  85. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  86. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  87. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  88. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  89. package/templates/apps/web/lib/served-pages.ts +95 -0
  90. package/templates/apps/web/lib/site-brand.tsx +3 -5
  91. package/templates/apps/web/messages/en.json +8 -684
  92. package/templates/apps/web/middleware.ts +3 -1
  93. package/templates/apps/web/next.config.mjs +27 -0
  94. package/templates/apps/web/package.json +1 -0
  95. package/templates/customizations.yaml +9 -0
  96. package/templates/package.json +3 -1
  97. package/templates/tools/lint-architecture.ts +164 -11
  98. package/versions.json +48 -47
  99. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  100. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  101. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  102. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  103. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  104. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  105. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  106. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  107. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  119. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  120. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  121. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  122. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  123. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  125. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  126. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  127. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  128. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  134. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  135. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  136. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  137. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  138. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  139. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  140. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  141. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  142. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  143. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  144. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  145. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  146. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  147. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  148. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  149. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  150. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  151. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  152. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  153. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  154. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  155. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  156. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  157. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  158. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  159. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  160. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  161. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  162. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  163. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  164. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  165. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  166. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  167. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  168. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  169. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  170. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  171. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  172. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  173. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  174. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  175. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  176. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  177. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  178. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  179. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  180. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  181. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  182. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  183. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  184. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  185. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  186. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  187. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  188. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  189. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  190. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  191. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  192. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  193. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  194. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  195. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  196. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  197. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  198. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  199. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  200. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  201. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  202. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  203. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  204. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  205. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  206. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  207. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  208. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  209. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  210. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  211. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  212. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  213. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  214. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  215. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  216. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  217. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  218. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  219. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  220. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  221. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  222. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  223. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  224. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  225. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  226. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  227. package/templates/apps/web/lib/account-config.ts +0 -678
  228. package/templates/apps/web/lib/checkout-config.ts +0 -16
  229. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  230. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,418 +0,0 @@
1
- /**
2
- * Tests for the New menu's popups (#8233, spec
3
- * docs/specs/8233-member-new-menu-the-new-spec.md D5–D10; AC-3, AC-4, AC-5).
4
- *
5
- * The Inbox page renders with every action offered; each case opens a popup
6
- * through the menu, so the popup runs its real server action
7
- * (`new-actions.ts`) against the mocked member reads and writes.
8
- *
9
- * Covers:
10
- * 1. Request quote renders the request-quote magnet's CURRENT steps, read
11
- * on each open — a step the provider adds shows on the next open — and
12
- * posts the typed answers, a blank optional one omitted (AC-3). #11155:
13
- * the date and the budget band are required (the browser refuses a
14
- * submit without them, so nothing is posted), the date is a date input
15
- * floored at today, the link's https refusal shows inline under it.
16
- * 2. Send message (#11152) is a link to the member thread page,
17
- * /account/inbox/thread — the lightbox is retired; the thread's
18
- * composer posts through the same write (`thread.test.tsx`). Schedule
19
- * appointment (#11154) is a link to /account/appointments: the schedule
20
- * popup is retired, so one booking path remains — the member's booking
21
- * page.
22
- * 3. A refusal shows a plain message, keeps every typed value and leaves
23
- * the popup open (AC-5).
24
- * 4. No popup asks for a name or an email.
25
- */
26
- import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
27
-
28
- jest.mock("next-intl/server", () => {
29
- const msgs: unknown = require("../../../../../messages/en.json");
30
- const dig = (obj: unknown, path: string): unknown =>
31
- path.split(".").reduce<unknown>(
32
- (acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
33
- obj,
34
- );
35
- return {
36
- __esModule: true,
37
- getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
38
- const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
39
- const messages = dig(msgs, ns);
40
- return (key: string, values?: Record<string, unknown>): string => {
41
- const value = dig(messages, key);
42
- if (typeof value !== "string") return `${ns}.${key}`;
43
- return value.replace(/\{(\w+)\}/g, (m, name: string) =>
44
- values && name in values ? String(values[name]) : m,
45
- );
46
- };
47
- },
48
- };
49
- });
50
-
51
- jest.mock("next/headers", () => ({
52
- __esModule: true,
53
- headers: jest.fn().mockResolvedValue(new Headers()),
54
- cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
55
- }));
56
-
57
- const mockGetSession = jest.fn();
58
- // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test of the session fields can mock without standing up Prisma.
59
- jest.mock("../../../../../auth", () => ({
60
- __esModule: true,
61
- auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
62
- }));
63
-
64
- const mockNotFound = jest.fn();
65
- const mockMemberMessages = jest.fn();
66
- const mockMemberMeetingTypes = jest.fn();
67
- const mockMemberRequestForm = jest.fn();
68
- const mockMemberRequestQuote = jest.fn();
69
- jest.mock("@working-theory/api-client", () => ({
70
- __esModule: true,
71
- // #8765 D7 — no agreement outstanding, so the Inbox loads.
72
- consent: {
73
- accountAgreements: () =>
74
- Promise.resolve({ ok: true, body: { agreements: [], complete: true } }),
75
- },
76
- waitlistSignups: { me: jest.fn() },
77
- subscription: { me: (...args: unknown[]) => mockNotFound(...args) },
78
- member: {
79
- pieces: (...args: unknown[]) => mockNotFound(...args),
80
- purchases: (...args: unknown[]) => mockNotFound(...args),
81
- appointments: (...args: unknown[]) => mockNotFound(...args),
82
- welcome: (...args: unknown[]) => mockNotFound(...args),
83
- messages: (...args: unknown[]) => mockMemberMessages(...args),
84
- meetingTypes: (...args: unknown[]) => mockMemberMeetingTypes(...args),
85
- requestForm: (...args: unknown[]) => mockMemberRequestForm(...args),
86
- requestQuote: (...args: unknown[]) => mockMemberRequestQuote(...args),
87
- },
88
- }));
89
-
90
- const mockPush = jest.fn();
91
- const mockRefresh = jest.fn();
92
- jest.mock("next/navigation", () => ({
93
- __esModule: true,
94
- useRouter: () => ({ push: mockPush, refresh: mockRefresh }),
95
- usePathname: () => "/account",
96
- useSearchParams: () => new URLSearchParams(),
97
- }));
98
-
99
- import { PhoneTabProvider } from "@working-theory/templates/account";
100
- import { toIsoDate } from "@working-theory/ui/primitives";
101
- import { requestQuoteFlowConfig } from "@working-theory/validation";
102
-
103
- import Page from "../page";
104
-
105
- const SESSION = {
106
- user: {
107
- id: "user_1",
108
- name: "Ada",
109
- email: "ada@example.com",
110
- emailVerified: true,
111
- createdAt: new Date("2026-09-01T00:00:00.000Z"),
112
- },
113
- };
114
-
115
- /** The cookie a single site forwards (`forwardedCookieInit()`). */
116
- const INIT = { headers: { cookie: "session=abc" } };
117
-
118
- const notFound = {
119
- ok: false,
120
- status: 404,
121
- body: { ok: false, error: { code: "not_found", message: "Not found" } },
122
- };
123
- const refusal = (status: number, code: string) => ({
124
- ok: false,
125
- status,
126
- body: { ok: false, error: { code, message: "x" } },
127
- });
128
- const ok = <T,>(body: T) => ({ ok: true, body });
129
-
130
- const TYPES = [
131
- { slug: "consult", title: "Consultation", durationMinutes: 30 },
132
- { slug: "review", title: "Design review", durationMinutes: 60 },
133
- ];
134
-
135
- const FORM = {
136
- form: { title: "Request a quote", defaultLocale: "en", steps: requestQuoteFlowConfig.steps },
137
- };
138
- const FORM_PLUS_STEP = {
139
- form: {
140
- ...FORM.form,
141
- steps: [
142
- ...requestQuoteFlowConfig.steps,
143
- {
144
- key: "extra",
145
- type: "field",
146
- copy: { title: { en: "A little more" } },
147
- fields: [{ name: "deadline", inputType: "text", copy: { label: { en: "Deadline" } } }],
148
- },
149
- ],
150
- },
151
- };
152
-
153
- const RECEIPT = ok({ id: "intx_1", createdAt: "2026-10-11T10:00:00.000Z" });
154
-
155
- beforeAll(() => {
156
- if (typeof globalThis.PointerEvent === "undefined") {
157
- // eslint-disable-next-line no-restricted-syntax -- a MouseEvent stands in for jsdom's missing PointerEvent
158
- globalThis.PointerEvent = MouseEvent as unknown as typeof PointerEvent;
159
- }
160
- });
161
-
162
- beforeEach(() => {
163
- window.localStorage.clear();
164
- mockPush.mockReset();
165
- mockRefresh.mockReset();
166
- mockGetSession.mockReset().mockResolvedValue(SESSION);
167
- mockNotFound.mockReset().mockResolvedValue(notFound);
168
- mockMemberMessages.mockReset().mockResolvedValue(ok({ items: [] }));
169
- mockMemberMeetingTypes.mockReset().mockResolvedValue(ok({ items: TYPES }));
170
- mockMemberRequestForm.mockReset().mockResolvedValue(ok(FORM));
171
- mockMemberRequestQuote.mockReset().mockResolvedValue(RECEIPT);
172
- });
173
-
174
- async function renderInbox(): Promise<void> {
175
- const element = await Page({ params: Promise.resolve({ locale: "en" }) });
176
- render(<PhoneTabProvider tab="inbox">{element}</PhoneTabProvider>);
177
- }
178
-
179
- /** Opens one New action's popup and returns it. */
180
- async function openPopup(label: string): Promise<HTMLElement> {
181
- fireEvent.pointerDown(screen.getByTestId("account-new-menu-trigger"), {
182
- button: 0,
183
- ctrlKey: false,
184
- pointerType: "mouse",
185
- });
186
- fireEvent.click(screen.getByRole("menuitem", { name: label }));
187
- return screen.findByTestId("account-new-popup");
188
- }
189
-
190
- async function closePopup(popup: HTMLElement): Promise<void> {
191
- fireEvent.click(within(popup).getByRole("button", { name: "Close" }));
192
- await waitFor(() => expect(screen.queryByTestId("account-new-popup")).not.toBeInTheDocument());
193
- }
194
-
195
- function type(control: HTMLElement, value: string): void {
196
- fireEvent.change(control, { target: { value } });
197
- }
198
-
199
- /** A future ISO date the server's "not before today" rule accepts. */
200
- const FUTURE_DATE = "2999-01-01";
201
-
202
- /** Today as the member's own `YYYY-MM-DD` — the date input's `min`. */
203
- const localToday = (): string => toIsoDate(new Date());
204
-
205
- /** Picks a band through the Select's native mirror (Radix bubbles a change on it back into the value). */
206
- function pickBudget(popup: HTMLElement, value: string): void {
207
- const native = popup.querySelector('select[name="answer.budget"]');
208
- if (!(native instanceof HTMLSelectElement)) throw new Error("no budget select");
209
- fireEvent.change(native, { target: { value } });
210
- }
211
-
212
- /** Fills the three required default answers. */
213
- async function fillRequired(popup: HTMLElement): Promise<void> {
214
- type(await within(popup).findByLabelText("What do you need?"), "A logo");
215
- type(within(popup).getByLabelText("When do you need it?"), FUTURE_DATE);
216
- pickBudget(popup, "1k-5k");
217
- }
218
-
219
- function expectNoIdentityFields(popup: HTMLElement): void {
220
- expect(within(popup).queryAllByLabelText(/name|e-?mail/i)).toEqual([]);
221
- expect(popup.querySelector('input[type="email"]')).toBeNull();
222
- }
223
-
224
- // ── Request quote ────────────────────────────────────────────────────────────
225
-
226
- describe("Request quote — the magnet's current steps, read on each open (AC-3)", () => {
227
- it("renders the four default fields — need, a date and a budget band required, the link optional — and no identity field (#11155)", async () => {
228
- await renderInbox();
229
- const popup = await openPopup("Request quote");
230
- await within(popup).findByLabelText("What do you need?");
231
- // Two text boxes: the need and the link. The date and the band are their own controls.
232
- expect(within(popup).getAllByRole("textbox")).toHaveLength(2);
233
- expect(within(popup).getByLabelText("What do you need?")).toBeRequired();
234
-
235
- const timing = within(popup).getByLabelText("When do you need it?");
236
- expect(timing).toHaveAttribute("type", "date");
237
- expect(timing).toBeRequired();
238
- expect(timing).toHaveAttribute("min", localToday());
239
- expect(within(popup).getByRole("button", { name: "Pick a date" })).toBeInTheDocument();
240
-
241
- expect(within(popup).getByRole("combobox", { name: "Budget range" })).toBeInTheDocument();
242
- const native = popup.querySelector('select[name="answer.budget"]');
243
- expect(native).toBeRequired();
244
- expect(Array.from((native as HTMLSelectElement).options).map((o) => o.value).filter(Boolean)).toEqual([
245
- "under-1k",
246
- "1k-5k",
247
- "5k-10k",
248
- "10k-25k",
249
- "25k-plus",
250
- ]);
251
-
252
- const link = within(popup).getByLabelText("Reference folder or document");
253
- expect(link).not.toBeRequired();
254
- expect(link).toHaveAttribute("placeholder", "https://");
255
- expect(within(popup).queryByText("A rough range is fine.")).toBeNull();
256
- expect(within(popup).queryByText(/Must start with https/)).toBeNull();
257
- expectNoIdentityFields(popup);
258
- });
259
-
260
- it("posts nothing while the required date or budget is blank: the browser refuses the submit (#11155)", async () => {
261
- await renderInbox();
262
- const popup = await openPopup("Request quote");
263
- type(await within(popup).findByLabelText("What do you need?"), "A logo");
264
- fireEvent.click(within(popup).getByTestId("new-quote-submit"));
265
- expect(within(popup).getByLabelText("When do you need it?")).toBeInvalid();
266
- expect(popup.querySelector('select[name="answer.budget"]')).toBeInvalid();
267
-
268
- type(within(popup).getByLabelText("When do you need it?"), FUTURE_DATE);
269
- fireEvent.click(within(popup).getByTestId("new-quote-submit"));
270
- expect(within(popup).getByLabelText("When do you need it?")).toBeValid();
271
- expect(popup.querySelector('select[name="answer.budget"]')).toBeInvalid();
272
-
273
- await new Promise((resolve) => setTimeout(resolve, 20));
274
- expect(mockMemberRequestQuote).not.toHaveBeenCalled();
275
- expect(screen.getByTestId("account-new-popup")).toBeInTheDocument();
276
- expect(within(popup).getByLabelText("What do you need?")).toHaveValue("A logo");
277
- });
278
-
279
- it("a date before today is refused by the server as answers_invalid; the message shows and every answer is kept (#11155)", async () => {
280
- mockMemberRequestQuote.mockResolvedValue(refusal(400, "answers_invalid"));
281
- await renderInbox();
282
- const popup = await openPopup("Request quote");
283
- await fillRequired(popup);
284
- // The input's own floor is bypassed the way a stale tab or a hand-built post would.
285
- const timing = within(popup).getByLabelText("When do you need it?");
286
- timing.removeAttribute("min");
287
- type(timing, "2000-01-01");
288
- fireEvent.click(within(popup).getByTestId("new-quote-submit"));
289
- expect(
290
- await within(popup).findByText("Some answers do not fit this form. Check them and try again."),
291
- ).toBeInTheDocument();
292
- expect(mockMemberRequestQuote).toHaveBeenCalledWith(
293
- { answers: { need: "A logo", timing: "2000-01-01", budget: "1k-5k" } },
294
- INIT,
295
- );
296
- expect(within(popup).getByLabelText("When do you need it?")).toHaveValue("2000-01-01");
297
- expect(within(popup).getByLabelText("What do you need?")).toHaveValue("A logo");
298
- expect(screen.getByTestId("account-new-popup")).toBeInTheDocument();
299
- });
300
-
301
- it("shows a step the provider added on the next open, with no page re-render", async () => {
302
- await renderInbox();
303
- let popup = await openPopup("Request quote");
304
- await within(popup).findByLabelText("What do you need?");
305
- expect(within(popup).queryByLabelText("Deadline")).not.toBeInTheDocument();
306
- await closePopup(popup);
307
-
308
- mockMemberRequestForm.mockResolvedValue(ok(FORM_PLUS_STEP));
309
- popup = await openPopup("Request quote");
310
- expect(await within(popup).findByLabelText("Deadline")).toBeInTheDocument();
311
- expect(within(popup).getAllByRole("textbox")).toHaveLength(3);
312
- });
313
-
314
- it("posts the typed answers through member.requestQuote, a blank optional answer omitted", async () => {
315
- await renderInbox();
316
- const popup = await openPopup("Request quote");
317
- await fillRequired(popup);
318
- fireEvent.click(within(popup).getByTestId("new-quote-submit"));
319
- await waitFor(() => expect(mockMemberRequestQuote).toHaveBeenCalledTimes(1));
320
- expect(mockMemberRequestQuote).toHaveBeenCalledWith(
321
- { answers: { need: "A logo", timing: FUTURE_DATE, budget: "1k-5k" } },
322
- INIT,
323
- );
324
- await waitFor(() => expect(screen.queryByTestId("account-new-popup")).not.toBeInTheDocument());
325
- expect(mockRefresh).toHaveBeenCalledTimes(1);
326
- });
327
-
328
- it("with the form switched off since the menu loaded, says Requests are off", async () => {
329
- await renderInbox();
330
- mockMemberRequestForm.mockResolvedValue(ok({ form: null }));
331
- const popup = await openPopup("Request quote");
332
- expect(await within(popup).findByText("Requests are switched off right now.")).toBeInTheDocument();
333
- expect(within(popup).queryAllByRole("textbox")).toEqual([]);
334
- });
335
-
336
- it("a failed read shows the load error, and Try again reads once more", async () => {
337
- await renderInbox();
338
- mockMemberRequestForm.mockResolvedValue(refusal(500, "failed"));
339
- const popup = await openPopup("Request quote");
340
- expect(await within(popup).findByText("This could not load.")).toBeInTheDocument();
341
- mockMemberRequestForm.mockResolvedValue(ok(FORM));
342
- fireEvent.click(within(popup).getByRole("button", { name: "Try again" }));
343
- expect(await within(popup).findByLabelText("What do you need?")).toBeInTheDocument();
344
- });
345
- });
346
-
347
- // ── Send message ─────────────────────────────────────────────────────────────
348
-
349
- describe("Send message — a link to the member thread page, no lightbox (#11152)", () => {
350
- it("navigates to /account/inbox/thread and opens nothing over the Inbox", async () => {
351
- await renderInbox();
352
- fireEvent.pointerDown(screen.getByTestId("account-new-menu-trigger"), {
353
- button: 0,
354
- ctrlKey: false,
355
- pointerType: "mouse",
356
- });
357
- const row = screen.getByRole("menuitem", { name: "Send message" });
358
- expect(row).toHaveAttribute("data-href", "/account/inbox/thread");
359
- fireEvent.click(row);
360
- expect(mockPush).toHaveBeenCalledWith("/account/inbox/thread");
361
- expect(screen.queryByTestId("account-new-popup")).not.toBeInTheDocument();
362
- expect(screen.queryByTestId("new-message-form")).not.toBeInTheDocument();
363
- });
364
- });
365
-
366
- // ── Schedule appointment ─────────────────────────────────────────────────────
367
-
368
- describe("Schedule appointment — a link to the member's Appointments page, no popup (#11154)", () => {
369
- it("navigates to /account/appointments and opens nothing over the Inbox", async () => {
370
- await renderInbox();
371
- fireEvent.pointerDown(screen.getByTestId("account-new-menu-trigger"), {
372
- button: 0,
373
- ctrlKey: false,
374
- pointerType: "mouse",
375
- });
376
- const row = screen.getByRole("menuitem", { name: "Schedule appointment" });
377
- expect(row).toHaveAttribute("data-href", "/account/appointments");
378
- fireEvent.click(row);
379
- expect(mockPush).toHaveBeenCalledWith("/account/appointments");
380
- expect(screen.queryByTestId("account-new-popup")).not.toBeInTheDocument();
381
- expect(screen.queryByRole("menuitem", { name: /service/i })).not.toBeInTheDocument();
382
- });
383
- });
384
-
385
- // ── Refusals ─────────────────────────────────────────────────────────────────
386
-
387
- describe("a refusal shows a plain message and keeps every typed value (AC-5)", () => {
388
- it("Request quote: a bare-domain link is sent as typed, refused INLINE under the link, and all four answers kept (#11155)", async () => {
389
- mockMemberRequestQuote.mockResolvedValue(refusal(400, "link_not_https"));
390
- await renderInbox();
391
- const popup = await openPopup("Request quote");
392
- await fillRequired(popup);
393
- type(within(popup).getByLabelText("Reference folder or document"), "example.com");
394
- fireEvent.click(within(popup).getByTestId("new-quote-submit"));
395
- const error = await within(popup).findByTestId("new-quote-field-link-error");
396
- expect(error).toHaveTextContent("A link must start with https://.");
397
- expect(error).toHaveAttribute("role", "alert");
398
- const link = within(popup).getByLabelText("Reference folder or document");
399
- expect(link).toHaveAttribute("aria-invalid", "true");
400
- expect(link).toHaveAttribute("aria-describedby", error.id);
401
- // Inline, not the form-level refusal.
402
- expect(within(popup).queryByTestId("new-popup-error")).toBeNull();
403
- expect(mockMemberRequestQuote).toHaveBeenCalledWith(
404
- { answers: { need: "A logo", timing: FUTURE_DATE, budget: "1k-5k", link: "example.com" } },
405
- INIT,
406
- );
407
- const values: Record<string, string> = {
408
- "What do you need?": "A logo",
409
- "When do you need it?": FUTURE_DATE,
410
- "Reference folder or document": "example.com",
411
- };
412
- for (const [label, value] of Object.entries(values)) {
413
- expect(within(popup).getByLabelText(label)).toHaveValue(value);
414
- }
415
- expect(screen.getByTestId("account-new-popup")).toBeInTheDocument();
416
- expect(mockRefresh).not.toHaveBeenCalled();
417
- });
418
- });