6c38cd0019
- Cascade delete on all entities (student, module, UE, user, role, promotion) - Fix Response body reuse bug (factory functions instead of constants) - Student note viewing via CAS uid (strip non-digit prefix) - Fix middleware page visibility for students in LOCAL mode - Import result popup component (shared across all import pages) - Fix student import to use numEtud from Excel - Bulk student selection with promo change and delete - Move UE/UE-Module API and pages from notes to admin module - Move promotions page from students to admin module - Multi-year maquette import with per-year promo selection - Inline promo creation in maquette import - Static Excel templates (students, notes, maquette) - Fix XLSX export using blob download instead of writeFile - Allow students to read modules list (GET /modules)
179 lines
4.4 KiB
TypeScript
179 lines
4.4 KiB
TypeScript
// E2E tests for /ues endpoints — handler + real DB
|
|
|
|
import { assertEquals, assertExists } from "@std/assert";
|
|
import {
|
|
makeEmployeeContext,
|
|
makeGetRequest,
|
|
makeJsonRequest,
|
|
} from "../helpers/handler.ts";
|
|
import { seedUes, truncateAll } from "../helpers/db_integration.ts";
|
|
import { handler as uesHandler } from "$apps/admin/api/ues.ts";
|
|
import { handler as ueHandler } from "$apps/admin/api/ues/[idUE].ts";
|
|
|
|
// --- GET /ues ---
|
|
|
|
Deno.test({
|
|
name: "e2e ues: GET /ues returns all UEs",
|
|
async fn() {
|
|
await truncateAll();
|
|
await seedUes([{ nom: "UE Informatique" }, { nom: "UE Mathématiques" }]);
|
|
const res = await uesHandler.GET!(
|
|
makeGetRequest("/ues"),
|
|
makeEmployeeContext(),
|
|
);
|
|
assertEquals(res.status, 200);
|
|
const body = await res.json();
|
|
assertEquals(body.length, 2);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "e2e ues: GET /ues returns empty when no UEs",
|
|
async fn() {
|
|
await truncateAll();
|
|
const res = await uesHandler.GET!(
|
|
makeGetRequest("/ues"),
|
|
makeEmployeeContext(),
|
|
);
|
|
assertEquals(res.status, 200);
|
|
const body = await res.json();
|
|
assertEquals(body.length, 0);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
// --- POST /ues ---
|
|
|
|
Deno.test({
|
|
name: "e2e ues: POST /ues creates UE (201)",
|
|
async fn() {
|
|
await truncateAll();
|
|
const res = await uesHandler.POST!(
|
|
makeJsonRequest("/ues", "POST", { nom: "UE Physique" }),
|
|
makeEmployeeContext(),
|
|
);
|
|
assertEquals(res.status, 201);
|
|
const body = await res.json();
|
|
assertExists(body.id);
|
|
assertEquals(body.nom, "UE Physique");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "e2e ues: POST /ues 400 on missing nom",
|
|
async fn() {
|
|
await truncateAll();
|
|
const res = await uesHandler.POST!(
|
|
makeJsonRequest("/ues", "POST", {}),
|
|
makeEmployeeContext(),
|
|
);
|
|
assertEquals(res.status, 400);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
// --- GET /ues/:id ---
|
|
|
|
Deno.test({
|
|
name: "e2e ues: GET /ues/:id returns UE",
|
|
async fn() {
|
|
await truncateAll();
|
|
const [ue] = await seedUes([{ nom: "UE Chimie" }]);
|
|
const res = await ueHandler.GET!(
|
|
makeGetRequest(`/ues/${ue.id}`),
|
|
makeEmployeeContext({ idUE: String(ue.id) }),
|
|
);
|
|
assertEquals(res.status, 200);
|
|
const body = await res.json();
|
|
assertEquals(body.nom, "UE Chimie");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "e2e ues: GET /ues/:id 404 when not found",
|
|
async fn() {
|
|
await truncateAll();
|
|
const res = await ueHandler.GET!(
|
|
makeGetRequest("/ues/99999"),
|
|
makeEmployeeContext({ idUE: "99999" }),
|
|
);
|
|
assertEquals(res.status, 404);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
// --- PUT /ues/:id ---
|
|
|
|
Deno.test({
|
|
name: "e2e ues: PUT /ues/:id updates nom",
|
|
async fn() {
|
|
await truncateAll();
|
|
const [ue] = await seedUes([{ nom: "UE Biologie" }]);
|
|
const res = await ueHandler.PUT!(
|
|
makeJsonRequest(`/ues/${ue.id}`, "PUT", {
|
|
nom: "UE Biologie moléculaire",
|
|
}),
|
|
makeEmployeeContext({ idUE: String(ue.id) }),
|
|
);
|
|
assertEquals(res.status, 200);
|
|
const body = await res.json();
|
|
assertEquals(body.nom, "UE Biologie moléculaire");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "e2e ues: PUT /ues/:id 404 when not found",
|
|
async fn() {
|
|
await truncateAll();
|
|
const res = await ueHandler.PUT!(
|
|
makeJsonRequest("/ues/99999", "PUT", { nom: "X" }),
|
|
makeEmployeeContext({ idUE: "99999" }),
|
|
);
|
|
assertEquals(res.status, 404);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
// --- DELETE /ues/:id ---
|
|
|
|
Deno.test({
|
|
name: "e2e ues: DELETE /ues/:id returns 204",
|
|
async fn() {
|
|
await truncateAll();
|
|
const [ue] = await seedUes([{ nom: "UE à supprimer" }]);
|
|
const res = await ueHandler.DELETE!(
|
|
makeGetRequest(`/ues/${ue.id}`),
|
|
makeEmployeeContext({ idUE: String(ue.id) }),
|
|
);
|
|
assertEquals(res.status, 204);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "e2e ues: DELETE /ues/:id 404 when not found",
|
|
async fn() {
|
|
await truncateAll();
|
|
const res = await ueHandler.DELETE!(
|
|
makeGetRequest("/ues/99999"),
|
|
makeEmployeeContext({ idUE: "99999" }),
|
|
);
|
|
assertEquals(res.status, 404);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|