create-ailk 0.2.0 → 0.3.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.
- package/component-catalog.md +50 -53
- package/dist/lib/apply-module-patches.d.ts +47 -0
- package/dist/lib/apply-module-patches.js +370 -0
- package/dist/lib/extract-module-bundle.d.ts +12 -3
- package/dist/lib/extract-module-bundle.js +236 -24
- package/dist/lib/fetch-module.d.ts +3 -38
- package/dist/lib/fetch-module.js +26 -8
- package/dist/lib/module-license-gate.d.ts +2 -0
- package/dist/lib/module-license-gate.js +1 -0
- package/dist/lib/paid-paths.d.ts +16 -0
- package/dist/lib/paid-paths.js +90 -0
- package/dist/module-architecture.d.ts +139 -23
- package/dist/module-architecture.js +668 -25
- package/dist/parse-args.d.ts +2 -2
- package/dist/parse-args.js +3 -1
- package/dist/programmatic.d.ts +2 -1
- package/dist/programmatic.js +15 -4
- package/dist/surfaces.d.ts +12 -36
- package/dist/surfaces.js +35 -5
- package/dist/sync-routes.js +31 -1
- package/package.json +2 -2
- package/templates/.claude/agents/web.md +2 -3
- package/templates/.claude/rules/architecture.md +5 -5
- package/templates/.claude/skills/README.md +2 -1
- package/templates/.env.example +21 -9
- package/templates/CONVENTIONS.md +6 -7
- package/templates/apps/api/.env.example +9 -0
- package/templates/apps/api/CLAUDE.md +33 -5
- package/templates/apps/api/package.json +0 -1
- package/templates/apps/api/src/__tests__/cors.test.ts +195 -0
- package/templates/apps/api/src/__tests__/module-exclusion.test.ts +60 -2
- package/templates/apps/api/src/__tests__/vercel-handler.test.ts +159 -0
- package/templates/apps/api/src/config/__tests__/modules.test.ts +76 -0
- package/templates/apps/api/src/config/index.ts +19 -0
- package/templates/apps/api/src/config/modules.ts +12 -14
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +3 -0
- package/templates/apps/api/src/lib/__tests__/slice-load.test.ts +89 -0
- package/templates/apps/api/src/lib/slice-load.ts +90 -0
- package/templates/apps/api/src/openapi/__tests__/openapi.test.ts +52 -32
- package/templates/apps/api/src/openapi/__tests__/spec-identity.test.ts +182 -0
- package/templates/apps/api/src/openapi/__tests__/surface-drift.test.ts +293 -0
- package/templates/apps/api/src/openapi/index.ts +9 -3
- package/templates/apps/api/src/openapi/spec.ts +505 -65
- package/templates/apps/api/src/openapi/surface-drift.ts +195 -0
- package/templates/apps/api/src/routes/content/__tests__/create.test.ts +14 -0
- package/templates/apps/api/src/routes/content/__tests__/delete.test.ts +14 -0
- package/templates/apps/api/src/routes/content/__tests__/update.test.ts +14 -0
- package/templates/apps/api/src/routes/content/index.ts +38 -11
- package/templates/apps/api/src/routes/project-listings/__tests__/configured-application.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/drafts.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/founder-identity.test.ts +796 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/me.test.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/public.test.ts +38 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/resume-email.test.ts +814 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/site-answers.test.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/site-key.test.ts +24 -0
- package/templates/apps/api/src/routes/project-listings/__tests__/structured-address.test.ts +17 -0
- package/templates/apps/api/src/routes/project-listings/index.ts +37 -10
- package/templates/apps/api/src/routes/project-listings/me.ts +10 -0
- package/templates/apps/api/src/routes/project-listings/patch-draft.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/public.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/respond.ts +11 -0
- package/templates/apps/api/src/routes/project-listings/resume-token.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/start.ts +30 -0
- package/templates/apps/api/src/routes/project-listings/submit.ts +5 -0
- package/templates/apps/api/src/routes/project-listings/verify-email.ts +150 -0
- package/templates/apps/api/src/server.ts +459 -135
- package/templates/apps/api/src/services/deliverable-fulfillment.ts +10 -0
- package/templates/apps/api/src/services/listing-config.ts +58 -0
- package/templates/apps/api/src/services/project-listing-resume-email.ts +326 -0
- package/templates/apps/api/src/services/project-listings.ts +229 -4
- package/templates/apps/api/src/vercel-handler.ts +60 -26
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +2 -2
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +21 -0
- package/templates/apps/mcp/__tests__/config/modules.test.ts +78 -0
- package/templates/apps/mcp/__tests__/module-exclusion.test.ts +1 -1
- package/templates/apps/mcp/src/config/modules.ts +14 -13
- package/templates/apps/mcp/src/server.ts +8 -4
- package/templates/apps/mcp/src/tools/index.ts +7 -22
- package/templates/apps/web/.env.example +15 -0
- package/templates/apps/web/app/[locale]/(authed)/{waitlist/__tests__ → __tests__}/gate.test.tsx +4 -4
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +2 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +1 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +1 -0
- package/templates/apps/web/app/llms.txt/route.ts +12 -9
- package/templates/apps/web/jest.config.cjs +14 -13
- package/templates/apps/web/next.config.mjs +1 -3
- package/templates/apps/web/package.json +0 -6
- package/templates/apps/web/public/android-chrome-192x192.png +0 -0
- package/templates/apps/web/public/android-chrome-512x512.png +0 -0
- package/templates/apps/web/public/apple-touch-icon.png +0 -0
- package/templates/apps/web/public/favicon-16x16.png +0 -0
- package/templates/apps/web/public/favicon-32x32.png +0 -0
- package/templates/apps/web/public/favicon.ico +0 -0
- package/templates/apps/web/public/favicon.svg +6 -3
- package/templates/apps/web/public/lockup-horizontal.svg +4 -0
- package/templates/apps/web/public/logomark.svg +4 -0
- package/templates/apps/web/public/site.webmanifest +2 -2
- package/templates/apps/web/public/wordmark.svg +4 -0
- package/templates/database/CHANGELOG.md +33 -0
- package/templates/database/inbox/schema.prisma +67 -0
- package/templates/database/migrations/20260914120000_listing_founder_identity/migration.sql +123 -0
- package/templates/database/package.json +1 -1
- package/templates/package.json +1 -1
- package/templates/.claude/skills/scaffold-commerce/SKILL.md +0 -807
- package/templates/.claude/skills/scaffold-commerce/references/lookup-keys-template.md +0 -71
- package/templates/.claude/skills/scaffold-commerce/references/marketplace-brand-pages.md +0 -83
- package/templates/.claude/skills/scaffold-commerce/templates/checkout-route.template.ts +0 -370
- package/templates/.claude/skills/scaffold-commerce/templates/invoice-route.template.ts +0 -376
- package/templates/.claude/skills/scaffold-commerce/templates/marketplace-cta-route.tsx.tmpl +0 -72
- package/templates/.claude/skills/scaffold-commerce/templates/payment-link-route.template.ts +0 -471
- package/templates/.claude/skills/scaffold-commerce/templates/portal-route.template.ts +0 -365
- package/templates/.claude/skills/scaffold-commerce/templates/stripe-config.template.ts +0 -60
- package/templates/.claude/skills/scaffold-commerce/templates/subscription-route.template.ts +0 -446
- package/templates/apps/api/src/__tests__/server.test.ts +0 -253
- package/templates/apps/api/src/bin/deliverable-resend.ts +0 -144
- package/templates/apps/api/src/bin/deliverable-upload.ts +0 -114
- package/templates/apps/api/src/bin/followup-sweep.ts +0 -44
- package/templates/apps/api/src/bin/listing-csv-sweep.ts +0 -46
- package/templates/apps/api/src/bin/seed-presets.ts +0 -58
- package/templates/apps/api/src/bin/seed-waitlist-experiments.ts +0 -104
- package/templates/apps/api/src/bin/session-retention-sweep.ts +0 -46
- package/templates/apps/api/src/lib/__tests__/stripe.test.ts +0 -74
- package/templates/apps/api/src/lib/stripe.ts +0 -52
- package/templates/apps/api/src/lib/tenant-db.ts +0 -225
- package/templates/apps/api/src/lib/ws-token.ts +0 -91
- package/templates/apps/api/src/middleware/tenant.ts +0 -99
- package/templates/apps/api/src/routes/billing/__tests__/portal.test.ts +0 -450
- package/templates/apps/api/src/routes/billing/__tests__/read.test.ts +0 -262
- package/templates/apps/api/src/routes/billing/__tests__/usage.test.ts +0 -436
- package/templates/apps/api/src/routes/billing/index.ts +0 -36
- package/templates/apps/api/src/routes/billing/portal.ts +0 -182
- package/templates/apps/api/src/routes/billing/read.ts +0 -75
- package/templates/apps/api/src/routes/billing/usage.ts +0 -153
- package/templates/apps/api/src/routes/checkout/__tests__/sessions.test.ts +0 -687
- package/templates/apps/api/src/routes/checkout/index.ts +0 -13
- package/templates/apps/api/src/routes/checkout/sessions.ts +0 -197
- package/templates/apps/api/src/routes/deliverables/__tests__/index.test.ts +0 -393
- package/templates/apps/api/src/routes/deliverables/index.ts +0 -200
- package/templates/apps/api/src/routes/flow-checkouts/__tests__/index.test.ts +0 -443
- package/templates/apps/api/src/routes/flow-checkouts/index.ts +0 -82
- package/templates/apps/api/src/routes/flows/README.md +0 -147
- package/templates/apps/api/src/routes/flows/__tests__/index.test.ts +0 -752
- package/templates/apps/api/src/routes/flows/__tests__/recommender.test.ts +0 -671
- package/templates/apps/api/src/routes/flows/index.ts +0 -202
- package/templates/apps/api/src/routes/flows/recommender.ts +0 -443
- package/templates/apps/api/src/routes/project-listings/__tests__/copy-edit.test.ts +0 -815
- package/templates/apps/api/src/routes/project-listings/__tests__/me-route-precedence.test.ts +0 -221
- package/templates/apps/api/src/routes/project-listings/__tests__/tenant-isolation.test.ts +0 -566
- package/templates/apps/api/src/routes/project-listings/get.ts +0 -70
- package/templates/apps/api/src/routes/project-listings/list.ts +0 -47
- package/templates/apps/api/src/routes/project-listings/patch.ts +0 -136
- package/templates/apps/api/src/routes/schedule/__tests__/index.test.ts +0 -490
- package/templates/apps/api/src/routes/schedule/index.ts +0 -249
- package/templates/apps/api/src/routes/slack/__tests__/actions.test.ts +0 -385
- package/templates/apps/api/src/routes/slack/actions.ts +0 -177
- package/templates/apps/api/src/routes/slack/index.ts +0 -38
- package/templates/apps/api/src/routes/waitlist-experiments/__tests__/tenant-isolation.test.ts +0 -577
- package/templates/apps/api/src/routes/waitlist-experiments/comparison.ts +0 -78
- package/templates/apps/api/src/routes/waitlist-experiments/index.ts +0 -41
- package/templates/apps/api/src/routes/waitlist-experiments/list.ts +0 -64
- package/templates/apps/api/src/routes/waitlist-experiments/respond.ts +0 -42
- package/templates/apps/api/src/routes/waitlist-experiments/signup.ts +0 -84
- package/templates/apps/api/src/routes/waitlist-experiments/signups.ts +0 -119
- package/templates/apps/api/src/routes/waitlist-signups/__tests__/index.test.ts +0 -238
- package/templates/apps/api/src/routes/waitlist-signups/index.ts +0 -101
- package/templates/apps/api/src/routes/webhooks/README.md +0 -80
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-flow-checkout.test.ts +0 -315
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-idempotency.test.ts +0 -247
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-org-billing.test.ts +0 -270
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-rate-limit.test.ts +0 -198
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe.test.ts +0 -633
- package/templates/apps/api/src/routes/webhooks/index.ts +0 -41
- package/templates/apps/api/src/routes/webhooks/stripe.ts +0 -481
- package/templates/apps/api/src/routes/workspaces/__tests__/config-tenant-isolation.test.ts +0 -356
- package/templates/apps/api/src/routes/workspaces/__tests__/tenant-isolation.test.ts +0 -671
- package/templates/apps/api/src/routes/workspaces/config.ts +0 -125
- package/templates/apps/api/src/routes/workspaces/index.ts +0 -194
- package/templates/apps/api/src/routes/workspaces/sessions.ts +0 -218
- package/templates/apps/api/src/services/__tests__/flow-aggregate.test.ts +0 -425
- package/templates/apps/api/src/services/__tests__/flow-engine.test.ts +0 -2840
- package/templates/apps/api/src/services/__tests__/lead-promotion.test.ts +0 -393
- package/templates/apps/api/src/services/__tests__/listing-csv-sweep.test.ts +0 -560
- package/templates/apps/api/src/services/__tests__/listing-promotion.test.ts +0 -684
- package/templates/apps/api/src/services/__tests__/playbook-compile.test.ts +0 -406
- package/templates/apps/api/src/services/__tests__/playbook-render.test.ts +0 -290
- package/templates/apps/api/src/services/__tests__/project-listing-decision.test.ts +0 -736
- package/templates/apps/api/src/services/__tests__/project-listing-flow.test.ts +0 -475
- package/templates/apps/api/src/services/__tests__/project-listing-issue.test.ts +0 -340
- package/templates/apps/api/src/services/__tests__/recommender-capture.test.ts +0 -983
- package/templates/apps/api/src/services/__tests__/tenant-context-cascade.test.ts +0 -71
- package/templates/apps/api/src/services/__tests__/tenant-context.test.ts +0 -379
- package/templates/apps/api/src/services/__tests__/usage-metering.test.ts +0 -768
- package/templates/apps/api/src/services/__tests__/waitlist-dashboard.test.ts +0 -1314
- package/templates/apps/api/src/services/__tests__/waitlist-experiments.test.ts +0 -341
- package/templates/apps/api/src/services/__tests__/waitlist-followup.test.ts +0 -567
- package/templates/apps/api/src/services/__tests__/waitlist-scoring.test.ts +0 -474
- package/templates/apps/api/src/services/__tests__/waitlist-signups.test.ts +0 -354
- package/templates/apps/api/src/services/flow-aggregate.ts +0 -232
- package/templates/apps/api/src/services/flow-checkouts.ts +0 -123
- package/templates/apps/api/src/services/flow-engine.ts +0 -1296
- package/templates/apps/api/src/services/lead-promotion.ts +0 -176
- package/templates/apps/api/src/services/listing-csv-sweep.ts +0 -455
- package/templates/apps/api/src/services/listing-promotion.ts +0 -342
- package/templates/apps/api/src/services/playbook-compile.ts +0 -398
- package/templates/apps/api/src/services/playbook-render.ts +0 -263
- package/templates/apps/api/src/services/project-listing-decision.ts +0 -510
- package/templates/apps/api/src/services/project-listing-flow.ts +0 -426
- package/templates/apps/api/src/services/project-listing-issue.ts +0 -251
- package/templates/apps/api/src/services/recommender-capture.ts +0 -835
- package/templates/apps/api/src/services/scheduling/cal-provider.ts +0 -392
- package/templates/apps/api/src/services/scheduling/index.ts +0 -63
- package/templates/apps/api/src/services/scheduling/types.ts +0 -88
- package/templates/apps/api/src/services/tenant-context.ts +0 -451
- package/templates/apps/api/src/services/usage-metering.ts +0 -699
- package/templates/apps/api/src/services/waitlist-dashboard.ts +0 -947
- package/templates/apps/api/src/services/waitlist-experiments.ts +0 -213
- package/templates/apps/api/src/services/waitlist-followup.ts +0 -486
- package/templates/apps/api/src/services/waitlist-scoring.ts +0 -166
- package/templates/apps/api/src/services/waitlist-signups.ts +0 -165
- package/templates/apps/mcp/__tests__/schedule_tools.test.ts +0 -242
- package/templates/apps/mcp/src/tools/create_booking.ts +0 -58
- package/templates/apps/mcp/src/tools/get_event_meta.ts +0 -55
- package/templates/apps/mcp/src/tools/get_flow.ts +0 -61
- package/templates/apps/mcp/src/tools/list_availability.ts +0 -67
- package/templates/apps/mcp/src/tools/submit_flow_step.ts +0 -83
- package/templates/apps/web/app/[locale]/(authed)/waitlist/[experimentId]/page.tsx +0 -309
- package/templates/apps/web/app/[locale]/(authed)/waitlist/[experimentId]/signups/[leadId]/page.tsx +0 -149
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/comparison.test.tsx +0 -273
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/list.test.tsx +0 -171
- package/templates/apps/web/app/[locale]/(authed)/waitlist/__tests__/signup.test.tsx +0 -179
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ExperimentsTable.tsx +0 -116
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/OfferFunnelTable.tsx +0 -66
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/RollupTicker.tsx +0 -61
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ScoreTrace.tsx +0 -114
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/SignupsTable.tsx +0 -139
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/WaitlistComparisonTabs.tsx +0 -85
- package/templates/apps/web/app/[locale]/(authed)/waitlist/components/status-badges.tsx +0 -67
- package/templates/apps/web/app/[locale]/(authed)/waitlist/page.tsx +0 -179
- package/templates/apps/web/app/[locale]/blog/[[...slug]]/page.tsx +0 -178
- package/templates/apps/web/app/[locale]/dev/purchase/__tests__/actions.test.ts +0 -160
- package/templates/apps/web/app/[locale]/dev/purchase/error.tsx +0 -25
- package/templates/apps/web/app/[locale]/dev/purchase/page.tsx +0 -117
- package/templates/apps/web/app/[locale]/dev/purchase/purchase.actions.ts +0 -58
- package/templates/apps/web/app/[locale]/docs/[[...slug]]/page.tsx +0 -119
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/checkout.actions.test.ts +0 -287
- package/templates/apps/web/app/[locale]/flows/[slug]/checkout.actions.ts +0 -254
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -532
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -121
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.checkout.test.tsx +0 -457
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -396
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/projects/apply/ListingApplicationClient.tsx +0 -110
- package/templates/apps/web/app/[locale]/projects/apply/__tests__/ListingApplicationClient.test.tsx +0 -96
- package/templates/apps/web/app/[locale]/schedule/__tests__/page.test.tsx +0 -117
- package/templates/apps/web/app/[locale]/schedule/confirmed/__tests__/page.test.tsx +0 -96
- package/templates/apps/web/app/[locale]/schedule/confirmed/page.tsx +0 -92
- package/templates/apps/web/app/[locale]/schedule/page.tsx +0 -82
- package/templates/apps/web/content/en/blog/README.txt +0 -25
- package/templates/apps/web/content/en/docs/index.mdx +0 -28
- package/templates/apps/web/lib/__mocks__/source-server.js +0 -31
- package/templates/apps/web/lib/blog-list-data.ts +0 -95
- package/templates/apps/web/lib/blog-post-data.ts +0 -79
- package/templates/apps/web/lib/source.ts +0 -34
- package/templates/apps/web/public/logomark-dark.svg +0 -4
- package/templates/apps/web/public/logomark-light.svg +0 -4
- package/templates/apps/web/source.config.ts +0 -78
|
@@ -1,736 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file project-listing-decision.test.ts
|
|
3
|
-
* @description Unit tests for `decideListing` + `sendListingDecisionEmail`
|
|
4
|
-
* (#4999) — the one Approve/Reject transition shared by the PATCH route and
|
|
5
|
-
* the Slack action handler.
|
|
6
|
-
*
|
|
7
|
-
* External dependency boundaries mocked:
|
|
8
|
-
* - @working-theory/database (via moduleNameMapper -> prisma-client.js mock; prisma singleton via __mocks__/prisma.ts)
|
|
9
|
-
* - @working-theory/email (sendListingApprovedEmail / sendListingRejectedEmail)
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line no-restricted-syntax -- lib/prisma.ts wraps the external DB boundary (PrismaClient requires a live connection); __mocks__/prisma.ts is the repo-standard test double for this boundary.
|
|
13
|
-
jest.mock("../../lib/prisma.js");
|
|
14
|
-
|
|
15
|
-
const mockSendApproved = jest.fn();
|
|
16
|
-
const mockSendRejected = jest.fn();
|
|
17
|
-
jest.mock("@working-theory/email", () => ({
|
|
18
|
-
sendListingApprovedEmail: (...args: unknown[]) => mockSendApproved(...args),
|
|
19
|
-
sendListingRejectedEmail: (...args: unknown[]) => mockSendRejected(...args),
|
|
20
|
-
// #5001's projection module (project-listing-flow.ts → flow-engine.ts) reaches these two.
|
|
21
|
-
sendLeadNotification: jest.fn().mockResolvedValue({ ok: true, messageId: "msg-test" }),
|
|
22
|
-
sendDeliverableEmail: jest.fn().mockResolvedValue({ ok: true, messageId: "msg-deliverable-test" }),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
// The REAL `generateListingFlow` runs in the #5001 suite below — only the
|
|
26
|
-
// license + crawler boundaries it reaches are mocked (CONTRIBUTING.md § Test
|
|
27
|
-
// code quality: mock a real boundary, never an internal module).
|
|
28
|
-
jest.mock("@working-theory/license", () => ({
|
|
29
|
-
checkLicense: jest.fn().mockResolvedValue({
|
|
30
|
-
tier: "free",
|
|
31
|
-
plan: null,
|
|
32
|
-
features: [],
|
|
33
|
-
expiresAt: null,
|
|
34
|
-
revoked: false,
|
|
35
|
-
}),
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line no-restricted-syntax -- aeo-score.ts is a network boundary (external crawl), same class as the DB mock above
|
|
39
|
-
jest.mock("../aeo-score.js", () => ({
|
|
40
|
-
scoreUrl: jest.fn(),
|
|
41
|
-
loadExampleScore: jest.fn(),
|
|
42
|
-
resolveScoreBudgetMs: () => 6000,
|
|
43
|
-
}));
|
|
44
|
-
|
|
45
|
-
import { projectListingQuestionsSchema } from "@working-theory/validation";
|
|
46
|
-
|
|
47
|
-
import * as configModule from "../../config/index.js";
|
|
48
|
-
import { prisma } from "../../lib/prisma.js";
|
|
49
|
-
|
|
50
|
-
import { decideListing, onListingDecided, sendListingDecisionEmail } from "../project-listing-decision";
|
|
51
|
-
// `computeListingStatus` lives in project-listings.ts but is the rule this
|
|
52
|
-
// module's own read applies (`toListing`), so its #5036 D6b featured-exemption
|
|
53
|
-
// cases are covered here alongside the decision that stamps the window.
|
|
54
|
-
import { computeListingStatus } from "../project-listings";
|
|
55
|
-
|
|
56
|
-
const opt = (value: string, label: string) => ({ value, label });
|
|
57
|
-
const QUESTIONS = {
|
|
58
|
-
q2: { prompt: "x", options: [opt("scale", "Scale"), opt("just-curious", "Just curious")] },
|
|
59
|
-
q3: { prompt: "x", options: [opt("a", "A"), opt("b", "B"), opt("c", "C")] },
|
|
60
|
-
q4: { prompt: "x", options: [opt("a", "A"), opt("b", "B"), opt("c", "C")] },
|
|
61
|
-
q5: { prompt: "x", options: [opt("urgent", "Now"), opt("planning", "Soon"), opt("exploring", "Someday")] },
|
|
62
|
-
q6: {
|
|
63
|
-
prompt: "x",
|
|
64
|
-
options: [opt("low", "Low"), opt("medium", "Medium"), opt("high", "High"), opt("critical", "Critical")],
|
|
65
|
-
},
|
|
66
|
-
q7: { prompt: "x" },
|
|
67
|
-
extras: [],
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const LISTING_ID = "prjl_00000000-0000-7000-8000-000000000001";
|
|
71
|
-
const SITE_ID = "wksp_00000000-0000-7000-8000-000000000001";
|
|
72
|
-
|
|
73
|
-
function makeRow(overrides: Partial<Record<string, unknown>> = {}) {
|
|
74
|
-
return {
|
|
75
|
-
id: LISTING_ID,
|
|
76
|
-
siteId: SITE_ID,
|
|
77
|
-
leadId: "lead_00000000-0000-7000-8000-000000000001",
|
|
78
|
-
slug: "my-project",
|
|
79
|
-
name: "My Project",
|
|
80
|
-
oneLiner: "A one-liner",
|
|
81
|
-
problem: "The problem",
|
|
82
|
-
url: null,
|
|
83
|
-
// #5036 D2/D5: `audience` is gone and `stage` is the six-rung `product`
|
|
84
|
-
// ladder; `commitment`/`teamComposition`/`faqs`/`anythingElse`/`address`
|
|
85
|
-
// are the new columns the page and tile render from.
|
|
86
|
-
product: "working-prototype",
|
|
87
|
-
commitment: "part-time",
|
|
88
|
-
teamComposition: "just-me",
|
|
89
|
-
faqs: null,
|
|
90
|
-
anythingElse: null,
|
|
91
|
-
address: "1 Example Street, Exampleton, EX1 2AM",
|
|
92
|
-
questions: QUESTIONS,
|
|
93
|
-
founderName: "Ada Founder",
|
|
94
|
-
founderEmail: "ada@example.com",
|
|
95
|
-
founderCompany: null,
|
|
96
|
-
headline: null,
|
|
97
|
-
logoMarkUrl: null,
|
|
98
|
-
logoWordmarkUrl: null,
|
|
99
|
-
featured: false,
|
|
100
|
-
status: "requested",
|
|
101
|
-
// Stamped at `start` and never null (#5036 D1) — the paired control for
|
|
102
|
-
// publishing the founder's name and address.
|
|
103
|
-
consentAt: new Date("2026-09-01T00:00:00.000Z"),
|
|
104
|
-
decidedAt: null,
|
|
105
|
-
decidedBy: null,
|
|
106
|
-
issueUrl: null,
|
|
107
|
-
experimentKey: null,
|
|
108
|
-
windowDays: 21,
|
|
109
|
-
windowEndsAt: null,
|
|
110
|
-
slackChannel: null,
|
|
111
|
-
slackTs: null,
|
|
112
|
-
createdAt: new Date("2026-09-01T00:00:00.000Z"),
|
|
113
|
-
updatedAt: new Date("2026-09-01T00:00:00.000Z"),
|
|
114
|
-
...overrides,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function installMocks(row: ReturnType<typeof makeRow> | null): void {
|
|
119
|
-
(prisma.projectListing.findFirst as jest.Mock).mockImplementation(
|
|
120
|
-
({ where }: { where: { id?: string; siteId?: string } }) => {
|
|
121
|
-
if (!row) return Promise.resolve(null);
|
|
122
|
-
if (row.id !== where.id) return Promise.resolve(null);
|
|
123
|
-
if (where.siteId !== undefined && row.siteId !== where.siteId) return Promise.resolve(null);
|
|
124
|
-
return Promise.resolve(row);
|
|
125
|
-
},
|
|
126
|
-
);
|
|
127
|
-
// The guarded compare-and-swap write (#4999 security review): only
|
|
128
|
-
// mutates `row` when every `where` key matches — a `status: "requested"`
|
|
129
|
-
// mismatch (already decided, or still `draft`) returns `{ count: 0 }`
|
|
130
|
-
// without touching the row, exactly like Postgres would under the guard.
|
|
131
|
-
(prisma.projectListing.updateMany as jest.Mock).mockImplementation(
|
|
132
|
-
({
|
|
133
|
-
where,
|
|
134
|
-
data,
|
|
135
|
-
}: {
|
|
136
|
-
where: { id: string; siteId?: string; status?: string };
|
|
137
|
-
data: Record<string, unknown>;
|
|
138
|
-
}) => {
|
|
139
|
-
if (!row || row.id !== where.id) return Promise.resolve({ count: 0 });
|
|
140
|
-
if (where.siteId !== undefined && row.siteId !== where.siteId) return Promise.resolve({ count: 0 });
|
|
141
|
-
if (where.status !== undefined && row.status !== where.status) return Promise.resolve({ count: 0 });
|
|
142
|
-
Object.assign(row, data);
|
|
143
|
-
return Promise.resolve({ count: 1 });
|
|
144
|
-
},
|
|
145
|
-
);
|
|
146
|
-
(prisma.waitlistExperiment.findMany as jest.Mock).mockResolvedValue([]);
|
|
147
|
-
(prisma.waitlistScore.count as jest.Mock).mockResolvedValue(0);
|
|
148
|
-
// The #5001 projection `decideListing` fires on a changed approve (fail-soft).
|
|
149
|
-
(prisma.flowDefinition.upsert as jest.Mock).mockResolvedValue({ id: "flow_1" });
|
|
150
|
-
(prisma.waitlistExperiment.upsert as jest.Mock).mockResolvedValue({ id: "wlexp_1" });
|
|
151
|
-
(prisma.projectListing.update as jest.Mock).mockResolvedValue({ id: LISTING_ID });
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
describe("decideListing", () => {
|
|
155
|
-
beforeEach(() => {
|
|
156
|
-
jest.clearAllMocks();
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it("requested -> active: stamps decidedAt/decidedBy, sets windowEndsAt = decidedAt + the ROW's windowDays, changed: true", async () => {
|
|
160
|
-
installMocks(makeRow({ windowDays: 21 }));
|
|
161
|
-
const before = Date.now();
|
|
162
|
-
|
|
163
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
164
|
-
|
|
165
|
-
expect(result.ok).toBe(true);
|
|
166
|
-
if (!result.ok) return;
|
|
167
|
-
expect(result.changed).toBe(true);
|
|
168
|
-
expect(result.value.status).toBe("active");
|
|
169
|
-
expect(result.value.decidedBy).toBe("U123");
|
|
170
|
-
expect(result.value.decidedAt).not.toBeNull();
|
|
171
|
-
expect(result.value.windowEndsAt).not.toBeNull();
|
|
172
|
-
|
|
173
|
-
const decidedAtMs = new Date(result.value.decidedAt as string).getTime();
|
|
174
|
-
const windowEndMs = new Date(result.value.windowEndsAt as string).getTime();
|
|
175
|
-
expect(windowEndMs - decidedAtMs).toBe(21 * 24 * 60 * 60 * 1000);
|
|
176
|
-
expect(decidedAtMs).toBeGreaterThanOrEqual(before);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("stamps the window from the ROW's own clamped windowDays, not a constant — a 5-day row gets 5 days", async () => {
|
|
180
|
-
installMocks(makeRow({ windowDays: 5 }));
|
|
181
|
-
|
|
182
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
183
|
-
|
|
184
|
-
expect(result.ok).toBe(true);
|
|
185
|
-
if (!result.ok) return;
|
|
186
|
-
const decidedAtMs = new Date(result.value.decidedAt as string).getTime();
|
|
187
|
-
const windowEndMs = new Date(result.value.windowEndsAt as string).getTime();
|
|
188
|
-
expect(windowEndMs - decidedAtMs).toBe(5 * 24 * 60 * 60 * 1000);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("falls back to the site's configured default for a row that predates the windowDays column", async () => {
|
|
192
|
-
installMocks(makeRow({ windowDays: null }));
|
|
193
|
-
(prisma.siteListingConfig.findUnique as jest.Mock).mockResolvedValue({
|
|
194
|
-
data: { maxWindowDays: 30, defaultWindowDays: 14, featuredEnabled: false },
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
198
|
-
|
|
199
|
-
expect(result.ok).toBe(true);
|
|
200
|
-
if (!result.ok) return;
|
|
201
|
-
const decidedAtMs = new Date(result.value.decidedAt as string).getTime();
|
|
202
|
-
const windowEndMs = new Date(result.value.windowEndsAt as string).getTime();
|
|
203
|
-
expect(windowEndMs - decidedAtMs).toBe(14 * 24 * 60 * 60 * 1000);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("requested -> rejected: stamps decidedAt/decidedBy, leaves windowEndsAt null, changed: true", async () => {
|
|
207
|
-
installMocks(makeRow());
|
|
208
|
-
|
|
209
|
-
const result = await decideListing({ id: LISTING_ID, decision: "rejected", decidedBy: "U123" });
|
|
210
|
-
|
|
211
|
-
expect(result.ok).toBe(true);
|
|
212
|
-
if (!result.ok) return;
|
|
213
|
-
expect(result.changed).toBe(true);
|
|
214
|
-
expect(result.value.status).toBe("rejected");
|
|
215
|
-
expect(result.value.decidedBy).toBe("U123");
|
|
216
|
-
expect(result.value.decidedAt).not.toBeNull();
|
|
217
|
-
expect(result.value.windowEndsAt).toBeNull();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it("second click (already active, decision active again): ok: true, changed: false, row untouched, no email/update trigger from decideListing itself", async () => {
|
|
221
|
-
// An already-approved row carries the window `decideListing` stamped on
|
|
222
|
-
// it. It has to be a LIVE one here: since #5036 D6b a non-featured active
|
|
223
|
-
// row with no window in force reads `closed`, so leaving `windowEndsAt`
|
|
224
|
-
// null would test the fail-closed branch rather than idempotency.
|
|
225
|
-
installMocks(
|
|
226
|
-
makeRow({
|
|
227
|
-
status: "active",
|
|
228
|
-
decidedAt: new Date("2026-08-01T00:00:00.000Z"),
|
|
229
|
-
decidedBy: "U000",
|
|
230
|
-
windowEndsAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
|
|
231
|
-
}),
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U999" });
|
|
235
|
-
|
|
236
|
-
expect(result.ok).toBe(true);
|
|
237
|
-
if (!result.ok) return;
|
|
238
|
-
expect(result.changed).toBe(false);
|
|
239
|
-
expect(result.value.status).toBe("active");
|
|
240
|
-
expect(result.value.decidedBy).toBe("U000"); // unchanged — the ORIGINAL decider, not U999
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("second click (already rejected, decision active this time): still idempotent — ok: true, changed: false, status stays rejected", async () => {
|
|
244
|
-
installMocks(makeRow({ status: "rejected", decidedAt: new Date("2026-08-01T00:00:00.000Z"), decidedBy: "U000" }));
|
|
245
|
-
|
|
246
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U999" });
|
|
247
|
-
|
|
248
|
-
expect(result.ok).toBe(true);
|
|
249
|
-
if (!result.ok) return;
|
|
250
|
-
expect(result.changed).toBe(false);
|
|
251
|
-
expect(result.value.status).toBe("rejected");
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("draft -> active: invalid_transition, row untouched", async () => {
|
|
255
|
-
installMocks(makeRow({ status: "draft" }));
|
|
256
|
-
|
|
257
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
258
|
-
|
|
259
|
-
expect(result.ok).toBe(false);
|
|
260
|
-
if (result.ok) return;
|
|
261
|
-
expect(result.error.kind).toBe("invalid_transition");
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it("security review (PR #4999, Finding 2): the write is a GUARDED updateMany (status: 'requested' in `where`), not a plain update — a concurrent racer that already flipped the row to a decided status makes THIS call's guard match 0 rows, landing it in the idempotent branch instead of double-writing", async () => {
|
|
265
|
-
const row = makeRow();
|
|
266
|
-
installMocks(row);
|
|
267
|
-
(prisma.projectListing.updateMany as jest.Mock).mockImplementation(async () => {
|
|
268
|
-
// Simulate a concurrent racer deciding the row between this call's
|
|
269
|
-
// updateMany guard check and its own — the guard sees "requested" is
|
|
270
|
-
// gone and correctly matches 0 rows, exactly as Postgres would under
|
|
271
|
-
// row-level locking with a `status: "requested"` WHERE guard.
|
|
272
|
-
row.status = "rejected";
|
|
273
|
-
row.decidedBy = "U-concurrent-winner";
|
|
274
|
-
return { count: 0 };
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U-this-call" });
|
|
278
|
-
|
|
279
|
-
expect(result.ok).toBe(true);
|
|
280
|
-
if (!result.ok) return;
|
|
281
|
-
expect(result.changed).toBe(false); // never claims it won the race
|
|
282
|
-
expect(result.value.status).toBe("rejected"); // the actual winner's outcome, not this call's
|
|
283
|
-
expect(result.value.decidedBy).toBe("U-concurrent-winner");
|
|
284
|
-
expect(prisma.projectListing.updateMany).toHaveBeenCalledWith(
|
|
285
|
-
expect.objectContaining({ where: expect.objectContaining({ status: "requested" }) }),
|
|
286
|
-
);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
it("unknown id: not_found", async () => {
|
|
290
|
-
installMocks(null);
|
|
291
|
-
|
|
292
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
293
|
-
|
|
294
|
-
expect(result.ok).toBe(false);
|
|
295
|
-
if (result.ok) return;
|
|
296
|
-
expect(result.error.kind).toBe("not_found");
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("siteId scoping: a foreign siteId 404s (not_found) even though the id exists", async () => {
|
|
300
|
-
installMocks(makeRow({ siteId: "wksp_owner" }));
|
|
301
|
-
|
|
302
|
-
const result = await decideListing({
|
|
303
|
-
id: LISTING_ID,
|
|
304
|
-
decision: "active",
|
|
305
|
-
decidedBy: "U123",
|
|
306
|
-
siteId: "wksp_other",
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
expect(result.ok).toBe(false);
|
|
310
|
-
if (result.ok) return;
|
|
311
|
-
expect(result.error.kind).toBe("not_found");
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it("no siteId (the Slack path): resolves by id alone, regardless of the row's siteId", async () => {
|
|
315
|
-
installMocks(makeRow({ siteId: "wksp_whatever" }));
|
|
316
|
-
|
|
317
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
318
|
-
|
|
319
|
-
expect(result.ok).toBe(true);
|
|
320
|
-
if (!result.ok) return;
|
|
321
|
-
expect(result.changed).toBe(true);
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it("returns the row's slackChannel/slackTs coordinates alongside value, never inside it", async () => {
|
|
325
|
-
installMocks(makeRow({ slackChannel: "C123", slackTs: "1234.5678" }));
|
|
326
|
-
|
|
327
|
-
const result = await decideListing({ id: LISTING_ID, decision: "active", decidedBy: "U123" });
|
|
328
|
-
|
|
329
|
-
expect(result.ok).toBe(true);
|
|
330
|
-
if (!result.ok) return;
|
|
331
|
-
expect(result.slack).toEqual({ channel: "C123", ts: "1234.5678" });
|
|
332
|
-
expect(result.value).not.toHaveProperty("slackChannel");
|
|
333
|
-
expect(result.value).not.toHaveProperty("slackTs");
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// #5036 D6d: the listing stores the experiment's KEY, which is the same
|
|
337
|
-
// string `WaitlistScore.experimentKey` holds — so the `WaitlistExperiment`
|
|
338
|
-
// read that existed only to translate an id into that key is gone, and the
|
|
339
|
-
// count is a single scoped read.
|
|
340
|
-
it("joins waitlistCount through experimentKey in ONE hop, like project-listings.ts", async () => {
|
|
341
|
-
installMocks(makeRow({ status: "active", experimentKey: "exp-a" }));
|
|
342
|
-
(prisma.waitlistScore.count as jest.Mock).mockResolvedValue(9);
|
|
343
|
-
|
|
344
|
-
const result = await decideListing({ id: LISTING_ID, decision: "rejected", decidedBy: "U123" });
|
|
345
|
-
|
|
346
|
-
expect(result.ok).toBe(true);
|
|
347
|
-
if (!result.ok) return;
|
|
348
|
-
expect(result.changed).toBe(false); // already decided
|
|
349
|
-
expect(result.value.waitlistCount).toBe(9);
|
|
350
|
-
expect(prisma.waitlistScore.count).toHaveBeenCalledWith({
|
|
351
|
-
where: { siteId: SITE_ID, experimentKey: "exp-a" },
|
|
352
|
-
});
|
|
353
|
-
expect(prisma.waitlistExperiment.findMany).not.toHaveBeenCalled();
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
// ── #5036 D6b — a featured listing never expires ────────────────────────
|
|
357
|
-
//
|
|
358
|
-
// `closed` is COMPUTED on every read from the window end, so an expired
|
|
359
|
-
// listing cannot linger publicly open because a scheduled job failed. The
|
|
360
|
-
// operator's own products are listing rows carrying `featured: true`
|
|
361
|
-
// (samhenry#316 D4), and such a row is not a time-boxed validation
|
|
362
|
-
// experiment: it has no meaningful window and must not vanish from the shelf
|
|
363
|
-
// because a date passed. `computeListingStatus` therefore takes the row's
|
|
364
|
-
// `featured` flag as a fourth argument and exempts it.
|
|
365
|
-
|
|
366
|
-
it("a featured row with a NULL window reads active, not closed", () => {
|
|
367
|
-
expect(computeListingStatus("active", null, new Date("2026-09-09T00:00:00.000Z"), true)).toBe(
|
|
368
|
-
"active",
|
|
369
|
-
);
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it("a featured row whose window has ELAPSED still reads active", () => {
|
|
373
|
-
expect(
|
|
374
|
-
computeListingStatus(
|
|
375
|
-
"active",
|
|
376
|
-
new Date("2026-01-01T00:00:00.000Z"),
|
|
377
|
-
new Date("2026-09-09T00:00:00.000Z"),
|
|
378
|
-
true,
|
|
379
|
-
),
|
|
380
|
-
).toBe("active");
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// The fail-closed branch. A null window on a NON-featured active row is a
|
|
384
|
-
// data error, not a licence to stay open forever: every real listing is
|
|
385
|
-
// time-boxed by design, and the whole point of computing `closed` rather
|
|
386
|
-
// than storing it is that an expired listing cannot linger. It reads
|
|
387
|
-
// `closed` — failing toward the closed shelf rather than toward a publicly
|
|
388
|
-
// open listing nothing bounds.
|
|
389
|
-
it("a NON-featured active row with a null window reads closed — the fail-closed error branch", () => {
|
|
390
|
-
expect(computeListingStatus("active", null, new Date("2026-09-09T00:00:00.000Z"), false)).toBe(
|
|
391
|
-
"closed",
|
|
392
|
-
);
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it("a non-featured active row still closes on an elapsed window and stays active before it", () => {
|
|
396
|
-
const now = new Date("2026-09-09T00:00:00.000Z");
|
|
397
|
-
expect(computeListingStatus("active", new Date("2026-09-08T00:00:00.000Z"), now, false)).toBe(
|
|
398
|
-
"closed",
|
|
399
|
-
);
|
|
400
|
-
expect(computeListingStatus("active", new Date("2026-09-10T00:00:00.000Z"), now, false)).toBe(
|
|
401
|
-
"active",
|
|
402
|
-
);
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
// `featured` only ever exempts an `active` row; the non-active stored
|
|
406
|
-
// statuses legitimately carry no window and are handed back untouched.
|
|
407
|
-
it.each(["draft", "requested", "rejected"])(
|
|
408
|
-
"passes the stored status %s through untouched, featured or not",
|
|
409
|
-
(stored) => {
|
|
410
|
-
const now = new Date("2026-09-09T00:00:00.000Z");
|
|
411
|
-
expect(computeListingStatus(stored, null, now, false)).toBe(stored);
|
|
412
|
-
expect(computeListingStatus(stored, null, now, true)).toBe(stored);
|
|
413
|
-
},
|
|
414
|
-
);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
describe("sendListingDecisionEmail", () => {
|
|
418
|
-
const originalEnv = process.env;
|
|
419
|
-
|
|
420
|
-
beforeEach(() => {
|
|
421
|
-
jest.clearAllMocks();
|
|
422
|
-
process.env = { ...originalEnv };
|
|
423
|
-
mockSendApproved.mockResolvedValue({ ok: true, messageId: "msg-1" });
|
|
424
|
-
mockSendRejected.mockResolvedValue({ ok: true, messageId: "msg-2" });
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
afterEach(() => {
|
|
428
|
-
process.env = originalEnv;
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
const listing = {
|
|
432
|
-
id: LISTING_ID,
|
|
433
|
-
siteId: SITE_ID,
|
|
434
|
-
leadId: "lead_1",
|
|
435
|
-
slug: "my-project",
|
|
436
|
-
name: "My Project",
|
|
437
|
-
headline: null,
|
|
438
|
-
oneLiner: "A one-liner",
|
|
439
|
-
problem: "The problem",
|
|
440
|
-
url: null,
|
|
441
|
-
product: "working-prototype" as const,
|
|
442
|
-
commitment: "part-time" as const,
|
|
443
|
-
teamComposition: "just-me" as const,
|
|
444
|
-
faqs: null,
|
|
445
|
-
anythingElse: null,
|
|
446
|
-
address: "1 Example Street, Exampleton, EX1 2AM",
|
|
447
|
-
founderName: "Ada Founder",
|
|
448
|
-
founderEmail: "ada@example.com",
|
|
449
|
-
founderCompany: null,
|
|
450
|
-
questions: projectListingQuestionsSchema.parse(QUESTIONS),
|
|
451
|
-
logoMarkUrl: null,
|
|
452
|
-
logoWordmarkUrl: null,
|
|
453
|
-
featured: false,
|
|
454
|
-
// `approved` left the vocabulary with #5033's five-state lifecycle; an
|
|
455
|
-
// approved listing is `active`.
|
|
456
|
-
status: "active" as const,
|
|
457
|
-
consentAt: "2026-09-01T00:00:00.000Z",
|
|
458
|
-
decidedAt: "2026-09-07T00:00:00.000Z",
|
|
459
|
-
decidedBy: "U123",
|
|
460
|
-
issueUrl: null,
|
|
461
|
-
experimentKey: null,
|
|
462
|
-
windowEndsAt: "2026-12-06T00:00:00.000Z",
|
|
463
|
-
waitlistCount: 0,
|
|
464
|
-
createdAt: "2026-09-01T00:00:00.000Z",
|
|
465
|
-
updatedAt: "2026-09-07T00:00:00.000Z",
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
it("no-ops (never calls Resend) when AILK_LEAD_NOTIFICATION_FROM is absent", async () => {
|
|
469
|
-
delete process.env["AILK_LEAD_NOTIFICATION_FROM"];
|
|
470
|
-
await sendListingDecisionEmail(listing, "active");
|
|
471
|
-
expect(mockSendApproved).not.toHaveBeenCalled();
|
|
472
|
-
expect(mockSendRejected).not.toHaveBeenCalled();
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
it("sends the approve email with the founder's address + a working-session link, when configured", async () => {
|
|
476
|
-
process.env["AILK_LEAD_NOTIFICATION_FROM"] = "noreply@example.com";
|
|
477
|
-
await sendListingDecisionEmail(listing, "active");
|
|
478
|
-
expect(mockSendApproved).toHaveBeenCalledTimes(1);
|
|
479
|
-
expect(mockSendRejected).not.toHaveBeenCalled();
|
|
480
|
-
const [call] = mockSendApproved.mock.calls;
|
|
481
|
-
expect(call[0].to).toBe("ada@example.com");
|
|
482
|
-
expect(call[0].fromAddress).toBe("noreply@example.com");
|
|
483
|
-
expect(call[0].founderName).toBe("Ada Founder");
|
|
484
|
-
expect(call[0].projectName).toBe("My Project");
|
|
485
|
-
expect(call[0].links.workingSession).toEqual(expect.any(String));
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
it("sends the reject email carrying both the working-session AND diagnostic links, when configured", async () => {
|
|
489
|
-
process.env["AILK_LEAD_NOTIFICATION_FROM"] = "noreply@example.com";
|
|
490
|
-
await sendListingDecisionEmail(listing, "rejected");
|
|
491
|
-
expect(mockSendRejected).toHaveBeenCalledTimes(1);
|
|
492
|
-
expect(mockSendApproved).not.toHaveBeenCalled();
|
|
493
|
-
const [call] = mockSendRejected.mock.calls;
|
|
494
|
-
expect(call[0].links.workingSession).toEqual(expect.any(String));
|
|
495
|
-
expect(call[0].links.diagnostic).toEqual(expect.any(String));
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
it("never throws when the send itself fails", async () => {
|
|
499
|
-
process.env["AILK_LEAD_NOTIFICATION_FROM"] = "noreply@example.com";
|
|
500
|
-
mockSendApproved.mockResolvedValue({ ok: false, error: { kind: "send_failed", message: "boom" } });
|
|
501
|
-
await expect(sendListingDecisionEmail(listing, "active")).resolves.toBeUndefined();
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
// ─── #5000 — the approve-path issue filing, fired after the email ─────────
|
|
505
|
-
//
|
|
506
|
-
// These run the REAL `fileListingIssue` (CONTRIBUTING.md § Test code
|
|
507
|
-
// quality: mock a real boundary, never an internal module) — only
|
|
508
|
-
// `global.fetch`, the boundary it calls the GitHub REST API through, is
|
|
509
|
-
// mocked, mirroring the #5001 suite's own treatment of `generateListingFlow`
|
|
510
|
-
// above.
|
|
511
|
-
|
|
512
|
-
afterEach(() => {
|
|
513
|
-
jest.replaceProperty(configModule, "config", {
|
|
514
|
-
...configModule.config,
|
|
515
|
-
AILK_GITHUB_REPO: undefined,
|
|
516
|
-
AILK_GITHUB_TOKEN: undefined,
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
it("on approve, still emails and resolves even when the GitHub filing call fails (network down)", async () => {
|
|
521
|
-
process.env["AILK_LEAD_NOTIFICATION_FROM"] = "noreply@example.com";
|
|
522
|
-
jest.replaceProperty(configModule, "config", {
|
|
523
|
-
...configModule.config,
|
|
524
|
-
AILK_GITHUB_REPO: "acme/site",
|
|
525
|
-
AILK_GITHUB_TOKEN: "ghp_test",
|
|
526
|
-
});
|
|
527
|
-
// eslint-disable-next-line no-restricted-syntax -- test double for the global fetch project-listing-issue.ts calls the GitHub REST API through
|
|
528
|
-
global.fetch = jest.fn().mockRejectedValue(new Error("network down")) as unknown as typeof fetch;
|
|
529
|
-
|
|
530
|
-
await expect(sendListingDecisionEmail(listing, "active")).resolves.toBeUndefined();
|
|
531
|
-
expect(mockSendApproved).toHaveBeenCalledTimes(1);
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
it("on approve, fires the GitHub filing call (fire-and-forget) when AILK_GITHUB_REPO/TOKEN are configured", async () => {
|
|
535
|
-
process.env["AILK_LEAD_NOTIFICATION_FROM"] = "noreply@example.com";
|
|
536
|
-
jest.replaceProperty(configModule, "config", {
|
|
537
|
-
...configModule.config,
|
|
538
|
-
AILK_GITHUB_REPO: "acme/site",
|
|
539
|
-
AILK_GITHUB_TOKEN: "ghp_test",
|
|
540
|
-
});
|
|
541
|
-
const fetchMock = jest.fn().mockResolvedValue({
|
|
542
|
-
status: 201,
|
|
543
|
-
json: () => Promise.resolve({ html_url: "https://github.com/acme/site/issues/1" }),
|
|
544
|
-
});
|
|
545
|
-
// eslint-disable-next-line no-restricted-syntax -- test double for the global fetch project-listing-issue.ts calls the GitHub REST API through
|
|
546
|
-
global.fetch = fetchMock as unknown as typeof fetch;
|
|
547
|
-
|
|
548
|
-
await sendListingDecisionEmail(listing, "active");
|
|
549
|
-
|
|
550
|
-
expect(fetchMock).toHaveBeenCalledWith(
|
|
551
|
-
"https://api.github.com/repos/acme/site/issues",
|
|
552
|
-
expect.objectContaining({ method: "POST" }),
|
|
553
|
-
);
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
it("on reject, never calls the GitHub filing endpoint", async () => {
|
|
557
|
-
process.env["AILK_LEAD_NOTIFICATION_FROM"] = "noreply@example.com";
|
|
558
|
-
jest.replaceProperty(configModule, "config", {
|
|
559
|
-
...configModule.config,
|
|
560
|
-
AILK_GITHUB_REPO: "acme/site",
|
|
561
|
-
AILK_GITHUB_TOKEN: "ghp_test",
|
|
562
|
-
});
|
|
563
|
-
const fetchMock = jest.fn();
|
|
564
|
-
// eslint-disable-next-line no-restricted-syntax -- test double for the global fetch project-listing-issue.ts calls the GitHub REST API through
|
|
565
|
-
global.fetch = fetchMock as unknown as typeof fetch;
|
|
566
|
-
|
|
567
|
-
await sendListingDecisionEmail(listing, "rejected");
|
|
568
|
-
|
|
569
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it("when AILK_LEAD_NOTIFICATION_FROM is absent (email skipped), still fires the GitHub filing call on approve", async () => {
|
|
573
|
-
delete process.env["AILK_LEAD_NOTIFICATION_FROM"];
|
|
574
|
-
jest.replaceProperty(configModule, "config", {
|
|
575
|
-
...configModule.config,
|
|
576
|
-
AILK_GITHUB_REPO: "acme/site",
|
|
577
|
-
AILK_GITHUB_TOKEN: "ghp_test",
|
|
578
|
-
});
|
|
579
|
-
const fetchMock = jest.fn().mockResolvedValue({
|
|
580
|
-
status: 201,
|
|
581
|
-
json: () => Promise.resolve({ html_url: "https://github.com/acme/site/issues/1" }),
|
|
582
|
-
});
|
|
583
|
-
// eslint-disable-next-line no-restricted-syntax -- test double for the global fetch project-listing-issue.ts calls the GitHub REST API through
|
|
584
|
-
global.fetch = fetchMock as unknown as typeof fetch;
|
|
585
|
-
|
|
586
|
-
await sendListingDecisionEmail(listing, "active");
|
|
587
|
-
|
|
588
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
589
|
-
});
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
// ─── #5001 — the approve-path projection (merged from main, PR #5010 resolution) ─────
|
|
593
|
-
|
|
594
|
-
const FLOW_SITE_ID = "site-abc";
|
|
595
|
-
|
|
596
|
-
const FLOW_QUESTIONS = projectListingQuestionsSchema.parse({
|
|
597
|
-
q2: {
|
|
598
|
-
prompt: "What brings you here?",
|
|
599
|
-
options: [
|
|
600
|
-
{ value: "shipping-now", label: "Shipping now" },
|
|
601
|
-
{ value: "just-curious", label: "Just curious" },
|
|
602
|
-
],
|
|
603
|
-
},
|
|
604
|
-
q3: {
|
|
605
|
-
prompt: "How painful?",
|
|
606
|
-
options: [
|
|
607
|
-
{ value: "a", label: "Not a problem" },
|
|
608
|
-
{ value: "b", label: "Annoying" },
|
|
609
|
-
{ value: "c", label: "Blocking" },
|
|
610
|
-
],
|
|
611
|
-
},
|
|
612
|
-
q4: {
|
|
613
|
-
prompt: "How close?",
|
|
614
|
-
options: [
|
|
615
|
-
{ value: "a", label: "Off" },
|
|
616
|
-
{ value: "b", label: "Close" },
|
|
617
|
-
{ value: "c", label: "Exact" },
|
|
618
|
-
],
|
|
619
|
-
},
|
|
620
|
-
q5: {
|
|
621
|
-
prompt: "When?",
|
|
622
|
-
options: [
|
|
623
|
-
{ value: "urgent", label: "Now" },
|
|
624
|
-
{ value: "planning", label: "Soon" },
|
|
625
|
-
{ value: "exploring", label: "Looking" },
|
|
626
|
-
],
|
|
627
|
-
},
|
|
628
|
-
q6: {
|
|
629
|
-
prompt: "Pay?",
|
|
630
|
-
options: [
|
|
631
|
-
{ value: "low", label: "Nothing" },
|
|
632
|
-
{ value: "medium", label: "A little" },
|
|
633
|
-
{ value: "high", label: "A budget" },
|
|
634
|
-
{ value: "critical", label: "Anything" },
|
|
635
|
-
],
|
|
636
|
-
},
|
|
637
|
-
q7: { prompt: "Anything else?" },
|
|
638
|
-
extras: [],
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
const FLOW_ROW = {
|
|
642
|
-
id: "prjl_1",
|
|
643
|
-
siteId: FLOW_SITE_ID,
|
|
644
|
-
slug: "orbit-notes",
|
|
645
|
-
name: "Orbit Notes",
|
|
646
|
-
oneLiner: "Meeting notes that file themselves.",
|
|
647
|
-
questions: FLOW_QUESTIONS,
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
describe("onListingDecided (#5001 — the approve-path projection)", () => {
|
|
651
|
-
beforeEach(() => {
|
|
652
|
-
jest.clearAllMocks();
|
|
653
|
-
process.env.DATABASE_URL = "postgres://test";
|
|
654
|
-
(prisma.projectListing.findFirst as jest.Mock).mockResolvedValue(FLOW_ROW);
|
|
655
|
-
(prisma.flowDefinition.upsert as jest.Mock).mockResolvedValue({ id: "flow_1" });
|
|
656
|
-
(prisma.waitlistExperiment.upsert as jest.Mock).mockResolvedValue({ id: "wlexp_1" });
|
|
657
|
-
(prisma.projectListing.update as jest.Mock).mockResolvedValue({ id: "prjl_1" });
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
it("projects the row on an approve", async () => {
|
|
661
|
-
await onListingDecided(FLOW_SITE_ID, "prjl_1", "active");
|
|
662
|
-
|
|
663
|
-
expect(prisma.projectListing.findFirst).toHaveBeenCalledWith({
|
|
664
|
-
where: { id: "prjl_1", siteId: FLOW_SITE_ID },
|
|
665
|
-
select: {
|
|
666
|
-
id: true,
|
|
667
|
-
siteId: true,
|
|
668
|
-
slug: true,
|
|
669
|
-
name: true,
|
|
670
|
-
oneLiner: true,
|
|
671
|
-
questions: true,
|
|
672
|
-
},
|
|
673
|
-
});
|
|
674
|
-
expect(prisma.flowDefinition.upsert).toHaveBeenCalledWith(
|
|
675
|
-
expect.objectContaining({
|
|
676
|
-
where: { siteId_slug: { siteId: FLOW_SITE_ID, slug: "orbit-notes" } },
|
|
677
|
-
}),
|
|
678
|
-
);
|
|
679
|
-
expect(prisma.waitlistExperiment.upsert).toHaveBeenCalledWith(
|
|
680
|
-
expect.objectContaining({
|
|
681
|
-
where: { siteId_key: { siteId: FLOW_SITE_ID, key: "orbit-notes" } },
|
|
682
|
-
}),
|
|
683
|
-
);
|
|
684
|
-
// #5036 D6d: the write-back is the experiment's KEY (which IS the
|
|
685
|
-
// listing's slug), not the id the upsert returned — the same string
|
|
686
|
-
// `WaitlistScore.experimentKey` holds on the other side of the join.
|
|
687
|
-
expect(prisma.projectListing.update).toHaveBeenCalledWith({
|
|
688
|
-
where: { id: "prjl_1" },
|
|
689
|
-
data: { experimentKey: "orbit-notes" },
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
it.each(["rejected", "draft", "requested"])("does nothing on a %s transition", async (status) => {
|
|
694
|
-
await onListingDecided(FLOW_SITE_ID, "prjl_1", status);
|
|
695
|
-
|
|
696
|
-
expect(prisma.projectListing.findFirst).not.toHaveBeenCalled();
|
|
697
|
-
expect(prisma.flowDefinition.upsert).not.toHaveBeenCalled();
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
it("does nothing when the row is not visible to this site", async () => {
|
|
701
|
-
(prisma.projectListing.findFirst as jest.Mock).mockResolvedValue(null);
|
|
702
|
-
|
|
703
|
-
await onListingDecided(FLOW_SITE_ID, "prjl_1", "active");
|
|
704
|
-
|
|
705
|
-
expect(prisma.flowDefinition.upsert).not.toHaveBeenCalled();
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
it("skips a row whose stored questions no longer match the template", async () => {
|
|
709
|
-
(prisma.projectListing.findFirst as jest.Mock).mockResolvedValue({
|
|
710
|
-
...FLOW_ROW,
|
|
711
|
-
questions: { q2: { prompt: "?", options: [] } },
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
await onListingDecided(FLOW_SITE_ID, "prjl_1", "active");
|
|
715
|
-
|
|
716
|
-
expect(prisma.flowDefinition.upsert).not.toHaveBeenCalled();
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
it("swallows a projection failure — the transition already committed", async () => {
|
|
720
|
-
// A doubled hyphen is a legal listing slug and an illegal flow slug, so
|
|
721
|
-
// the projection refuses before any write.
|
|
722
|
-
(prisma.projectListing.findFirst as jest.Mock).mockResolvedValue({
|
|
723
|
-
...FLOW_ROW,
|
|
724
|
-
slug: "orbit--notes",
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
await expect(onListingDecided(FLOW_SITE_ID, "prjl_1", "active")).resolves.toBeUndefined();
|
|
728
|
-
expect(prisma.projectListing.update).not.toHaveBeenCalled();
|
|
729
|
-
});
|
|
730
|
-
|
|
731
|
-
it("swallows a thrown error rather than failing the committed transition", async () => {
|
|
732
|
-
(prisma.projectListing.findFirst as jest.Mock).mockRejectedValue(new Error("db down"));
|
|
733
|
-
|
|
734
|
-
await expect(onListingDecided(FLOW_SITE_ID, "prjl_1", "active")).resolves.toBeUndefined();
|
|
735
|
-
});
|
|
736
|
-
});
|