forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

work.test.ts86 lines, 2.8 KiBHistoryRawDownload
1import { afterEach, describe, expect, it, vi } from "vitest";
2import { getMyWorkLog } from "../../work";
3import { getUserWorkLog } from "../../work";
4import { postWorkCheckIn } from "../../work";
5import { postWorkCheckOut } from "../../work";
6import { patchWorkEntryById } from "../../work";
7import { deleteWorkEntryById } from "../../work";
8import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
9
10describe("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});