hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | import { getModules } from "../../modules"; |
| 3 | import { getModulesCatalog } from "../../modules"; |
| 4 | import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 5 | |
| 6 | describe("modules API", () => { |
| 7 | afterEach(() => { |
| 8 | vi.restoreAllMocks(); |
| 9 | }); |
| 10 | |
| 11 | it("getModules calls /modules", async () => { |
| 12 | const mockModules = { enabled: ["courses", "meals"] }; |
| 13 | mockFetchSuccess(mockModules); |
| 14 | |
| 15 | const result = await getModules(); |
| 16 | expect(result).toEqual(mockModules); |
| 17 | |
| 18 | const [url, init] = lastFetchCall(); |
| 19 | expect(url).toBe("/api/modules"); |
| 20 | expect(init?.method).toBe("GET"); |
| 21 | }); |
| 22 | |
| 23 | it("getModulesCatalog calls /modules/catalog", async () => { |
| 24 | const mockCatalog = { |
| 25 | modules: [{ module: "exams", package: "academics", requires: ["courses"] }], |
| 26 | packages: [{ package: "academics", modules: ["exams"] }], |
| 27 | }; |
| 28 | mockFetchSuccess(mockCatalog); |
| 29 | |
| 30 | const result = await getModulesCatalog(); |
| 31 | expect(result).toEqual(mockCatalog); |
| 32 | |
| 33 | const [url, init] = lastFetchCall(); |
| 34 | expect(url).toBe("/api/modules/catalog"); |
| 35 | expect(init?.method).toBe("GET"); |
| 36 | }); |
| 37 | }); |