hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 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 { lastFetchCall, mockFetchSuccess } from "../helpers/mock-fetch"; |
| 8 | |
| 9 | describe("reports API", () => { |
| 10 | afterEach(() => { |
| 11 | vi.restoreAllMocks(); |
| 12 | }); |
| 13 | |
| 14 | it("getMyCourses calls /courses/me", async () => { |
| 15 | const mockCourses = [{ id: "c1" }]; |
| 16 | mockFetchSuccess(mockCourses); |
| 17 | |
| 18 | const result = await getMyCourses(); |
| 19 | expect(result).toEqual({ items: mockCourses, limit: null, offset: 0, total: 1 }); |
| 20 | |
| 21 | const [url, init] = lastFetchCall(); |
| 22 | expect(url).toBe("/api/courses/me"); |
| 23 | expect(init?.method).toBe("GET"); |
| 24 | }); |
| 25 | |
| 26 | it("getMyCourses sends course filters", async () => { |
| 27 | mockFetchSuccess({ items: [], total: 0 }); |
| 28 | await getMyCourses({ kind: "club", q: "robot", term_id: "t1" }); |
| 29 | expect(lastFetchCall()[0]).toBe("/api/courses/me?kind=club&q=robot&term_id=t1"); |
| 30 | }); |
| 31 | |
| 32 | it("getMyAttendance calls /attendance/me", async () => { |
| 33 | const mockAttendance = { courses: [] }; |
| 34 | mockFetchSuccess(mockAttendance); |
| 35 | |
| 36 | const result = await getMyAttendance(); |
| 37 | expect(result).toEqual(mockAttendance); |
| 38 | |
| 39 | const [url, init] = lastFetchCall(); |
| 40 | expect(url).toBe("/api/attendance/me"); |
| 41 | expect(init?.method).toBe("GET"); |
| 42 | }); |
| 43 | |
| 44 | it("getMyMarks calls /marks/me", async () => { |
| 45 | const mockMarks = { courses: [] }; |
| 46 | mockFetchSuccess(mockMarks); |
| 47 | |
| 48 | const result = await getMyMarks(); |
| 49 | expect(result).toEqual(mockMarks); |
| 50 | |
| 51 | const [url, init] = lastFetchCall(); |
| 52 | expect(url).toBe("/api/marks/me"); |
| 53 | expect(init?.method).toBe("GET"); |
| 54 | }); |
| 55 | |
| 56 | it("getUserAttendance calls /attendance/users/:id", async () => { |
| 57 | const mockAttendance = { courses: [] }; |
| 58 | mockFetchSuccess(mockAttendance); |
| 59 | |
| 60 | const result = await getUserAttendance("u1"); |
| 61 | expect(result).toEqual(mockAttendance); |
| 62 | |
| 63 | const [url, init] = lastFetchCall(); |
| 64 | expect(url).toBe("/api/attendance/u1"); |
| 65 | expect(init?.method).toBe("GET"); |
| 66 | }); |
| 67 | |
| 68 | it("getUserMarks calls /marks/users/:id", async () => { |
| 69 | const mockMarks = { courses: [] }; |
| 70 | mockFetchSuccess(mockMarks); |
| 71 | |
| 72 | const result = await getUserMarks("u1"); |
| 73 | expect(result).toEqual(mockMarks); |
| 74 | |
| 75 | const [url, init] = lastFetchCall(); |
| 76 | expect(url).toBe("/api/marks/u1"); |
| 77 | expect(init?.method).toBe("GET"); |
| 78 | }); |
| 79 | }); |