Skip to content

Add behavior-level test coverage for the remaining admin CRUD routes #62

Closed

Description

@diese-tech

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

Out of scope

Activity

  1. added a commit that references this issue on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions