chore(test): set up integration test framework with postgres #136

Merged
djalim merged 14 commits from PMPR-setup-test-framework into develop 2026-04-26 11:30:34 +00:00
Collaborator

Summary

This PR sets up the complete testing infrastructure for the project, enabling
both unit and integration tests.

Changes

Database

  • Add databases/schema.kit.ts — Node-compatible schema for drizzle-kit
  • Generate initial migration databases/migrations/0000_square_jetstream.sql
    covering all 13 tables

Test helpers

  • Add tests/helpers/db_integration.ts — test DB connection, truncateAll()
    for clean state between tests, and seed helpers for each table

CI

  • Add .gitea/workflows/test.yml — dedicated test workflow with a postgres
    service container (unit + integration jobs)
  • Update lint.yml — run test:unit instead of the full test suite (no DB
    needed for lint CI)

Tasks

  • deno task test:unit — run unit tests only
  • deno task test:integration — run integration tests only
  • deno task migrate — apply Drizzle migrations

Fixes

  • Add @0.45.2 version to unversioned npm:drizzle-orm imports (lint rule
    no-unversioned-import)
  • Prefix unused NOT_FOUND in enseignements.ts with _

How to run locally

# Apply migrations against your local DB
deno task migrate

# Unit tests (no DB required)
deno task test:unit

# Integration tests (requires postgres)
deno task test:integration
## Summary This PR sets up the complete testing infrastructure for the project, enabling both unit and integration tests. ## Changes ### Database - Add `databases/schema.kit.ts` — Node-compatible schema for drizzle-kit - Generate initial migration `databases/migrations/0000_square_jetstream.sql` covering all 13 tables ### Test helpers - Add `tests/helpers/db_integration.ts` — test DB connection, `truncateAll()` for clean state between tests, and seed helpers for each table ### CI - Add `.gitea/workflows/test.yml` — dedicated test workflow with a postgres service container (unit + integration jobs) - Update `lint.yml` — run `test:unit` instead of the full test suite (no DB needed for lint CI) ### Tasks - `deno task test:unit` — run unit tests only - `deno task test:integration` — run integration tests only - `deno task migrate` — apply Drizzle migrations ### Fixes - Add `@0.45.2` version to unversioned `npm:drizzle-orm` imports (lint rule `no-unversioned-import`) - Prefix unused `NOT_FOUND` in `enseignements.ts` with `_` ## How to run locally ```bash # Apply migrations against your local DB deno task migrate # Unit tests (no DB required) deno task test:unit # Integration tests (requires postgres) deno task test:integration
djalim added 2 commits 2026-04-25 22:26:17 +00:00
- Generate Drizzle migrations (databases/migrations/)
- Add databases/schema.kit.ts for drizzle-kit (Node-compatible imports)
- Update drizzle.config.ts to use schema.kit.ts
- Add deno tasks: test:unit, test:integration, migrate
- Add tests/helpers/db_integration.ts: testDb, truncateAll, seed helpers
- Add .gitea/workflows/test.yml: CI with postgres service container
- Update lint.yml: run test:unit only (no DB needed)
- Update deploy.yml: add check-code job, gate deploy on it
fix(lint): add version to drizzle-orm imports and prefix unused NOT_FOUND
Tests / Unit tests (pull_request) Failing after 6s
Tests / Integration tests (pull_request) Failing after 1m28s
ea61d83384
djalim added 1 commit 2026-04-25 22:27:23 +00:00
fix(ci): install npm deps before running unit tests
Tests / Unit tests (pull_request) Failing after 27s
Tests / Integration tests (pull_request) Failing after 27s
f66de20dad
djalim added 1 commit 2026-04-25 22:32:07 +00:00
fix(ci): use deno install for unit tests, add postgres readiness check
Tests / Unit tests (pull_request) Successful in 13s
Tests / Integration tests (pull_request) Has been cancelled
f739f94403
djalim added 1 commit 2026-04-25 22:36:00 +00:00
fix(ci): replace pg_isready with nc for postgres readiness check
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Has been cancelled
af2562ef2b
djalim added 1 commit 2026-04-25 22:37:37 +00:00
fix(ci): use bash /dev/tcp for postgres readiness check
Tests / Unit tests (pull_request) Successful in 12s
Tests / Integration tests (pull_request) Has been cancelled
f26b2b044f
djalim added 2 commits 2026-04-25 22:43:42 +00:00
fix(ci): install postgres via apt-get instead of docker
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Failing after 25s
182342aab0
djalim added 1 commit 2026-04-25 22:46:15 +00:00
fix(ci): start postgres with pg_ctlcluster instead of systemctl
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Failing after 53s
ce807391c6
djalim added 1 commit 2026-04-25 22:49:21 +00:00
fix(ci): add GRANT on public schema and verbose migrate output
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Failing after 54s
32052ab1c9
djalim added 1 commit 2026-04-25 22:51:56 +00:00
fix(ci): remove unsupported --verbose from drizzle-kit migrate
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Failing after 53s
7be13737d5
djalim added 1 commit 2026-04-25 22:54:35 +00:00
debug(ci): add connection diagnostics before migrate
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Failing after 56s
ae5d5b64ac
djalim added 1 commit 2026-04-25 22:58:22 +00:00
fix(ci): use connection URL with ssl:false in drizzle config
Tests / Unit tests (pull_request) Successful in 13s
Tests / Integration tests (pull_request) Failing after 56s
e0ac451372
djalim added 1 commit 2026-04-26 11:26:58 +00:00
fix(ci): fix postgres TCP setup and truncateAll superuser error
Tests / Unit tests (pull_request) Successful in 12s
Tests / Integration tests (pull_request) Successful in 58s
367b0b2357
- Use apt-get install + configure listen_addresses + md5 auth in pg_hba
  so psql can connect via 127.0.0.1 (not just Unix socket)
- Use pg_ctlcluster restart after config changes + wait for pg_isready
- Replace session_replication_role (requires superuser) with a single
  TRUNCATE ... CASCADE which handles FK deps without elevated privileges
- All 3 integration tests now pass in CI (act + Gitea Actions)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
djalim merged commit daa7f4951f into develop 2026-04-26 11:30:34 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/PolyMPR#136