Compare commits
2 Commits
61207e4f21
...
080f7606a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 080f7606a7 | |||
| 4e220f72d7 |
@@ -29,7 +29,7 @@ export function mockFetch(
|
|||||||
_originalFetch = globalThis.fetch;
|
_originalFetch = globalThis.fetch;
|
||||||
_calls = [];
|
_calls = [];
|
||||||
|
|
||||||
globalThis.fetch = async (
|
globalThis.fetch = (
|
||||||
input: string | URL | Request,
|
input: string | URL | Request,
|
||||||
init?: RequestInit,
|
init?: RequestInit,
|
||||||
): Promise<Response> => {
|
): Promise<Response> => {
|
||||||
@@ -106,7 +106,11 @@ export function restoreFetch(): void {
|
|||||||
/**
|
/**
|
||||||
* Retourne la liste des appels fetch interceptés.
|
* Retourne la liste des appels fetch interceptés.
|
||||||
*/
|
*/
|
||||||
export function getFetchCalls(): { url: string; method: string; body?: unknown }[] {
|
export function getFetchCalls(): {
|
||||||
|
url: string;
|
||||||
|
method: string;
|
||||||
|
body?: unknown;
|
||||||
|
}[] {
|
||||||
return [..._calls];
|
return [..._calls];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
import { assertEquals, assertExists } from "@std/assert";
|
import { assertEquals, assertExists } from "@std/assert";
|
||||||
import {
|
import { getFetchCalls, mockFetch, restoreFetch } from "../helpers/api_mock.ts";
|
||||||
getFetchCalls,
|
|
||||||
mockFetch,
|
|
||||||
restoreFetch,
|
|
||||||
} from "../helpers/api_mock.ts";
|
|
||||||
import { createMockDb } from "../helpers/db_mock.ts";
|
import { createMockDb } from "../helpers/db_mock.ts";
|
||||||
import {
|
import {
|
||||||
type Student,
|
|
||||||
ERROR_CONFLICT,
|
ERROR_CONFLICT,
|
||||||
ERROR_NOT_FOUND,
|
ERROR_NOT_FOUND,
|
||||||
modules,
|
modules,
|
||||||
notes,
|
notes,
|
||||||
|
type Student,
|
||||||
students,
|
students,
|
||||||
} from "../helpers/fixtures.ts";
|
} from "../helpers/fixtures.ts";
|
||||||
import { cleanupDOM, setupDOM } from "../helpers/render.ts";
|
import { cleanupDOM, setupDOM } from "../helpers/render.ts";
|
||||||
@@ -116,7 +112,11 @@ Deno.test("mockFetch - 409 conflict", async () => {
|
|||||||
try {
|
try {
|
||||||
const res = await fetch("http://localhost/api/enseignements", {
|
const res = await fetch("http://localhost/api/enseignements", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ idProf: 1, idModule: "JIN702C", idPromo: "4AFISE25/26" }),
|
body: JSON.stringify({
|
||||||
|
idProf: 1,
|
||||||
|
idModule: "JIN702C",
|
||||||
|
idPromo: "4AFISE25/26",
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
assertEquals(res.status, 409);
|
assertEquals(res.status, 409);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user