// Integration tests for /ues — Drizzle ORM direct on real DB import { assertEquals, assertExists, assertRejects } from "@std/assert"; import { seedUes, testDb, truncateAll } from "../helpers/db_integration.ts"; import { ues } from "$root/databases/schema.ts"; import { eq } from "npm:drizzle-orm@0.45.2"; Deno.test({ name: "integration ues: list all UEs", async fn() { await truncateAll(); await seedUes([{ nom: "UE Informatique" }, { nom: "UE Mathématiques" }]); const rows = await testDb.select().from(ues); assertEquals(rows.length, 2); }, sanitizeResources: false, sanitizeOps: false, }); Deno.test({ name: "integration ues: create and retrieve by id", async fn() { await truncateAll(); const [created] = await testDb.insert(ues).values({ nom: "UE Physique" }) .returning(); assertExists(created); assertExists(created.id); assertEquals(created.nom, "UE Physique"); const row = await testDb.select().from(ues).where(eq(ues.id, created.id)) .then((r) => r[0] ?? null); assertExists(row); assertEquals(row.nom, "UE Physique"); }, sanitizeResources: false, sanitizeOps: false, }); Deno.test({ name: "integration ues: get by id returns null when not found", async fn() { await truncateAll(); const row = await testDb.select().from(ues).where(eq(ues.id, 99999)).then(( r, ) => r[0] ?? null); assertEquals(row, null); }, sanitizeResources: false, sanitizeOps: false, }); Deno.test({ name: "integration ues: update nom", async fn() { await truncateAll(); const [ue] = await seedUes([{ nom: "UE Chimie" }]); const [updated] = await testDb.update(ues).set({ nom: "UE Chimie organique", }).where(eq(ues.id, ue.id)).returning(); assertEquals(updated.nom, "UE Chimie organique"); }, sanitizeResources: false, sanitizeOps: false, }); Deno.test({ name: "integration ues: delete removes the UE", async fn() { await truncateAll(); const [ue] = await seedUes([{ nom: "UE à supprimer" }]); await testDb.delete(ues).where(eq(ues.id, ue.id)); const row = await testDb.select().from(ues).where(eq(ues.id, ue.id)).then(( r, ) => r[0] ?? null); assertEquals(row, null); }, sanitizeResources: false, sanitizeOps: false, }); Deno.test({ name: "integration ues: nom is required (not null)", async fn() { await truncateAll(); // deno-lint-ignore no-explicit-any await assertRejects(() => testDb.insert(ues).values({ nom: null as any })); }, sanitizeResources: false, sanitizeOps: false, });