hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 2 | import { getParentStudents } from "../../parents"; |
| 3 | import { postParentStudent } from "../../parents"; |
| 4 | import { deleteParentStudent } from "../../parents"; |
| 5 | import { getMyStudents } from "../../parents"; |
| 6 | import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 7 | |
| 8 | describe("parents API", () => { |
| 9 | afterEach(() => { |
| 10 | vi.restoreAllMocks(); |
| 11 | }); |
| 12 | |
| 13 | it("getParentStudents calls /users/:id/students with pagination", async () => { |
| 14 | const mockPage = { items: [{ id: "s1" }], total: 1 }; |
| 15 | mockFetchSuccess(mockPage); |
| 16 | |
| 17 | const result = await getParentStudents("u1", { limit: 10 }); |
| 18 | expect(result).toEqual(mockPage); |
| 19 | |
| 20 | const [url, init] = lastFetchCall(); |
| 21 | expect(url).toBe("/api/users/u1/students?limit=10"); |
| 22 | expect(init?.method).toBe("GET"); |
| 23 | }); |
| 24 | |
| 25 | it("postParentStudent calls /users/:id/students", async () => { |
| 26 | const mockStudent = { id: "s1" }; |
| 27 | mockFetchSuccess(mockStudent); |
| 28 | |
| 29 | const result = await postParentStudent("u1", "s1"); |
| 30 | expect(result).toEqual(mockStudent); |
| 31 | |
| 32 | const [url, init] = lastFetchCall(); |
| 33 | expect(url).toBe("/api/users/u1/students"); |
| 34 | expect(init?.method).toBe("POST"); |
| 35 | expect(init?.body).toBe(JSON.stringify({ user_id: "s1" })); |
| 36 | }); |
| 37 | |
| 38 | it("deleteParentStudent calls /users/:id/students/:studentId", async () => { |
| 39 | mockFetch204(); |
| 40 | |
| 41 | await deleteParentStudent("u1", "s1"); |
| 42 | |
| 43 | const [url, init] = lastFetchCall(); |
| 44 | expect(url).toBe("/api/users/u1/students/s1"); |
| 45 | expect(init?.method).toBe("DELETE"); |
| 46 | }); |
| 47 | |
| 48 | it("getMyStudents calls /parents/me/students", async () => { |
| 49 | const mockStudents = [{ id: "s1" }]; |
| 50 | mockFetchSuccess(mockStudents); |
| 51 | |
| 52 | const result = await getMyStudents(); |
| 53 | expect(result).toEqual(mockStudents); |
| 54 | |
| 55 | const [url, init] = lastFetchCall(); |
| 56 | expect(url).toBe("/api/users/me/students"); |
| 57 | expect(init?.method).toBe("GET"); |
| 58 | }); |
| 59 | }); |