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 { getBuilderMe } from "../../builder"; |
| 3 | import { postBuilderLogin } from "../../builder"; |
| 4 | import { postBuilderLogout } from "../../builder"; |
| 5 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 6 | |
| 7 | describe("builder API", () => { |
| 8 | afterEach(() => { |
| 9 | vi.restoreAllMocks(); |
| 10 | }); |
| 11 | |
| 12 | it("postBuilderLogin posts credentials to /builder/login", async () => { |
| 13 | const builder = { id: "b1", username: "operator" }; |
| 14 | mockFetchSuccess(builder); |
| 15 | |
| 16 | const result = await postBuilderLogin({ username: "operator", password: "correct horse" }); |
| 17 | expect(result).toEqual(builder); |
| 18 | |
| 19 | const [url, init] = lastFetchCall(); |
| 20 | expect(url).toBe("/api/builder/login"); |
| 21 | expect(init?.method).toBe("POST"); |
| 22 | expect(init?.body).toBe(JSON.stringify({ username: "operator", password: "correct horse" })); |
| 23 | }); |
| 24 | |
| 25 | it("postBuilderLogout posts to /builder/logout", async () => { |
| 26 | mockFetch204(); |
| 27 | |
| 28 | await postBuilderLogout(); |
| 29 | |
| 30 | const [url, init] = lastFetchCall(); |
| 31 | expect(url).toBe("/api/builder/logout"); |
| 32 | expect(init?.method).toBe("POST"); |
| 33 | }); |
| 34 | |
| 35 | it("getBuilderMe reads /builder/me", async () => { |
| 36 | mockFetchSuccess({ id: "b1", username: "operator" }); |
| 37 | |
| 38 | await getBuilderMe(); |
| 39 | |
| 40 | const [url, init] = lastFetchCall(); |
| 41 | expect(url).toBe("/api/builder/me"); |
| 42 | expect(init?.method).toBe("GET"); |
| 43 | }); |
| 44 | }); |