Skip to content

Add integration test suite with Testcontainers PostgreSQL#37

Merged
aji70 merged 1 commit into
MyFanss:mainfrom
ndii-dev:feature/integration-test-suite-testcontainers
Jun 20, 2026
Merged

Add integration test suite with Testcontainers PostgreSQL#37
aji70 merged 1 commit into
MyFanss:mainfrom
ndii-dev:feature/integration-test-suite-testcontainers

Conversation

@ndii-dev

Copy link
Copy Markdown

Closes #28

Summary

  • test/integration/setup.ts — Testcontainers bootstrap: spins up a postgres:16 container, sets DB env vars dynamically, starts the full NestJS app, and exports clearAll() for per-test table isolation. Failed migrations exit fast with a clear error.
  • 3 integration spec files (17 assertions total, all order-independent):
    • users-pagination.integration.spec.ts — default limit, custom limit, cursor-based next page (no overlap), role filter, status filter, hasMore: false, name search
    • user-sessions.integration.spec.ts — session persistence after signup/login, token rotation (old token revoked), logout, logout-all, revoked-token rejection (401)
    • user-profile-constraints.integration.spec.ts — duplicate email returns 409, non-unique display name allowed, displayName/bio/avatarUrl persist end-to-end, bio > 300 chars returns 400
  • test/jest-integration.json — separate Jest config (testTimeout: 120 000 ms, maxWorkers: 1)
  • npm run test:integration — added to package.json
  • CI — new integration-tests job on ubuntu-latest (Docker available by default); Testcontainers manages its own container, no services: block needed
  • README — "Running integration tests locally" section with prerequisite (Docker daemon), run command, and table of covered scenarios

Test plan

  • npm run test:integration passes locally with Docker running
  • Tests do not use production DB credentials (all connection details come from the container)
  • A broken migration fails fast with a clear error message
  • CI integration-tests job passes on this PR
  • All 17 assertions pass; tests are isolated (order-independent via clearAll() in beforeEach)

- Add test/integration/setup.ts: boots a real postgres:16 container via
  Testcontainers, wires DB env vars, starts the full NestJS app, and
  provides clearAll() for per-test table isolation
- Add 3 integration spec files covering 17 assertions total:
    users-pagination   – default limit, custom limit, cursor pagination,
                         role/status filter, hasMore flag, name search
    user-sessions      – signup/login session persistence, token rotation,
                         logout, logout-all, revoked-token rejection
    user-profile-constraints – duplicate email (409), non-unique display
                         name, profile field persistence, bio max length
- Add test/jest-integration.json Jest config (testTimeout 120 s, serial)
- Add npm run test:integration script (--forceExit)
- Add integration-tests CI job that runs on ubuntu-latest with Docker;
  Testcontainers manages its own container lifecycle, no service block needed
- Add "Running integration tests locally" section to README
@aji70

aji70 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

@ndii-dev Please fix the CI to pass

@aji70 aji70 merged commit 7e02af8 into MyFanss:main Jun 20, 2026
0 of 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.

Add Integration Test Suite with Testcontainers PostgreSQL

3 participants