Skip to content

[nightshift] test-gap: Zero test coverage — critical paths untested #3

@nightshift-micr

Description

@nightshift-micr

Test Coverage Gap Analysis Report — micr-dev/anonq

Executive Summary

Metric Value
Total source files 20 (non-UI-library)
Files with tests 0
Estimated test coverage ~0%
Test framework None
Overall risk 🔴 Critical

Prioritized Test Coverage Gaps

🔴 P0 — Critical

# File Untested Logic
1 lib/data/questionService.ts All DB operations — addQuestion, addAnswer (transactional with rollback), deleteQuestion, getAllQA, getQuestionById
2 app/api/admin/questions/route.ts Auth0 session check, isAllowedUser guard, DELETE missing-ID returns 400
3 app/api/admin/answer/route.ts Auth guard, input validation (empty, >2000 chars), question-not-found 404
4 lib/auth0.ts isAllowedUser() — null/undefined/empty/allowed/denied emails
5 app/api/questions/route.ts Dual rate limiting (100/15min + 5/hour), input validation

🟠 P1 — High

# File Untested Logic
6 lib/services/apiService.ts Grammar correction API integration, notification dispatch
7 lib/config.ts Configuration singleton, env var fallbacks
8 app/api/questions/regenerate/route.ts Rate-limited paid API calls
9 lib/api.ts Client-side API wrapper
10 app/api/questions/qa/route.ts Public Q&A endpoint

🟡 P2 — Medium

# File Risk
11 components/QuestionForm.tsx Form submission flow, character limits
12 components/AdminDashboardClient.tsx Full admin flow
13 components/HomeClient.tsx QA polling, toast notifications

🟢 P3 — Low

# File Risk
14 components/QAList.tsx Display-only
15 components/FaultyTerminal.tsx Visual WebGL effect
16-20 Types, utils, hooks, pages Low complexity

Recommended Test Cases

P0-1: lib/data/questionService.ts

  • should insert a trimmed question and return it
  • should insert answer and mark question as answered
  • should rollback answer if question update fails
  • should join questions with answers and sort correctly

P0-4: lib/auth0.ts

  • should return false for null/undefined/empty email
  • should return true for allowed email (case-insensitive)

P0-5: app/api/questions/route.ts

  • should reject empty content (400)
  • should return 429 when rate limit exceeded
  • should submit question and return 201

Recommended Infrastructure

  1. Install Vitest: npm install -D vitest @vitejs/plugin-react jsdom
  2. Install API testing: npm install -D node-mocks-http
  3. Create vitest.config.ts with @/ alias support
  4. Update test script: "test": "vitest run"

Top 3 Immediate Actions

  1. Add questionService.ts testsaddAnswer has manual transaction/rollback, prime candidate for silent data corruption
  2. Add auth guard tests — Without tests, any regression opens admin to unauthorized users
  3. Add rate limiter tests — Complex in-memory rate limiting needs testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions