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 { getMyCourses } from "../../reports"; |
| 3 | import { getMyAttendance } from "../../reports"; |
| 4 | import { getMyMarks } from "../../reports"; |
| 5 | import { getUserAttendance } from "../../reports"; |
| 6 | import { getUserMarks } from "../../reports"; |
| 7 | import { getMyKarne } from "../../reports"; |
| 8 | import { getUserKarne } from "../../reports"; |
| 9 | import { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 10 | |
| 11 | describe("reports API", () => { |
| 12 | afterEach(() => { |
| 13 | vi.restoreAllMocks(); |
| 14 | }); |
| 15 | |
| 16 | it("getMyCourses calls /courses/me", async () => { |
| 17 | const mockCourses = [{ id: "c1" }]; |
| 18 | mockFetchSuccess(mockCourses); |
| 19 | |
| 20 | const result = await getMyCourses(); |
| 21 | expect(result).toEqual({ items: mockCourses, limit: null, offset: 0, total: 1 }); |
| 22 | |
| 23 | const [url, init] = lastFetchCall(); |
| 24 | expect(url).toBe("/api/courses/me"); |
| 25 | expect(init?.method).toBe("GET"); |
| 26 | }); |
| 27 | |
| 28 | it("getMyCourses sends pagination only — /courses/me takes no filters", async () => { |
| 29 | mockFetchSuccess({ items: [], total: 0 }); |
| 30 | await getMyCourses({ limit: 5 }); |
| 31 | expect(lastFetchCall()[0]).toBe("/api/courses/me?limit=5"); |
| 32 | }); |
| 33 | |
| 34 | it("getMyAttendance calls /attendance/me", async () => { |
| 35 | const mockAttendance = { courses: [] }; |
| 36 | mockFetchSuccess(mockAttendance); |
| 37 | |
| 38 | const result = await getMyAttendance(); |
| 39 | expect(result).toEqual(mockAttendance); |
| 40 | |
| 41 | const [url, init] = lastFetchCall(); |
| 42 | expect(url).toBe("/api/attendance/me"); |
| 43 | expect(init?.method).toBe("GET"); |
| 44 | }); |
| 45 | |
| 46 | it("getMyMarks calls /marks/me", async () => { |
| 47 | const mockMarks = { courses: [] }; |
| 48 | mockFetchSuccess(mockMarks); |
| 49 | |
| 50 | const result = await getMyMarks(); |
| 51 | expect(result).toEqual(mockMarks); |
| 52 | |
| 53 | const [url, init] = lastFetchCall(); |
| 54 | expect(url).toBe("/api/marks/me"); |
| 55 | expect(init?.method).toBe("GET"); |
| 56 | }); |
| 57 | |
| 58 | it("getUserAttendance calls /attendance/users/:id", async () => { |
| 59 | const mockAttendance = { courses: [] }; |
| 60 | mockFetchSuccess(mockAttendance); |
| 61 | |
| 62 | const result = await getUserAttendance("u1"); |
| 63 | expect(result).toEqual(mockAttendance); |
| 64 | |
| 65 | const [url, init] = lastFetchCall(); |
| 66 | expect(url).toBe("/api/attendance/u1"); |
| 67 | expect(init?.method).toBe("GET"); |
| 68 | }); |
| 69 | |
| 70 | it("getUserMarks calls /marks/users/:id", async () => { |
| 71 | const mockMarks = { courses: [] }; |
| 72 | mockFetchSuccess(mockMarks); |
| 73 | |
| 74 | const result = await getUserMarks("u1"); |
| 75 | expect(result).toEqual(mockMarks); |
| 76 | |
| 77 | const [url, init] = lastFetchCall(); |
| 78 | expect(url).toBe("/api/marks/u1"); |
| 79 | expect(init?.method).toBe("GET"); |
| 80 | }); |
| 81 | it("getMyKarne calls /marks/karne without a term", async () => { |
| 82 | mockFetchSuccess({ user: "u1", term: "t1", instances: [] }); |
| 83 | |
| 84 | await getMyKarne(); |
| 85 | |
| 86 | const [url, init] = lastFetchCall(); |
| 87 | expect(url).toBe("/api/marks/karne"); |
| 88 | expect(init?.method).toBe("GET"); |
| 89 | }); |
| 90 | |
| 91 | it("getMyKarne passes the term through as a query", async () => { |
| 92 | mockFetchSuccess({ user: "u1", term: "t 1", instances: [] }); |
| 93 | |
| 94 | await getMyKarne("t 1"); |
| 95 | |
| 96 | const [url] = lastFetchCall(); |
| 97 | expect(url).toBe("/api/marks/karne?term=t%201"); |
| 98 | }); |
| 99 | |
| 100 | it("getUserKarne calls /marks/karne/:user with the term", async () => { |
| 101 | mockFetchSuccess({ user: "u2", term: "t1", instances: [] }); |
| 102 | |
| 103 | await getUserKarne("u2", "t1"); |
| 104 | |
| 105 | const [url] = lastFetchCall(); |
| 106 | expect(url).toBe("/api/marks/karne/u2?term=t1"); |
| 107 | }); |
| 108 | |
| 109 | }); |