Testing
NestForge Pro ships with 21 test suites: 18 unit test suites and 3 end-to-end (E2E) test suites covering the critical paths of the application.
Running tests
All tests via Turborepo
npx turbo test
API tests only
cd apps/api && npm test
Run with coverage
cd apps/api && npx jest --coverage
Test structure
Each API module has a co-located .spec.ts file containing its unit tests:
apps/api/src/
├── modules/
│ ├── auth/
│ │ ├── auth.service.ts
│ │ └── auth.service.spec.ts
│ ├── users/
│ │ ├── users.service.ts
│ │ └── users.service.spec.ts
│ ├── billing/
│ │ ├── billing.service.ts
│ │ └── billing.service.spec.ts
│ ├── teams/
│ │ ├── teams.service.ts
│ │ └── teams.service.spec.ts
│ └── ...
Unit tests mock external dependencies (Prisma, Stripe, Resend) so they run fast and without network access.
E2E tests
End-to-end tests live in apps/api/test/ and exercise full request/response cycles against a running application:
apps/api/test/
├── auth.e2e-spec.ts # Login, registration, token refresh, password reset
├── teams.e2e-spec.ts # Team creation, member invitations, role management
└── admin.e2e-spec.ts # Admin user listing, metrics, impersonation
E2E prerequisites
E2E tests require running service containers:
- PostgreSQL -- a test database (the test runner applies migrations automatically)
- Redis -- required for queue-dependent flows
In CI, these are provided by service containers defined in the GitHub Actions workflow. See .github/workflows/ci.yml for the configuration.
Running E2E tests locally
cd apps/api && npx jest --config test/jest-e2e.config.ts
Make sure your .env points to a test database (not your development database) to avoid data conflicts.
CI integration
The CI pipeline (.github/workflows/ci.yml) runs the full test suite on every push and pull request:
- Spins up PostgreSQL and Redis service containers
- Installs dependencies and generates the Prisma client
- Runs migrations against the test database
- Executes
jest --coveragefor both unit and E2E suites - Reports coverage results
Writing new tests
When adding a new module or feature:
- Create a
.spec.tsfile next to the service or controller you are testing - Mock Prisma using the existing
PrismaServicemock factory inapps/api/src/database/prisma.service.mock.ts - For E2E tests, add a new
*.e2e-spec.tsfile inapps/api/test/and usesupertestto make HTTP requests against the running app