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
+68 -19
View File
@@ -33,7 +33,9 @@ Deno.test("mock API: GET /ue-modules?idPromo filters by promo", async () => {
const filtered = ueModules.filter((u) => u.idPromo === "4AFISE25/26");
mockFetch({ "/ue-modules": filtered });
try {
const res = await fetch("http://localhost/api/ue-modules?idPromo=4AFISE25%2F26");
const res = await fetch(
"http://localhost/api/ue-modules?idPromo=4AFISE25%2F26",
);
const data: UeModule[] = await res.json();
assertEquals(data.length, 2);
assertEquals(data.every((u) => u.idPromo === "4AFISE25/26"), true);
@@ -56,8 +58,15 @@ Deno.test("mock API: GET /ue-modules?idUE filters by UE", async () => {
});
Deno.test("mock API: POST /ue-modules creates association (201)", async () => {
const newUeModule: UeModule = { idModule: "JIN705C", idUE: 2, idPromo: "3AFISE25/26", coeff: 3.0 };
mockFetch({ "/ue-modules": { method: "POST", status: 201, body: newUeModule } });
const newUeModule: UeModule = {
idModule: "JIN705C",
idUE: 2,
idPromo: "3AFISE25/26",
coeff: 3.0,
};
mockFetch({
"/ue-modules": { method: "POST", status: 201, body: newUeModule },
});
try {
const res = await fetch("http://localhost/api/ue-modules", {
method: "POST",
@@ -90,7 +99,9 @@ Deno.test("mock API: POST /ue-modules 400 on missing fields", async () => {
Deno.test("mock API: GET /ue-modules/:idModule/:idUE/:idPromo returns association (employee)", async () => {
mockFetch({ "/ue-modules/JIN702C/1/4AFISE25": ueModules[0] });
try {
const res = await fetch("http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26");
const res = await fetch(
"http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26",
);
assertEquals(res.status, 200);
const data: UeModule = await res.json();
assertEquals(data.coeff, 3.0);
@@ -102,7 +113,9 @@ Deno.test("mock API: GET /ue-modules/:idModule/:idUE/:idPromo returns associatio
Deno.test("mock API: GET /ue-modules/:idModule/:idUE/:idPromo 403 for non-employee", async () => {
mockFetch({ "/ue-modules/JIN702C/1/4AFISE25": { status: 403 } });
try {
const res = await fetch("http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26");
const res = await fetch(
"http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26",
);
assertEquals(res.status, 403);
} finally {
restoreFetch();
@@ -111,13 +124,22 @@ Deno.test("mock API: GET /ue-modules/:idModule/:idUE/:idPromo 403 for non-employ
Deno.test("mock API: PUT /ue-modules/:idModule/:idUE/:idPromo updates coeff", async () => {
const updated: UeModule = { ...ueModules[0], coeff: 5.0 };
mockFetch({ "/ue-modules/JIN702C/1/4AFISE25": { method: "PUT", status: 200, body: updated } });
try {
const res = await fetch("http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26", {
mockFetch({
"/ue-modules/JIN702C/1/4AFISE25": {
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify({ coeff: 5.0 }),
});
status: 200,
body: updated,
},
});
try {
const res = await fetch(
"http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26",
{
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify({ coeff: 5.0 }),
},
);
assertEquals(res.status, 200);
const data: UeModule = await res.json();
assertEquals(data.coeff, 5.0);
@@ -127,9 +149,14 @@ Deno.test("mock API: PUT /ue-modules/:idModule/:idUE/:idPromo updates coeff", as
});
Deno.test("mock API: DELETE /ue-modules/:idModule/:idUE/:idPromo returns 204", async () => {
mockFetch({ "/ue-modules/JIN702C/1/4AFISE25": { method: "DELETE", status: 204 } });
mockFetch({
"/ue-modules/JIN702C/1/4AFISE25": { method: "DELETE", status: 204 },
});
try {
const res = await fetch("http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26", { method: "DELETE" });
const res = await fetch(
"http://localhost/api/ue-modules/JIN702C/1/4AFISE25%2F26",
{ method: "DELETE" },
);
assertEquals(res.status, 204);
} finally {
restoreFetch();
@@ -140,34 +167,56 @@ Deno.test("mock API: DELETE /ue-modules/:idModule/:idUE/:idPromo returns 204", a
Deno.test("mock DB: find ue-module by composite key", () => {
const db = createMockDb({ tables: { ueModules: [...ueModules] } });
const u = db.findOne<UeModule>("ueModules", (u) => u.idModule === "JIN702C" && u.idUE === 1 && u.idPromo === "4AFISE25/26");
const u = db.findOne<UeModule>(
"ueModules",
(u) =>
u.idModule === "JIN702C" && u.idUE === 1 && u.idPromo === "4AFISE25/26",
);
assertExists(u);
assertEquals(u.coeff, 3.0);
});
Deno.test("mock DB: filter ue-modules by promo", () => {
const db = createMockDb({ tables: { ueModules: [...ueModules] } });
const rows = db.findMany<UeModule>("ueModules", (u) => u.idPromo === "4AFISE25/26");
const rows = db.findMany<UeModule>(
"ueModules",
(u) => u.idPromo === "4AFISE25/26",
);
assertEquals(rows.length, 2);
});
Deno.test("mock DB: insert ue-module", () => {
const db = createMockDb({ tables: { ueModules: [...ueModules] } });
db.insert<UeModule>("ueModules", { idModule: "JIN705C", idUE: 2, idPromo: "3AFISE25/26", coeff: 1.5 });
db.insert<UeModule>("ueModules", {
idModule: "JIN705C",
idUE: 2,
idPromo: "3AFISE25/26",
coeff: 1.5,
});
assertEquals(db.getTable("ueModules").length, 4);
});
Deno.test("mock DB: update ue-module coeff", () => {
const db = createMockDb({ tables: { ueModules: [...ueModules] } });
db.updateWhere<UeModule>("ueModules", (u) => u.idModule === "JIN702C" && u.idUE === 1, { coeff: 6.0 });
db.updateWhere<UeModule>(
"ueModules",
(u) => u.idModule === "JIN702C" && u.idUE === 1,
{ coeff: 6.0 },
);
assertEquals(
db.findOne<UeModule>("ueModules", (u) => u.idModule === "JIN702C" && u.idUE === 1)?.coeff,
db.findOne<UeModule>(
"ueModules",
(u) => u.idModule === "JIN702C" && u.idUE === 1,
)?.coeff,
6.0,
);
});
Deno.test("mock DB: delete ue-module", () => {
const db = createMockDb({ tables: { ueModules: [...ueModules] } });
db.deleteWhere<UeModule>("ueModules", (u) => u.idModule === "JIN702C" && u.idUE === 1);
db.deleteWhere<UeModule>(
"ueModules",
(u) => u.idModule === "JIN702C" && u.idUE === 1,
);
assertEquals(db.getTable("ueModules").length, 2);
});