Skip to content

test(backend): add comprehensive API route handler test coverage (#261) - #490

Open
duongynhi000005-oss wants to merge 1 commit into
AetherEdu:mainfrom
duongynhi000005-oss:test/issue-261-route-handler-coverage
Open

duongynhi000005-oss wants to merge 1 commit into
AetherEdu:mainfrom
duongynhi000005-oss:test/issue-261-route-handler-coverage

Conversation

@duongynhi000005-oss

@duongynhi000005-oss duongynhi000005-oss commented Oct 20, 2026 •

Copy link
Copy Markdown

Closes #261

Summary

Adds comprehensive unit and integration API test coverage across backend route handlers along with automated 80%+ coverage threshold enforcement and baseline/target documentation.

Changes

  • Comprehensive Route Handler Suite (backend/tests/routes/comprehensiveRoutes.test.ts):
    • Covers verify.ts (/api/v1/verify), disputes.ts (/api/disputes), metrics.ts (/api/metrics), forum.ts (/api/forum), notifications.ts (/api/notifications), progress.ts (/api/progress), classroom.ts (/api/classroom), bookmarks.js (/api/bookmarks), localization.ts (/api/localization), and vrf.ts (/api/vrf).
    • Exercises 200/201 success paths, 400 validation & bad-request errors, 401/403 authentication & RBAC checks (authenticate, optionalAuth, requireAdmin, host-only checks, internal metrics key), 404 resource not found errors, and 500 internal server error propagation through the RFC 7807 errorHandler.
  • Auth Middleware Parity (backend/src/middleware/auth.js):
    • Exports optionalAuth and authMiddleware in src/middleware/auth.js so CommonJS/Jest module resolution matches src/middleware/auth.ts.
  • Coverage Configuration & Documentation (backend/jest.routes.config.js, backend/package.json, backend/docs/API_TEST_COVERAGE.md):
    • Adds
      pm run test:routes:coverage enforcing >= 80% statements, branches, functions, and lines.
    • Documents baseline vs achieved coverage (98.94% statements, 88.63% branches, 100% functions, 98.89% lines).

Verification

pm --prefix backend run test:routes:coverage: 2 passed suites, 45 passed tests (98.94% statements, 88.63% branches, 100% functions, 98.89% lines).

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.

[Backend] Add comprehensive API test coverage for all route handlers

1 participant