Repository navigation
Description
Parent discovery
Tracked under #53 — Discovery: Half-Shell codebase audit and technical-debt dependency map. This is Phase 2 of the route-coverage work #58 started — the 8 routes #58 explicitly deferred as lower-risk.
Problem
#58 covered the 8 highest-value untested mutation seams (money path, public intake, technician SMS actions, job/quote CRUD). That leaves these 8 route files still without a route.test.ts:
| Route | Methods | Auth | Notes |
|---|---|---|---|
src/app/api/admin/users/route.ts |
GET/POST | requireApiRole(['admin']) |
POST invites via Supabase Auth admin (inviteUserByEmail) then inserts a users row — two-step, needs Auth-admin API mocked alongside the DB |
src/app/api/admin/templates/route.ts |
GET/POST | GET: ['admin','dispatcher']; POST: ['admin'] |
Role differs by method — worth its own test per method |
src/app/api/admin/templates/[id]/route.ts |
PATCH/DELETE | requireApiRole(['admin']) |
DELETE is a soft-delete (is_active: false); company-scoped ownership check before either |
src/app/api/admin/settings/route.ts |
GET/PATCH | requireApiRole(['admin']) |
Slug-uniqueness conflict check; calls getPublicSquareConnection() for display — needs that helper mocked |
src/app/api/admin/square/connect/route.ts |
GET | requireApiRole(['admin']) |
Returns a redirect, not JSON — asserts on Location/status under configured vs. unconfigured Square OAuth |
src/app/api/admin/technicians/[id]/regenerate-pin/route.ts |
POST | requireApiRole(['admin']) |
Company-scoped technician lookup; updates the technician's password via Supabase Auth admin (updateUserById) |
src/app/api/tech/login/route.ts |
POST | Public, per-handle rate limit (hardcoded 10/min) | Delegates entirely to Supabase Auth signInWithPassword — no direct table access, smallest surface of the eight |
src/app/api/intake/status/route.ts |
GET | Public, JWT-token-gated + dual rate limit (IP + token) | Reads jobs/status_events, conditionally quotes + generates a quote-approval token when the job is quote_pending |
None of these are money-path or cross-tenant-critical the way #58's routes were (hence "lower-risk" in #58's own scope), but each is still a real production mutation or auth surface with zero regression coverage today.
Scope
Same pattern as #58 and #60: hand-built fake Supabase query-builder, requireApiRole mocked per test, external calls (Supabase Auth admin methods, getPublicSquareConnection, rate limiter) mocked directly rather than modeled through the DB fake. For each route: success path, its role/auth rejection(s), and a cross-tenant case wherever the route is company-scoped (admin/templates/[id], admin/settings, admin/technicians/[id]/regenerate-pin, intake/status).
Acceptance criteria
- Each of the 8 routes above has a
route.test.tscovering success, auth/role rejection, and cross-tenant isolation where applicable. - Supabase Auth admin calls (
inviteUserByEmail,updateUserById) are mocked, not exercised for real. -
npm run lint,npx tsc --noEmit,npm test,npm run buildall pass. - No production code changes unless a test surfaces an actual bug (same discipline as Centralize API role authorization and enforce a tested permission matrix #49–Harden payment provider tests, especially the live Square integration #60) — if one does, fix it with red-before-fix verification and call it out explicitly rather than folding it in silently.
Out of scope
- Payment provider test hardening (Harden payment provider tests, especially the live Square integration #60).
- Load test script refresh (Review and refresh load test scripts against the current route/auth model #61).
- A systematic role × route permission-matrix audit (separate, broader follow-up item — this issue is per-route coverage, not a matrix).
Activity
Merge pull request #68 from diese-tech/claude/admin-crud-coverage-62