c5018d9ced
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>
123 lines
2.9 KiB
TypeScript
123 lines
2.9 KiB
TypeScript
import { assertEquals, assertExists } from "@std/assert";
|
|
import {
|
|
seedPromotions,
|
|
testDb,
|
|
truncateAll,
|
|
} from "../helpers/db_integration.ts";
|
|
import { promotions } from "$root/databases/schema.ts";
|
|
import { eq } from "npm:drizzle-orm@0.45.2";
|
|
|
|
Deno.test({
|
|
name: "integration: GET /promotions - returns all promotions",
|
|
async fn() {
|
|
await truncateAll();
|
|
await seedPromotions([
|
|
{ id: "PEIP1-2024", annee: "2024" },
|
|
{ id: "PEIP2-2024", annee: "2024" },
|
|
]);
|
|
|
|
const rows = await testDb.select().from(promotions);
|
|
assertEquals(rows.length, 2);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: POST /promotions - creates a promotion",
|
|
async fn() {
|
|
await truncateAll();
|
|
|
|
const [created] = await testDb
|
|
.insert(promotions)
|
|
.values({ id: "PEIP1-2025", annee: "2025" })
|
|
.returning();
|
|
|
|
assertExists(created);
|
|
assertEquals(created.id, "PEIP1-2025");
|
|
assertEquals(created.annee, "2025");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: GET /promotions/:id - returns a specific promotion",
|
|
async fn() {
|
|
await truncateAll();
|
|
await seedPromotions([{ id: "INFO3-2024", annee: "2024" }]);
|
|
|
|
const row = await testDb
|
|
.select()
|
|
.from(promotions)
|
|
.where(eq(promotions.id, "INFO3-2024"))
|
|
.then((r) => r[0] ?? null);
|
|
|
|
assertExists(row);
|
|
assertEquals(row.id, "INFO3-2024");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: GET /promotions/:id - returns null when not found",
|
|
async fn() {
|
|
await truncateAll();
|
|
|
|
const row = await testDb
|
|
.select()
|
|
.from(promotions)
|
|
.where(eq(promotions.id, "NONEXISTENT"))
|
|
.then((r) => r[0] ?? null);
|
|
|
|
assertEquals(row, null);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: PUT /promotions/:id - updates a promotion",
|
|
async fn() {
|
|
await truncateAll();
|
|
await seedPromotions([{ id: "INFO3-2023", annee: "2023" }]);
|
|
|
|
const [updated] = await testDb
|
|
.update(promotions)
|
|
.set({ annee: "2024" })
|
|
.where(eq(promotions.id, "INFO3-2023"))
|
|
.returning();
|
|
|
|
assertExists(updated);
|
|
assertEquals(updated.annee, "2024");
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|
|
|
|
Deno.test({
|
|
name: "integration: DELETE /promotions/:id - deletes a promotion",
|
|
async fn() {
|
|
await truncateAll();
|
|
await seedPromotions([{ id: "INFO3-2022", annee: "2022" }]);
|
|
|
|
const [deleted] = await testDb
|
|
.delete(promotions)
|
|
.where(eq(promotions.id, "INFO3-2022"))
|
|
.returning();
|
|
|
|
assertExists(deleted);
|
|
|
|
const row = await testDb
|
|
.select()
|
|
.from(promotions)
|
|
.where(eq(promotions.id, "INFO3-2022"))
|
|
.then((r) => r[0] ?? null);
|
|
|
|
assertEquals(row, null);
|
|
},
|
|
sanitizeResources: false,
|
|
sanitizeOps: false,
|
|
});
|