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
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:
@@ -32,7 +32,9 @@ Deno.test("mock API: GET /ajustements?numEtud filters by student", async () => {
|
||||
const filtered = ajustements.filter((a) => a.numEtud === 21212006);
|
||||
mockFetch({ "/ajustements": filtered });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ajustements?numEtud=21212006");
|
||||
const res = await fetch(
|
||||
"http://localhost/api/ajustements?numEtud=21212006",
|
||||
);
|
||||
const data: Ajustement[] = await res.json();
|
||||
assertEquals(data.length, 1);
|
||||
assertEquals(data[0].numEtud, 21212006);
|
||||
@@ -53,7 +55,9 @@ Deno.test("mock API: GET /ajustements?numEtud=NaN returns 400", async () => {
|
||||
|
||||
Deno.test("mock API: POST /ajustements creates ajustement (201) as employee", async () => {
|
||||
const newAjust: Ajustement = { numEtud: 21212007, idUE: 2, valeur: 14.0 };
|
||||
mockFetch({ "/ajustements": { method: "POST", status: 201, body: newAjust } });
|
||||
mockFetch({
|
||||
"/ajustements": { method: "POST", status: 201, body: newAjust },
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ajustements", {
|
||||
method: "POST",
|
||||
@@ -72,7 +76,9 @@ Deno.test("mock API: POST /ajustements creates ajustement (201) as employee", as
|
||||
Deno.test("mock API: POST /ajustements 403 for non-employee", async () => {
|
||||
mockFetch({ "/ajustements": { method: "POST", status: 403 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ajustements", { method: "POST" });
|
||||
const res = await fetch("http://localhost/api/ajustements", {
|
||||
method: "POST",
|
||||
});
|
||||
assertEquals(res.status, 403);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -116,7 +122,12 @@ Deno.test("mock API: GET /ajustements/:numEtud/:idUE 403 for non-employee", asyn
|
||||
});
|
||||
|
||||
Deno.test("mock API: GET /ajustements/:numEtud/:idUE 404 when not found", async () => {
|
||||
mockFetch({ "/ajustements/99999/9": { status: 404, body: { error: "Ajustement introuvable" } } });
|
||||
mockFetch({
|
||||
"/ajustements/99999/9": {
|
||||
status: 404,
|
||||
body: { error: "Ajustement introuvable" },
|
||||
},
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ajustements/99999/9");
|
||||
assertEquals(res.status, 404);
|
||||
@@ -127,7 +138,9 @@ Deno.test("mock API: GET /ajustements/:numEtud/:idUE 404 when not found", async
|
||||
|
||||
Deno.test("mock API: PUT /ajustements/:numEtud/:idUE updates valeur", async () => {
|
||||
const updated: Ajustement = { ...ajustements[0], valeur: 18.0 };
|
||||
mockFetch({ "/ajustements/21212006/1": { method: "PUT", status: 200, body: updated } });
|
||||
mockFetch({
|
||||
"/ajustements/21212006/1": { method: "PUT", status: 200, body: updated },
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ajustements/21212006/1", {
|
||||
method: "PUT",
|
||||
@@ -145,7 +158,9 @@ Deno.test("mock API: PUT /ajustements/:numEtud/:idUE updates valeur", async () =
|
||||
Deno.test("mock API: DELETE /ajustements/:numEtud/:idUE returns 204", async () => {
|
||||
mockFetch({ "/ajustements/21212006/1": { method: "DELETE", status: 204 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ajustements/21212006/1", { method: "DELETE" });
|
||||
const res = await fetch("http://localhost/api/ajustements/21212006/1", {
|
||||
method: "DELETE",
|
||||
});
|
||||
assertEquals(res.status, 204);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -156,34 +171,54 @@ Deno.test("mock API: DELETE /ajustements/:numEtud/:idUE returns 204", async () =
|
||||
|
||||
Deno.test("mock DB: find ajustement by composite key", () => {
|
||||
const db = createMockDb({ tables: { ajustements: [...ajustements] } });
|
||||
const a = db.findOne<Ajustement>("ajustements", (a) => a.numEtud === 21212006 && a.idUE === 1);
|
||||
const a = db.findOne<Ajustement>(
|
||||
"ajustements",
|
||||
(a) => a.numEtud === 21212006 && a.idUE === 1,
|
||||
);
|
||||
assertExists(a);
|
||||
assertEquals(a.valeur, 13.25);
|
||||
});
|
||||
|
||||
Deno.test("mock DB: filter ajustements by numEtud", () => {
|
||||
const db = createMockDb({ tables: { ajustements: [...ajustements] } });
|
||||
const rows = db.findMany<Ajustement>("ajustements", (a) => a.numEtud === 21212006);
|
||||
const rows = db.findMany<Ajustement>(
|
||||
"ajustements",
|
||||
(a) => a.numEtud === 21212006,
|
||||
);
|
||||
assertEquals(rows.length, 1);
|
||||
});
|
||||
|
||||
Deno.test("mock DB: insert ajustement", () => {
|
||||
const db = createMockDb({ tables: { ajustements: [...ajustements] } });
|
||||
db.insert<Ajustement>("ajustements", { numEtud: 21212007, idUE: 2, valeur: 14.0 });
|
||||
db.insert<Ajustement>("ajustements", {
|
||||
numEtud: 21212007,
|
||||
idUE: 2,
|
||||
valeur: 14.0,
|
||||
});
|
||||
assertEquals(db.getTable("ajustements").length, 3);
|
||||
});
|
||||
|
||||
Deno.test("mock DB: update ajustement valeur", () => {
|
||||
const db = createMockDb({ tables: { ajustements: [...ajustements] } });
|
||||
db.updateWhere<Ajustement>("ajustements", (a) => a.numEtud === 21212006 && a.idUE === 1, { valeur: 20.0 });
|
||||
db.updateWhere<Ajustement>(
|
||||
"ajustements",
|
||||
(a) => a.numEtud === 21212006 && a.idUE === 1,
|
||||
{ valeur: 20.0 },
|
||||
);
|
||||
assertEquals(
|
||||
db.findOne<Ajustement>("ajustements", (a) => a.numEtud === 21212006 && a.idUE === 1)?.valeur,
|
||||
db.findOne<Ajustement>(
|
||||
"ajustements",
|
||||
(a) => a.numEtud === 21212006 && a.idUE === 1,
|
||||
)?.valeur,
|
||||
20.0,
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("mock DB: delete ajustement", () => {
|
||||
const db = createMockDb({ tables: { ajustements: [...ajustements] } });
|
||||
db.deleteWhere<Ajustement>("ajustements", (a) => a.numEtud === 21212006 && a.idUE === 1);
|
||||
db.deleteWhere<Ajustement>(
|
||||
"ajustements",
|
||||
(a) => a.numEtud === 21212006 && a.idUE === 1,
|
||||
);
|
||||
assertEquals(db.getTable("ajustements").length, 1);
|
||||
});
|
||||
|
||||
@@ -22,8 +22,14 @@ Deno.test("enseignements: fixtures have correct shape", () => {
|
||||
// --- Mock API ---
|
||||
|
||||
Deno.test("mock API: POST /enseignements creates enseignement (201) as employee", async () => {
|
||||
const newEns: Enseignement = { idProf: "prof.dupont", idModule: "JIN702C", idPromo: "4AFISE25/26" };
|
||||
mockFetch({ "/enseignements": { method: "POST", status: 201, body: newEns } });
|
||||
const newEns: Enseignement = {
|
||||
idProf: "prof.dupont",
|
||||
idModule: "JIN702C",
|
||||
idPromo: "4AFISE25/26",
|
||||
};
|
||||
mockFetch({
|
||||
"/enseignements": { method: "POST", status: 201, body: newEns },
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements", {
|
||||
method: "POST",
|
||||
@@ -41,7 +47,9 @@ Deno.test("mock API: POST /enseignements creates enseignement (201) as employee"
|
||||
Deno.test("mock API: POST /enseignements 403 for non-employee", async () => {
|
||||
mockFetch({ "/enseignements": { method: "POST", status: 403 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements", { method: "POST" });
|
||||
const res = await fetch("http://localhost/api/enseignements", {
|
||||
method: "POST",
|
||||
});
|
||||
assertEquals(res.status, 403);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -64,13 +72,21 @@ Deno.test("mock API: POST /enseignements 400 on missing fields", async () => {
|
||||
|
||||
Deno.test("mock API: POST /enseignements 409 on duplicate", async () => {
|
||||
mockFetch({
|
||||
"/enseignements": { method: "POST", status: 409, body: { error: "Cet enseignement existe déjà." } },
|
||||
"/enseignements": {
|
||||
method: "POST",
|
||||
status: 409,
|
||||
body: { error: "Cet enseignement existe déjà." },
|
||||
},
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ idProf: "prof.dupont", idModule: "JIN702C", idPromo: "4AFISE25/26" }),
|
||||
body: JSON.stringify({
|
||||
idProf: "prof.dupont",
|
||||
idModule: "JIN702C",
|
||||
idPromo: "4AFISE25/26",
|
||||
}),
|
||||
});
|
||||
assertEquals(res.status, 409);
|
||||
const data = await res.json();
|
||||
@@ -81,10 +97,16 @@ Deno.test("mock API: POST /enseignements 409 on duplicate", async () => {
|
||||
});
|
||||
|
||||
Deno.test("mock API: GET /enseignements/:idProf/:idModule/:idPromo returns enseignement (employee)", async () => {
|
||||
const ens: Enseignement = { idProf: "prof.dupont", idModule: "JIN702C", idPromo: "4AFISE25/26" };
|
||||
const ens: Enseignement = {
|
||||
idProf: "prof.dupont",
|
||||
idModule: "JIN702C",
|
||||
idPromo: "4AFISE25/26",
|
||||
};
|
||||
mockFetch({ "/enseignements/prof.dupont/JIN702C/4AFISE25": ens });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26");
|
||||
const res = await fetch(
|
||||
"http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26",
|
||||
);
|
||||
assertEquals(res.status, 200);
|
||||
const data: Enseignement = await res.json();
|
||||
assertEquals(data.idProf, "prof.dupont");
|
||||
@@ -97,7 +119,9 @@ Deno.test("mock API: GET /enseignements/:idProf/:idModule/:idPromo returns ensei
|
||||
Deno.test("mock API: GET /enseignements/:idProf/:idModule/:idPromo 403 for non-employee", async () => {
|
||||
mockFetch({ "/enseignements/prof.dupont/JIN702C/4AFISE25": { status: 403 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26");
|
||||
const res = await fetch(
|
||||
"http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26",
|
||||
);
|
||||
assertEquals(res.status, 403);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -105,9 +129,16 @@ Deno.test("mock API: GET /enseignements/:idProf/:idModule/:idPromo 403 for non-e
|
||||
});
|
||||
|
||||
Deno.test("mock API: GET /enseignements/:idProf/:idModule/:idPromo 404 when not found", async () => {
|
||||
mockFetch({ "/enseignements/ghost/GHOST/GHOST": { status: 404, body: { error: "Ressource introuvable" } } });
|
||||
mockFetch({
|
||||
"/enseignements/ghost/GHOST/GHOST": {
|
||||
status: 404,
|
||||
body: { error: "Ressource introuvable" },
|
||||
},
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements/ghost/GHOST/GHOST");
|
||||
const res = await fetch(
|
||||
"http://localhost/api/enseignements/ghost/GHOST/GHOST",
|
||||
);
|
||||
assertEquals(res.status, 404);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -115,11 +146,19 @@ Deno.test("mock API: GET /enseignements/:idProf/:idModule/:idPromo 404 when not
|
||||
});
|
||||
|
||||
Deno.test("mock API: DELETE /enseignements/:idProf/:idModule/:idPromo returns 204 (employee)", async () => {
|
||||
mockFetch({ "/enseignements/prof.dupont/JIN702C/4AFISE25": { method: "DELETE", status: 204 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26", {
|
||||
mockFetch({
|
||||
"/enseignements/prof.dupont/JIN702C/4AFISE25": {
|
||||
method: "DELETE",
|
||||
});
|
||||
status: 204,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const res = await fetch(
|
||||
"http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26",
|
||||
{
|
||||
method: "DELETE",
|
||||
},
|
||||
);
|
||||
assertEquals(res.status, 204);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -127,11 +166,19 @@ Deno.test("mock API: DELETE /enseignements/:idProf/:idModule/:idPromo returns 20
|
||||
});
|
||||
|
||||
Deno.test("mock API: DELETE /enseignements/:idProf/:idModule/:idPromo 403 for non-employee", async () => {
|
||||
mockFetch({ "/enseignements/prof.dupont/JIN702C/4AFISE25": { method: "DELETE", status: 403 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26", {
|
||||
mockFetch({
|
||||
"/enseignements/prof.dupont/JIN702C/4AFISE25": {
|
||||
method: "DELETE",
|
||||
});
|
||||
status: 403,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const res = await fetch(
|
||||
"http://localhost/api/enseignements/prof.dupont/JIN702C/4AFISE25%2F26",
|
||||
{
|
||||
method: "DELETE",
|
||||
},
|
||||
);
|
||||
assertEquals(res.status, 403);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
@@ -146,14 +193,21 @@ Deno.test("mock DB: find enseignement by composite key", () => {
|
||||
{ idProf: "prof.moreau", idModule: "JIN703C", idPromo: "4AFISE25/26" },
|
||||
];
|
||||
const db = createMockDb({ tables: { enseignements: data } });
|
||||
const e = db.findOne<Enseignement>("enseignements", (e) => e.idProf === "prof.dupont" && e.idModule === "JIN702C");
|
||||
const e = db.findOne<Enseignement>(
|
||||
"enseignements",
|
||||
(e) => e.idProf === "prof.dupont" && e.idModule === "JIN702C",
|
||||
);
|
||||
assertExists(e);
|
||||
assertEquals(e.idPromo, "4AFISE25/26");
|
||||
});
|
||||
|
||||
Deno.test("mock DB: insert enseignement", () => {
|
||||
const db = createMockDb({ tables: { enseignements: [] } });
|
||||
db.insert<Enseignement>("enseignements", { idProf: "prof.dupont", idModule: "JIN702C", idPromo: "4AFISE25/26" });
|
||||
db.insert<Enseignement>("enseignements", {
|
||||
idProf: "prof.dupont",
|
||||
idModule: "JIN702C",
|
||||
idPromo: "4AFISE25/26",
|
||||
});
|
||||
assertEquals(db.getTable("enseignements").length, 1);
|
||||
});
|
||||
|
||||
@@ -163,7 +217,10 @@ Deno.test("mock DB: delete enseignement", () => {
|
||||
{ idProf: "prof.moreau", idModule: "JIN703C", idPromo: "4AFISE25/26" },
|
||||
];
|
||||
const db = createMockDb({ tables: { enseignements: data } });
|
||||
db.deleteWhere<Enseignement>("enseignements", (e) => e.idProf === "prof.dupont");
|
||||
db.deleteWhere<Enseignement>(
|
||||
"enseignements",
|
||||
(e) => e.idProf === "prof.dupont",
|
||||
);
|
||||
assertEquals(db.getTable("enseignements").length, 1);
|
||||
});
|
||||
|
||||
@@ -174,6 +231,9 @@ Deno.test("mock DB: filter enseignements by idModule", () => {
|
||||
{ idProf: "prof.moreau", idModule: "JIN703C", idPromo: "4AFISE25/26" },
|
||||
];
|
||||
const db = createMockDb({ tables: { enseignements: data } });
|
||||
const rows = db.findMany<Enseignement>("enseignements", (e) => e.idModule === "JIN702C");
|
||||
const rows = db.findMany<Enseignement>(
|
||||
"enseignements",
|
||||
(e) => e.idModule === "JIN702C",
|
||||
);
|
||||
assertEquals(rows.length, 2);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -42,7 +42,9 @@ Deno.test("mock API: GET /ues/:id returns one UE", async () => {
|
||||
});
|
||||
|
||||
Deno.test("mock API: GET /ues/:id 404 when not found", async () => {
|
||||
mockFetch({ "/ues/99": { status: 404, body: { error: "Ressource introuvable" } } });
|
||||
mockFetch({
|
||||
"/ues/99": { status: 404, body: { error: "Ressource introuvable" } },
|
||||
});
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ues/99");
|
||||
assertEquals(res.status, 404);
|
||||
@@ -125,7 +127,9 @@ Deno.test("mock API: DELETE /ues/:id returns 204", async () => {
|
||||
Deno.test("mock API: DELETE /ues/:id 404 when not found", async () => {
|
||||
mockFetch({ "/ues/99": { method: "DELETE", status: 404 } });
|
||||
try {
|
||||
const res = await fetch("http://localhost/api/ues/99", { method: "DELETE" });
|
||||
const res = await fetch("http://localhost/api/ues/99", {
|
||||
method: "DELETE",
|
||||
});
|
||||
assertEquals(res.status, 404);
|
||||
} finally {
|
||||
restoreFetch();
|
||||
|
||||
Reference in New Issue
Block a user