Skip to content

chore(test): scaffold vitest and add waitlist route tests#3

Merged
MP2EZ merged 1 commit into
previewfrom
chore/test-vitest-waitlist
May 23, 2026
Merged

chore(test): scaffold vitest and add waitlist route tests#3
MP2EZ merged 1 commit into
previewfrom
chore/test-vitest-waitlist

Conversation

@MP2EZ
Copy link
Copy Markdown
Owner

@MP2EZ MP2EZ commented May 23, 2026

Summary

  • Adds `vitest` as a devDependency with `test` / `test:watch` scripts.
  • New `vitest.config.ts`: node environment (matches Cloudflare Workers' `nodejs_compat`), aliases `@/` to repo root, excludes `.next` / `.open-next`.
  • New `app/api/waitlist/route.test.ts`: 8 tests covering every branch of the POST handler — missing/invalid email (400), missing `NOTION_TOKEN` / `NOTION_WAITLIST_DB_ID` (500), success without A/B variant (no `Variant` property), success with variant 'A' (Notion payload + `trackConversion` called), Notion API non-ok (500 via outer catch), malformed JSON body (500 via outer catch).

Mocking strategy: `vi.mock('@/lib/ab-testing', ...)` for `getVariant` / `trackConversion`, `vi.stubEnv` for env vars (with `vi.resetModules()` + dynamic `import()` of the route per test because env is captured at module-load time), `vi.spyOn(global, 'fetch')` for the Notion call.

Resolves audit TEST-08 from `.audit-report.md`. This is the first test in the repo — the waitlist is the only ingress for real user data so getting coverage here was the highest-leverage starting point.

Test plan

  • `npm run test` exits 0 with 8 passing tests
  • `npm run lint` clean
  • CI honors the new `test` script (if a CI step exists; otherwise this PR can land before wiring it)

🤖 Generated with Claude Code

Adds vitest as a devDependency with test/test:watch scripts and a
vitest.config.ts that aliases @/ to repo root and runs in the node
environment (Cloudflare Workers' nodejs_compat flag matches).

Covers the waitlist POST handler across all 8 branches:
- missing/invalid email (400)
- missing NOTION_TOKEN or NOTION_WAITLIST_DB_ID (500)
- no A/B variant (Notion payload without Variant, no trackConversion)
- variant 'A' assigned (Variant select + trackConversion called)
- Notion API non-ok response (500)
- malformed request body (500 via outer catch)

Resolves audit TEST-08 (.audit-report.md).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant