hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | import { getMyWorkLog } from "../../work"; |
| 3 | import { getUserWorkLog } from "../../work"; |
| 4 | import { postWorkCheckIn } from "../../work"; |
| 5 | import { postWorkCheckOut } from "../../work"; |
| 6 | import { patchWorkEntryById } from "../../work"; |
| 7 | import { deleteWorkEntryById } from "../../work"; |
| 8 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 9 | |
| 10 | describe("work API", () => { |
| 11 | afterEach(() => { |
| 12 | vi.restoreAllMocks(); |
| 13 | }); |
| 14 | |
| 15 | it("getMyWorkLog calls /work/me with pagination", async () => { |
| 16 | const mockPage = { items: [{ id: "w1" }], total: 1 }; |
| 17 | mockFetchSuccess(mockPage); |
| 18 | |
| 19 | const result = await getMyWorkLog({ limit: 10 }); |
| 20 | expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); |
| 21 | |
| 22 | const [url, init] = lastFetchCall(); |
| 23 | expect(url).toBe("/api/work/me?limit=10"); |
| 24 | expect(init?.method).toBe("GET"); |
| 25 | }); |
| 26 | |
| 27 | it("getUserWorkLog calls /work/:id with pagination", async () => { |
| 28 | const mockPage = { items: [{ id: "w1" }], total: 1 }; |
| 29 | mockFetchSuccess(mockPage); |
| 30 | |
| 31 | const result = await getUserWorkLog("u1", { limit: 10 }); |
| 32 | expect(result).toEqual({ ...mockPage, limit: null, offset: 0 }); |
| 33 | |
| 34 | const [url, init] = lastFetchCall(); |
| 35 | expect(url).toBe("/api/work/u1?limit=10"); |
| 36 | expect(init?.method).toBe("GET"); |
| 37 | }); |
| 38 | |
| 39 | it("postWorkCheckIn calls /work/check-in", async () => { |
| 40 | const mockEntry = { id: "w1", check_in: 1000 }; |
| 41 | mockFetchSuccess(mockEntry); |
| 42 | |
| 43 | const result = await postWorkCheckIn(); |
| 44 | expect(result).toEqual(mockEntry); |
| 45 | |
| 46 | const [url, init] = lastFetchCall(); |
| 47 | expect(url).toBe("/api/work/check-in"); |
| 48 | expect(init?.method).toBe("POST"); |
| 49 | }); |
| 50 | |
| 51 | it("postWorkCheckOut calls /work/check-out", async () => { |
| 52 | const mockEntry = { id: "w1", check_out: 2000 }; |
| 53 | mockFetchSuccess(mockEntry); |
| 54 | |
| 55 | const result = await postWorkCheckOut(); |
| 56 | expect(result).toEqual(mockEntry); |
| 57 | |
| 58 | const [url, init] = lastFetchCall(); |
| 59 | expect(url).toBe("/api/work/check-out"); |
| 60 | expect(init?.method).toBe("POST"); |
| 61 | }); |
| 62 | |
| 63 | it("patchWorkEntryById calls /work/:id with updates", async () => { |
| 64 | const mockEntry = { id: "w1", check_out: 2000 }; |
| 65 | mockFetchSuccess(mockEntry); |
| 66 | |
| 67 | const updates = { check_out: 2000 }; |
| 68 | const result = await patchWorkEntryById("w1", updates); |
| 69 | expect(result).toEqual(mockEntry); |
| 70 | |
| 71 | const [url, init] = lastFetchCall(); |
| 72 | expect(url).toBe("/api/work/entries/w1"); |
| 73 | expect(init?.method).toBe("PATCH"); |
| 74 | expect(init?.body).toBe(JSON.stringify(updates)); |
| 75 | }); |
| 76 | |
| 77 | it("deleteWorkEntryById calls /work/:id", async () => { |
| 78 | mockFetch204(); |
| 79 | |
| 80 | await deleteWorkEntryById("w1"); |
| 81 | |
| 82 | const [url, init] = lastFetchCall(); |
| 83 | expect(url).toBe("/api/work/entries/w1"); |
| 84 | expect(init?.method).toBe("DELETE"); |
| 85 | }); |
| 86 | }); |