Compare commits

..

8 Commits

Author SHA1 Message Date
djalim 07b6f1e347 chore(test-framework): remove endpoint-specific tests from framework branch
Tests / Unit tests (pull_request) Successful in 12s
Tests / Integration tests (pull_request) Failing after 54s
Each endpoint's tests will be on their own issue branch (PMPR-109, etc.).
The framework branch only contains: CI config, db helpers, migrations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 13:55:21 +02:00
djalim c5018d9ced test(integration): add DB integration tests for students, promotions, roles, modules
Covers full CRUD for each resource via testDb:
- promotions: list, create, get by id, not found, update, delete
- students: list, filter by promo, create, get, not found, update, delete
- roles: list, create, get with permissions, update+reset perms, delete
- modules: list, create, duplicate id rejection, get, not found, update, delete

27 integration tests passing in CI (act + Gitea Actions).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 13:37:02 +02:00
djalim 367b0b2357 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
- 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>
2026-04-26 13:22:45 +02:00
djalim e0ac451372 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
2026-04-26 00:57:38 +02:00
djalim ae5d5b64ac debug(ci): add connection diagnostics before migrate
Tests / Unit tests (pull_request) Successful in 11s
Tests / Integration tests (pull_request) Failing after 56s
2026-04-26 00:54:11 +02:00
djalim 7be13737d5 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
2026-04-26 00:51:22 +02:00
djalim 32052ab1c9 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
2026-04-26 00:48:57 +02:00
djalim ce807391c6 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
2026-04-26 00:46:02 +02:00
3 changed files with 23 additions and 39 deletions
+12 -11
View File
@@ -43,25 +43,26 @@ jobs:
- name: Start postgres - name: Start postgres
run: | run: |
sudo apt-get update -qq && sudo apt-get install -y -qq postgresql > /dev/null sudo apt-get update -qq && sudo apt-get install -y -qq postgresql > /dev/null
sudo systemctl start postgresql PG_VER=$(ls /etc/postgresql/)
sudo sed -i "s/^#*listen_addresses\s*=.*/listen_addresses = '127.0.0.1'/" /etc/postgresql/$PG_VER/main/postgresql.conf
echo "host all all 127.0.0.1/32 md5" | sudo tee -a /etc/postgresql/$PG_VER/main/pg_hba.conf
sudo pg_ctlcluster $PG_VER main restart
until sudo -u postgres pg_isready -h 127.0.0.1; do sleep 1; done
sudo -u postgres psql -c "CREATE USER test WITH PASSWORD 'test';" sudo -u postgres psql -c "CREATE USER test WITH PASSWORD 'test';"
sudo -u postgres psql -c "CREATE DATABASE polympr_test OWNER test;" sudo -u postgres psql -c "CREATE DATABASE polympr_test OWNER test;"
sudo -u postgres psql -d polympr_test -c "GRANT ALL ON SCHEMA public TO test;"
- name: Apply migrations
run: |
sed 's/--> statement-breakpoint/;/g' databases/migrations/0000_square_jetstream.sql | \
PGPASSWORD=test psql -h 127.0.0.1 -U test -d polympr_test
- name: Install dependencies - name: Install dependencies
run: npm install --ignore-scripts && deno install run: npm install --ignore-scripts && deno install
- name: Apply migrations
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: test
POSTGRES_PASS: test
POSTGRES_DB: polympr_test
run: deno task migrate
- name: Run integration tests - name: Run integration tests
env: env:
POSTGRES_HOST: localhost POSTGRES_HOST: 127.0.0.1
POSTGRES_PORT: 5432 POSTGRES_PORT: 5432
POSTGRES_USER: test POSTGRES_USER: test
POSTGRES_PASS: test POSTGRES_PASS: test
+5 -5
View File
@@ -1,15 +1,15 @@
import { defineConfig } from "drizzle-kit"; import { defineConfig } from "drizzle-kit";
import process from "node:process"; import process from "node:process";
const url = process.env.DATABASE_URL ??
`postgresql://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASS}@${process.env.POSTGRES_HOST ?? "localhost"}:${process.env.POSTGRES_PORT ?? 5432}/${process.env.POSTGRES_DB}`;
export default defineConfig({ export default defineConfig({
dialect: "postgresql", dialect: "postgresql",
schema: "./databases/schema.kit.ts", schema: "./databases/schema.kit.ts",
out: "./databases/migrations", out: "./databases/migrations",
dbCredentials: { dbCredentials: {
host: process.env.POSTGRES_HOST!, url,
port: Number(process.env.POSTGRES_PORT ?? 5432), ssl: false,
user: process.env.POSTGRES_USER!,
password: process.env.POSTGRES_PASS!,
database: process.env.POSTGRES_DB!,
}, },
}); });
+6 -23
View File
@@ -18,29 +18,15 @@ function createTestPool(): pg.Pool {
user: Deno.env.get("POSTGRES_USER") ?? "test", user: Deno.env.get("POSTGRES_USER") ?? "test",
password: Deno.env.get("POSTGRES_PASS") ?? "test", password: Deno.env.get("POSTGRES_PASS") ?? "test",
database: Deno.env.get("POSTGRES_DB") ?? "polympr_test", database: Deno.env.get("POSTGRES_DB") ?? "polympr_test",
ssl: false,
}); });
} }
export const testPool = createTestPool(); export const testPool = createTestPool();
export const testDb = drizzle(testPool, { schema }); export const testDb = drizzle(testPool, { schema });
// Ordre de truncate respectant les FK (enfants avant parents) const ALL_TABLES =
const TRUNCATE_ORDER = [ '"mobility","ajustements","notes","ue_modules","enseignements","role_permissions","students","users","modules","ues","promotions","permissions","roles"';
"mobility",
"ajustements",
"notes",
"ue_modules",
"enseignements",
"role_permissions",
"students",
"ue_modules",
"users",
"modules",
"ues",
"promotions",
"permissions",
"roles",
] as const;
/** /**
* Vide toutes les tables dans le bon ordre. * Vide toutes les tables dans le bon ordre.
@@ -49,12 +35,9 @@ const TRUNCATE_ORDER = [
export async function truncateAll(): Promise<void> { export async function truncateAll(): Promise<void> {
const client = await testPool.connect(); const client = await testPool.connect();
try { try {
// Désactiver les FK temporairement pour simplifier await client.query(
await client.query("SET session_replication_role = replica"); `TRUNCATE TABLE ${ALL_TABLES} RESTART IDENTITY CASCADE`,
for (const table of TRUNCATE_ORDER) { );
await client.query(`TRUNCATE TABLE "${table}" RESTART IDENTITY CASCADE`);
}
await client.query("SET session_replication_role = DEFAULT");
} finally { } finally {
client.release(); client.release();
} }