Skip to content

Integration test setup #47

Description

@slifty

Description

Set up integration testing infrastructure that tests API endpoints against a real PostgreSQL database.

Requirements

Infrastructure

  • Test database provisioned via Docker Compose (separate from dev database)
  • Migration runner executes before test suite
  • Test isolation: each test starts with a clean database state
    • Option A: Transaction rollback (wrap each test in a transaction, rollback after)
    • Option B: Truncate all tables between tests
  • Test database connection configuration via environment variables

Test Patterns

  • API endpoint tests using supertest
    • Authenticated requests (generate test JWTs)
    • Test all HTTP methods, status codes, response shapes
    • Test authorization (correct role required, 403 on insufficient permissions)
  • Database query tests: verify SQL queries return expected results
  • Test helpers: seed data utilities for common scenarios (org with members, meeting with motions, etc.)

Initial Tests

  • Auth endpoints: register, login, me
  • Organization CRUD
  • Meeting CRUD
  • Vote casting (both anonymous and open)

CI Integration

  • Integration tests run in GitHub Actions with a PostgreSQL service container
  • Separate test command: npm run test:integration
  • Integration test results included in CI pipeline

Notes

Integration tests are slower than unit tests but critical for verifying SQL queries, database constraints, and API behavior. Keep them focused — test the boundaries (HTTP → database), not business logic (that's what unit tests are for).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions