chore: formated tests
Check Deno code / Check Deno code (pull_request) Successful in 5s
Tests / Unit tests (pull_request) Successful in 12s
Tests / Integration tests (pull_request) Successful in 1m9s
Check Deno code / Check Deno code (push) Successful in 6s
Tests / Unit tests (push) Successful in 12s
Tests / Integration tests (push) Successful in 1m13s

This commit was merged in pull request #145.
This commit is contained in:
2026-04-26 19:07:15 +02:00
parent b0930b8da2
commit 714486f43c
16 changed files with 699 additions and 176 deletions
+37 -9
View File
@@ -113,7 +113,12 @@ Deno.test("mock API: GET /notes/:numEtud/:idModule returns note", async () => {
});
Deno.test("mock API: GET /notes/:numEtud/:idModule 404 when not found", async () => {
mockFetch({ "/notes/99999/GHOST": { status: 404, body: { error: "Ressource introuvable" } } });
mockFetch({
"/notes/99999/GHOST": {
status: 404,
body: { error: "Ressource introuvable" },
},
});
try {
const res = await fetch("http://localhost/api/notes/99999/GHOST");
assertEquals(res.status, 404);
@@ -124,7 +129,9 @@ Deno.test("mock API: GET /notes/:numEtud/:idModule 404 when not found", async ()
Deno.test("mock API: PUT /notes/:numEtud/:idModule updates note", async () => {
const updated: Note = { ...notes[0], note: 17.0 };
mockFetch({ "/notes/21212006/JIN702C": { method: "PUT", status: 200, body: updated } });
mockFetch({
"/notes/21212006/JIN702C": { method: "PUT", status: 200, body: updated },
});
try {
const res = await fetch("http://localhost/api/notes/21212006/JIN702C", {
method: "PUT",
@@ -142,7 +149,9 @@ Deno.test("mock API: PUT /notes/:numEtud/:idModule updates note", async () => {
Deno.test("mock API: DELETE /notes/:numEtud/:idModule returns 204", async () => {
mockFetch({ "/notes/21212006/JIN702C": { method: "DELETE", status: 204 } });
try {
const res = await fetch("http://localhost/api/notes/21212006/JIN702C", { method: "DELETE" });
const res = await fetch("http://localhost/api/notes/21212006/JIN702C", {
method: "DELETE",
});
assertEquals(res.status, 204);
} finally {
restoreFetch();
@@ -152,7 +161,9 @@ Deno.test("mock API: DELETE /notes/:numEtud/:idModule returns 204", async () =>
Deno.test("mock API: DELETE /notes/:numEtud/:idModule 404 when not found", async () => {
mockFetch({ "/notes/99999/GHOST": { method: "DELETE", status: 404 } });
try {
const res = await fetch("http://localhost/api/notes/99999/GHOST", { method: "DELETE" });
const res = await fetch("http://localhost/api/notes/99999/GHOST", {
method: "DELETE",
});
assertEquals(res.status, 404);
} finally {
restoreFetch();
@@ -163,7 +174,10 @@ Deno.test("mock API: DELETE /notes/:numEtud/:idModule 404 when not found", async
Deno.test("mock DB: find note by composite key", () => {
const db = createMockDb({ tables: { notes: [...notes] } });
const n = db.findOne<Note>("notes", (n) => n.numEtud === 21212006 && n.idModule === "JIN702C");
const n = db.findOne<Note>(
"notes",
(n) => n.numEtud === 21212006 && n.idModule === "JIN702C",
);
assertExists(n);
assertEquals(n.note, 15.5);
});
@@ -176,21 +190,35 @@ Deno.test("mock DB: filter notes by numEtud", () => {
Deno.test("mock DB: insert note", () => {
const db = createMockDb({ tables: { notes: [...notes] } });
db.insert<Note>("notes", { note: 10.0, numEtud: 21212006, idModule: "JIN704C" });
db.insert<Note>("notes", {
note: 10.0,
numEtud: 21212006,
idModule: "JIN704C",
});
assertEquals(db.getTable("notes").length, 5);
});
Deno.test("mock DB: update note value", () => {
const db = createMockDb({ tables: { notes: [...notes] } });
db.updateWhere<Note>("notes", (n) => n.numEtud === 21212006 && n.idModule === "JIN702C", { note: 20.0 });
db.updateWhere<Note>(
"notes",
(n) => n.numEtud === 21212006 && n.idModule === "JIN702C",
{ note: 20.0 },
);
assertEquals(
db.findOne<Note>("notes", (n) => n.numEtud === 21212006 && n.idModule === "JIN702C")?.note,
db.findOne<Note>(
"notes",
(n) => n.numEtud === 21212006 && n.idModule === "JIN702C",
)?.note,
20.0,
);
});
Deno.test("mock DB: delete note", () => {
const db = createMockDb({ tables: { notes: [...notes] } });
db.deleteWhere<Note>("notes", (n) => n.numEtud === 21212006 && n.idModule === "JIN702C");
db.deleteWhere<Note>(
"notes",
(n) => n.numEtud === 21212006 && n.idModule === "JIN702C",
);
assertEquals(db.getTable("notes").length, 3);
});