test: add full test coverage for notes, ues, ue-modules, ajustements, enseignements, users
- Unit tests (mock DB + API) for all missing endpoints - Integration tests (Drizzle direct) for all missing entities - E2E tests (handler + real DB) for all missing endpoints - Robustness tests: invalid inputs, SQL injection, type errors, business rule violations - Seed helpers: seedNotes, seedUeModules, seedEnseignements, seedAjustements - Add test:coverage and test:coverage:html tasks to deno.json Tests expose known handler bugs (marked [BUG] in test names): - ajustements PUT/DELETE: .where() without and() modifies all rows for student - Missing try/catch in modules, users, enseignements handlers - Whitespace accepted as valid string values - No type or business rule validation (note bounds, coeff >= 0)
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
// Integration tests for /enseignements — Drizzle ORM direct on real DB
|
||||
|
||||
import { assertEquals, assertExists, assertRejects } from "@std/assert";
|
||||
import {
|
||||
seedEnseignements,
|
||||
seedModules,
|
||||
seedPromotions,
|
||||
seedUsers,
|
||||
testDb,
|
||||
truncateAll,
|
||||
} from "../helpers/db_integration.ts";
|
||||
import { enseignements } from "$root/databases/schema.ts";
|
||||
import { and, eq } from "npm:drizzle-orm@0.45.2";
|
||||
|
||||
Deno.test({
|
||||
name: "integration enseignements: list all enseignements",
|
||||
async fn() {
|
||||
await truncateAll();
|
||||
await seedUsers([{ id: "prof.dupont", nom: "Dupont", prenom: "Jean" }]);
|
||||
await seedModules([{ id: "M1", nom: "Mod A" }, { id: "M2", nom: "Mod B" }]);
|
||||
await seedPromotions([{ id: "P1" }]);
|
||||
await seedEnseignements([
|
||||
{ idProf: "prof.dupont", idModule: "M1", idPromo: "P1" },
|
||||
{ idProf: "prof.dupont", idModule: "M2", idPromo: "P1" },
|
||||
]);
|
||||
const rows = await testDb.select().from(enseignements);
|
||||
assertEquals(rows.length, 2);
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "integration enseignements: create and retrieve by composite key",
|
||||
async fn() {
|
||||
await truncateAll();
|
||||
await seedUsers([{ id: "prof.moreau", nom: "Moreau", prenom: "Sophie" }]);
|
||||
await seedModules([{ id: "M1", nom: "Mod A" }]);
|
||||
await seedPromotions([{ id: "P1" }]);
|
||||
|
||||
const [created] = await testDb
|
||||
.insert(enseignements)
|
||||
.values({ idProf: "prof.moreau", idModule: "M1", idPromo: "P1" })
|
||||
.returning();
|
||||
assertExists(created);
|
||||
assertEquals(created.idProf, "prof.moreau");
|
||||
|
||||
const row = await testDb
|
||||
.select()
|
||||
.from(enseignements)
|
||||
.where(
|
||||
and(
|
||||
eq(enseignements.idProf, "prof.moreau"),
|
||||
eq(enseignements.idModule, "M1"),
|
||||
eq(enseignements.idPromo, "P1"),
|
||||
),
|
||||
)
|
||||
.then((r) => r[0] ?? null);
|
||||
assertExists(row);
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "integration enseignements: get by composite key returns null when not found",
|
||||
async fn() {
|
||||
await truncateAll();
|
||||
const row = await testDb
|
||||
.select()
|
||||
.from(enseignements)
|
||||
.where(
|
||||
and(
|
||||
eq(enseignements.idProf, "ghost"),
|
||||
eq(enseignements.idModule, "GHOST"),
|
||||
eq(enseignements.idPromo, "GHOST"),
|
||||
),
|
||||
)
|
||||
.then((r) => r[0] ?? null);
|
||||
assertEquals(row, null);
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "integration enseignements: duplicate composite key insert fails",
|
||||
async fn() {
|
||||
await truncateAll();
|
||||
await seedUsers([{ id: "prof.dupont", nom: "Dupont", prenom: "Jean" }]);
|
||||
await seedModules([{ id: "M1", nom: "Mod A" }]);
|
||||
await seedPromotions([{ id: "P1" }]);
|
||||
await seedEnseignements([{ idProf: "prof.dupont", idModule: "M1", idPromo: "P1" }]);
|
||||
await assertRejects(() =>
|
||||
testDb.insert(enseignements).values({ idProf: "prof.dupont", idModule: "M1", idPromo: "P1" })
|
||||
);
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "integration enseignements: delete removes the enseignement",
|
||||
async fn() {
|
||||
await truncateAll();
|
||||
await seedUsers([{ id: "prof.dupont", nom: "Dupont", prenom: "Jean" }]);
|
||||
await seedModules([{ id: "M1", nom: "Mod A" }]);
|
||||
await seedPromotions([{ id: "P1" }]);
|
||||
await seedEnseignements([{ idProf: "prof.dupont", idModule: "M1", idPromo: "P1" }]);
|
||||
|
||||
await testDb
|
||||
.delete(enseignements)
|
||||
.where(
|
||||
and(
|
||||
eq(enseignements.idProf, "prof.dupont"),
|
||||
eq(enseignements.idModule, "M1"),
|
||||
eq(enseignements.idPromo, "P1"),
|
||||
),
|
||||
);
|
||||
const row = await testDb
|
||||
.select()
|
||||
.from(enseignements)
|
||||
.where(
|
||||
and(
|
||||
eq(enseignements.idProf, "prof.dupont"),
|
||||
eq(enseignements.idModule, "M1"),
|
||||
eq(enseignements.idPromo, "P1"),
|
||||
),
|
||||
)
|
||||
.then((r) => r[0] ?? null);
|
||||
assertEquals(row, null);
|
||||
},
|
||||
sanitizeResources: false,
|
||||
sanitizeOps: false,
|
||||
});
|
||||
Reference in New Issue
Block a user