Skip to content

feat(tests): implemented comprehensive production-grade automated test suite - #26

Merged
AmanKrSahu merged 5 commits into
devfrom
feat/testing-infrastructure
Aug 22, 2026
Merged

AmanKrSahu merged 5 commits into
devfrom
feat/testing-infrastructure

Conversation

@AmanKrSahu

Copy link
Copy Markdown
Owner

Overview

This Pull Request implements FR-1: Automated Test Suite & Quality Gates (Task 2.22 in docs/audit/2026-07-20/task.md). It establishes a production-grade, zero-dependency, three-layer automated testing architecture using Vitest and Supertest, running 100% in-memory out-of-the-box. It includes decoupled mock data layers, continuous integration (CI) quality gates, path alias standardization, and full documentation consolidation.


Key Changes by Functional Area

1. Zero-Infrastructure In-Memory Execution & Decoupled Mocks

  • Decoupled Mock Client Suite: Extracted test mocks out of production files (src/core/database/prisma.ts & src/core/database/redis.ts) into modular files inside tests/mocks/.
  • In-Memory Data Stores:
    • Built a stateful JS Map backing store for Prisma (tests/mocks/prisma.ts) supporting user, session, account, and oidcClient models, relation loading (user.accounts, session.user), in-place record mutations, $transaction handling, and auto-resetting prismaMock spies.
    • Configured polyfilled ioredis-mock (tests/mocks/redis.ts) to handle custom Redis Lua commands (SCRIPT LOAD, EVALSHA, EVAL) required by rate-limit-redis.
  • Path Alias Standardization: Configured clean @tests/*, @core/*, and @api/* path aliases across tsconfig.json and vitest.config.ts, replacing relative import paths (../../../).

2. Three-Layer Automated Test Suite (61 / 61 Tests Passing)

  • Layer 1: Service Unit Tests (tests/unit/*.service.test.ts): Covered business logic across all 8 service classes (AuthService, UserService, MfaService, OidcService, OAuthService, SessionService, MagicLinkService, HealthService, AdminService).
  • Layer 2: Integration Tests (tests/integration/*.test.ts): Verified Express middlewares (CORS, CSRF double-submit tokens, role authorization, rate-limiters, error sanitizers) and router schema validations.
  • Layer 3: End-to-End User Journeys (tests/e2e/*.test.ts): Covered multi-step customer flows including Credentials signup/login/rotation/lockout, Magic Link verification, TOTP MFA lifecycle and backup codes, OIDC PKCE authorization and UserInfo, and Admin user/session management.

3. Continuous Integration & Artifact Relocation

  • GitHub Actions CI Quality Gate: Configured .github/workflows/ci.yml to execute Node 20, frozen lockfile caching (pnpm install --frozen-lockfile), linter (pnpm lint), type-check (pnpm type-check), and in-memory test suite (pnpm test).
  • Dev Email Artifact Storage: Moved outbound non-production HTML preview email generation from root temporary folders to logs/emails/.

Documentation Synchronization

  • docs/testing_architecture.md: Consolidated docs/testing_architecture.md and docs/testing-workflows.md into a single authoritative guide detailing test architecture, directory layout, CLI commands, pre-commit hooks, CI gates, and deployment workflows (Local Dev, Docker Dev with Redis Insight, and Docker Prod behind Nginx). Deleted duplicate docs/testing-workflows.md.
  • docs/api-specs/AuthKit.postman_collection.json: Restructured to cover all 46 API endpoints organized into 10 structured workflow folders.
  • docs/api-specs/openapi.json & Swagger UI: Regenerated and synchronized all 46 endpoints via pnpm build:swagger.
  • README.md: Updated documentation links to point to docs/testing_architecture.md and detailed the 10 Postman collection workflow folders.
  • docs/audit/2026-07-20/task.md: Marked Phase 2 tasks 2.21, 2.21a, 2.21b, and 2.22 (FR-1) as Done.

Verification Summary

  • Type Safety: Passed compilation checks (pnpm type-check) with zero errors.
  • Linting & Formatting: Checked code quality (pnpm lint) and formatting (pnpm format) successfully with zero issues.
  • Test Suite Execution: All 14 test files passed (61 / 61 tests passing 100%).

@AmanKrSahu
AmanKrSahu merged commit 3915cdc into dev Aug 22, 2026
2 checks passed
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.

1 participant