- Install dependencies:
npm install- Set up PostgreSQL database:
# Using Docker
docker run --name postgres-test -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=test_db -p 5432:5432 -d postgres:15
# Or install PostgreSQL locally and create database
createdb test_db- Configure environment variables:
cp .env.example .env
# Edit .env with your database credentialsnpm testThis runs all unit tests including:
- UsersService tests
- UsersController tests
- RolesGuard tests
- JwtStrategy tests
- DTO validation tests
npm run test:e2eThis runs end-to-end tests covering:
- User listing with pagination
- Search and filtering
- Role updates
- Status updates (suspend/activate)
- Password resets
- Audit log retrieval
- Authentication and authorization
npm run test:covGenerates a coverage report in the coverage/ directory.
npm run test:watchThe project includes GitHub Actions workflow that:
- Sets up PostgreSQL service
- Installs dependencies
- Runs unit tests
- Runs E2E tests
- Generates coverage report
src/
├── users/
│ ├── users.service.spec.ts # Service unit tests
│ ├── users.controller.spec.ts # Controller unit tests
│ └── dto/
│ ├── query-users.dto.spec.ts
│ └── reset-password.dto.spec.ts
├── auth/
│ ├── roles.guard.spec.ts
│ └── jwt.strategy.spec.ts
test/
└── users.e2e-spec.ts # E2E integration tests
All tests should pass with:
- ✓ 30+ unit tests
- ✓ 15+ E2E tests
- ✓ >80% code coverage
- Ensure PostgreSQL is running
- Check credentials in .env file
- Verify database exists
- Change port in main.ts or stop conflicting service
- Run
npm installto ensure all dependencies are installed