Deep DivesAPI

Testing

Testing guide for the RawStack API component.

The API has three levels of testing, each with its own Jest configuration.

Unit tests

Tests for domain logic and application layer handlers. All dependencies are mocked — no database or Redis required.

npm run test:unit

Configuration: jest.config.js — scans test/unit/**/*.test.ts.

Integration tests

Tests for infrastructure adapters (repositories, controllers) against real databases. Requires the test Docker Compose services to be running.

docker compose up -d postgres-test redis-test
npm run test:integration

Configuration: jest-integration.config.js.

Test containers run on separate ports so they don't conflict with the dev database:

  • PostgreSQL test: port 5433
  • Redis test: port 6380

E2E tests

Full end-to-end tests that boot the NestJS application and make HTTP requests against it.

npm run test:e2e

Configuration: jest-e2e.config.js.

Test patterns

Unit test example — command handler:

test/unit/auth/application/command/create-token.handler.test.ts

Mocks the token repository and domain service. Asserts the command handler produces the expected events.

Integration test example — repository:

test/integration/auth/infrastructure/persistence/token.repository.test.ts

Runs against the test Postgres container. Exercises the Prisma adapter directly.