Compare commits

..

16 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
djalim 182342aab0 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
2026-04-26 00:43:11 +02:00
djalim d32758b310 fix(ci): use docker run instead of services for postgres 2026-04-26 00:41:20 +02:00
djalim f26b2b044f 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
2026-04-26 00:37:21 +02:00
djalim af2562ef2b 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
2026-04-26 00:35:42 +02:00
djalim f739f94403 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
2026-04-26 00:31:15 +02:00
djalim f66de20dad 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
2026-04-26 00:27:07 +02:00
djalim ea61d83384 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
2026-04-26 00:24:27 +02:00
djalim 6402f802e9 chore(test): set up integration test framework with postgres
- 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
2026-04-26 00:23:12 +02:00
6 changed files with 1 additions and 189 deletions
-17
View File
@@ -6,26 +6,9 @@ on:
- main
jobs:
check-code:
name: "Check Deno code"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Check formatting
run: deno fmt --check
- name: Check linting
run: deno lint
deploy:
name: "Build Docker image"
runs-on: ubuntu-latest
needs: check-code
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
-4
View File
@@ -4,10 +4,6 @@ on:
pull_request:
branches:
- main
- develop
push:
branches:
- develop
permissions:
contents: read
+1 -3
View File
@@ -2,9 +2,7 @@ import { defineConfig } from "drizzle-kit";
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}`;
`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({
dialect: "postgresql",
-42
View File
@@ -1,42 +0,0 @@
// #115 - E2E tests for GET /permissions
// Handler statique (pas de DB), test direct du handler
import { assertEquals, assertExists } from "@std/assert";
import { makeEmployeeContext, makeGetRequest } from "../helpers/handler.ts";
import { handler as permissionsHandler } from "$apps/admin/api/permissions.ts";
Deno.test({
name: "e2e permissions: GET /permissions returns all 9 permissions",
fn() {
const res = permissionsHandler.GET!(
makeGetRequest("/permissions"),
makeEmployeeContext(),
);
assertEquals(res.status, 200);
return res.text().then((text) => {
const data = JSON.parse(text);
assertEquals(data.length, 9);
assertExists(data.find((p: { id: string }) => p.id === "student_read"));
assertExists(data.find((p: { id: string }) => p.id === "role_write"));
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "e2e permissions: GET /permissions - all entries have id and nom",
async fn() {
const res = permissionsHandler.GET!(
makeGetRequest("/permissions"),
makeEmployeeContext(),
);
const data: { id: string; nom: string }[] = await res.json();
for (const p of data) {
assertEquals(typeof p.id, "string");
assertEquals(typeof p.nom, "string");
}
},
sanitizeResources: false,
sanitizeOps: false,
});
-58
View File
@@ -1,58 +0,0 @@
import { assertEquals, assertExists } from "@std/assert";
import {
closeTestPool,
seedRoles,
seedUsers,
testDb,
truncateAll,
} from "../helpers/db_integration.ts";
import { users } from "$root/databases/schema.ts";
Deno.test({
name: "integration: GET /users - DB round trip",
async fn() {
await truncateAll();
const [role] = await seedRoles([{ nom: "employee" }]);
await seedUsers([
{ id: "dupont.jean", nom: "Dupont", prenom: "Jean", idRole: role.id },
{ id: "martin.alice", nom: "Martin", prenom: "Alice", idRole: role.id },
]);
const rows = await testDb.select().from(users);
assertEquals(rows.length, 2);
assertExists(rows.find((u) => u.id === "dupont.jean"));
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "integration: INSERT user and retrieve by id",
async fn() {
await truncateAll();
const [role] = await seedRoles([{ nom: "admin" }]);
const [created] = await testDb.insert(users).values({
id: "durand.claire",
nom: "Durand",
prenom: "Claire",
idRole: role.id,
}).returning();
assertExists(created);
assertEquals(created.id, "durand.claire");
assertEquals(created.nom, "Durand");
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "integration: cleanup - close pool",
async fn() {
await closeTestPool();
},
sanitizeResources: false,
sanitizeOps: false,
});
-65
View File
@@ -1,65 +0,0 @@
// #115 - Unit tests for GET /permissions
import { assertEquals, assertExists } from "@std/assert";
import { mockFetch, restoreFetch } from "../helpers/api_mock.ts";
interface Permission {
id: string;
nom: string;
}
const EXPECTED_PERMISSIONS: Permission[] = [
{ id: "student_read", nom: "Consulter les élèves" },
{ id: "student_write", nom: "Gérer les élèves" },
{ id: "note_read", nom: "Consulter les notes" },
{ id: "note_write", nom: "Gérer les notes" },
{ id: "module_read", nom: "Consulter les modules" },
{ id: "module_write", nom: "Gérer les modules" },
{ id: "user_read", nom: "Consulter les utilisateurs" },
{ id: "user_write", nom: "Gérer les utilisateurs" },
{ id: "role_write", nom: "Gérer les rôles" },
];
Deno.test("permissions: known permission ids", () => {
const ids = EXPECTED_PERMISSIONS.map((p) => p.id);
assertEquals(ids.includes("student_read"), true);
assertEquals(ids.includes("student_write"), true);
assertEquals(ids.includes("note_read"), true);
assertEquals(ids.includes("role_write"), true);
assertEquals(ids.length, 9);
});
Deno.test("permissions: all permissions have string id and nom", () => {
for (const p of EXPECTED_PERMISSIONS) {
assertEquals(typeof p.id, "string");
assertEquals(typeof p.nom, "string");
}
});
Deno.test("mock API: GET /permissions returns all permissions", async () => {
mockFetch({ "/permissions": EXPECTED_PERMISSIONS });
try {
const res = await fetch("http://localhost/api/permissions");
assertEquals(res.status, 200);
const data: Permission[] = await res.json();
assertEquals(data.length, 9);
assertExists(data.find((p) => p.id === "student_read"));
assertExists(data.find((p) => p.id === "role_write"));
} finally {
restoreFetch();
}
});
Deno.test("mock API: GET /permissions - each permission has id and nom", async () => {
mockFetch({ "/permissions": EXPECTED_PERMISSIONS });
try {
const res = await fetch("http://localhost/api/permissions");
const data: Permission[] = await res.json();
for (const p of data) {
assertExists(p.id);
assertExists(p.nom);
}
} finally {
restoreFetch();
}
});