diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 093d086..e4c4f05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,3 +59,11 @@ jobs: run: npx tsx scripts/audit-constraints.ts --json audit.json - run: npm run build - run: npm test + # Integration tier (#135): real Postgres 16 + Redis 7 from the service + # containers above. TEST_DATABASE_URL is the admin DB, used to clone a + # migrated template database per test file. + - name: Integration tests + run: npm run test:integration + env: + TEST_DATABASE_URL: postgresql://oracledesk:oracledesk@localhost:5432/postgres + TEST_REDIS_URL: redis://localhost:6379 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f94491a..e463ae5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,3 +121,27 @@ in code, tests, fixtures or logs. Tests generate throwaway keys with `Keypair.random()`. New config goes in `.env.example` with an empty value. If you commit a secret by accident, tell a maintainer privately (see [SECURITY.md](SECURITY.md)) so it can be rotated; removing it in a later commit is not enough. + +## Tests + +There are two tiers: + +| Command | What runs | Needs | +|---|---|---| +| `npm test` | Unit tests (`tests/*.test.ts`), Prisma and Redis mocked | nothing | +| `npm run test:integration` | `tests/integration/*.int.test.ts` against real Postgres 16 + Redis 7 | Docker, or `TEST_DATABASE_URL` + `TEST_REDIS_URL` | +| `npm run test:all` | both | as above | + +Integration tests get services from Testcontainers locally, or from +`TEST_DATABASE_URL` (an admin connection, used for `CREATE DATABASE`) and +`TEST_REDIS_URL` when set, as in CI. A migrated template database is created +once; each test file gets its own clone, and tests truncate all tables in +`beforeEach`. Without Docker or the `TEST_*` URLs, the tier skips with a message. + +Writing an integration test: + +- Call `await integrationEnv('