1 pointby madebyjam8 hours ago1 comment
  • madebyjam8 hours ago
    Building a multi-tenant SaaS for live event crew management (subdomain per company, Clerk auth, Convex backend). Just finished an 8-phase testing sprint that took the suite from ~30 tests to 868 across 65 files. 91.7% line coverage.

    The most interesting part was the middleware. Next.js middleware handles subdomain resolution, custom domain mapping (CNAME verification against Vercel API), subscription gating (expired/inactive/domain_removed), and CORS preflight. Writing tests for it surfaced real gaps: permissions arrays not being injected when non-empty, custom font URLs not propagating to downstream server components, inactive subscriptions getting a different redirect param than expired ones.

    Test infrastructure: Vitest with JSDOM environment, ConvexHttpClient mocked at the module level, Clerk auth mocked to return configurable userId, vi.useFakeTimers for date-dependent cron tests. Each server action test follows the same pattern: mock getConvexClient, mock revalidatePath, verify mutation args and revalidation paths.

    The cron job tests were tricky. The weekly digest only runs on Mondays, so fake timers were essential. The gig reminders cron does three passes (today's reminders, urgency nudges for pending assignments, streak-at-risk warnings) with rate formatting that changes based on whether the assignment has a rate set.

    Coverage report shows every previously-below-70% file is now above 85%. Middleware: 99%. Crew actions (was 18%): 100%. SSO config (was 35%): 100%.

    Stack: Next.js 15, Convex, Clerk, Vitest, Vercel.

    https://jamcrew.io