forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

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

holidays.test.ts65 lines, 2.2 KiBHistoryRawDownload
1import { afterEach, describe, expect, it, vi } from "vitest";
2import {
3 deleteHolidayById,
4 getHolidayById,
5 getHolidays,
6 patchHolidayById,
7 postHoliday,
8} from "../../holidays";
9import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch";
10
11describe("holidays API", () => {
12 afterEach(() => {
13 vi.restoreAllMocks();
14 });
15
16 it("getHolidays GETs /holidays with paging and the overlap window", async () => {
17 mockFetchSuccess({ items: [], total: 0 });
18 await getHolidays({ limit: 50, offset: 0, from: 1000, to: 2000 });
19 const [url, init] = lastFetchCall();
20 expect(url).toBe("/api/holidays?limit=50&offset=0&from=1000&to=2000");
21 expect(init?.method).toBe("GET");
22 });
23
24 it("getHolidays sends no query when unfiltered", async () => {
25 mockFetchSuccess({ items: [], total: 0 });
26 await getHolidays();
27 const [url, init] = lastFetchCall();
28 expect(url).toBe("/api/holidays");
29 expect(init?.method).toBe("GET");
30 });
31
32 it("getHolidayById GETs /holidays/h1", async () => {
33 mockFetchSuccess({ id: "x1" });
34 await getHolidayById("h1");
35 const [url, init] = lastFetchCall();
36 expect(url).toBe("/api/holidays/h1");
37 expect(init?.method).toBe("GET");
38 });
39
40 it("postHoliday POSTs /holidays", async () => {
41 mockFetchSuccess({ id: "x1" });
42 await postHoliday({ name: "29 Ekim", kind: "resmi", starts_at: 1, ends_at: 2 });
43 const [url, init] = lastFetchCall();
44 expect(url).toBe("/api/holidays");
45 expect(init?.method).toBe("POST");
46 expect(init?.body).toBe(JSON.stringify({ name: "29 Ekim", kind: "resmi", starts_at: 1, ends_at: 2 }));
47 });
48
49 it("patchHolidayById PATCHs /holidays/h1", async () => {
50 mockFetchSuccess({ id: "x1" });
51 await patchHolidayById("h1", { name: "Ara tatil" });
52 const [url, init] = lastFetchCall();
53 expect(url).toBe("/api/holidays/h1");
54 expect(init?.method).toBe("PATCH");
55 expect(init?.body).toBe(JSON.stringify({ name: "Ara tatil" }));
56 });
57
58 it("deleteHolidayById DELETEs /holidays/h1", async () => {
59 mockFetch204();
60 await deleteHolidayById("h1");
61 const [url, init] = lastFetchCall();
62 expect(url).toBe("/api/holidays/h1");
63 expect(init?.method).toBe("DELETE");
64 });
65});