diff --git a/src/api/__tests__/contract/learning.contract.test.ts b/src/api/__tests__/contract/learning.contract.test.ts index 8eb48dc..c462289 100644 --- a/src/api/__tests__/contract/learning.contract.test.ts +++ b/src/api/__tests__/contract/learning.contract.test.ts @@ -21,8 +21,10 @@ describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); }); - it("returns filtered courses through the standard page envelope", async () => { - const page = await json<{ items: Array<{ id: string }> }>(`/courses?kind=course&q=contract-learning&limit=10`); + // `/courses` takes limit/offset only — kind/term/search filtering is the + // caller's job, so this asserts the envelope, not a server-side filter. + it("returns courses through the standard page envelope", async () => { + const page = await json<{ items: Array<{ id: string }> }>(`/courses?limit=10`); expectPage(page); expect(page.items.some((course) => course.id === courseId)).toBe(true); }); diff --git a/src/api/__tests__/courses/courses.test.ts b/src/api/__tests__/courses/courses.test.ts index 5c21a97..66433f8 100644 --- a/src/api/__tests__/courses/courses.test.ts +++ b/src/api/__tests__/courses/courses.test.ts @@ -60,10 +60,10 @@ describe("courses API", () => { expect(init?.method).toBe("GET"); }); - it("getCourses sends server-side kind, search, and term filters", async () => { + it("getCourses sends pagination only — the endpoint has no kind/term/search filter", async () => { mockFetchSuccess({ items: [], total: 0 }); - await getCourses({ limit: 12, offset: 24, kind: "course", q: "math", term_id: "none" }); - expect(lastFetchCall()[0]).toBe("/api/courses?limit=12&offset=24&kind=course&q=math&term_id=none"); + await getCourses({ limit: 12, offset: 24 }); + expect(lastFetchCall()[0]).toBe("/api/courses?limit=12&offset=24"); }); it("getCourseById calls /courses/:id", async () => { diff --git a/src/api/__tests__/homework/homework.test.ts b/src/api/__tests__/homework/homework.test.ts index 5348943..88a5b07 100644 --- a/src/api/__tests__/homework/homework.test.ts +++ b/src/api/__tests__/homework/homework.test.ts @@ -37,10 +37,10 @@ describe("homework API", () => { expect(init?.method).toBe("GET"); }); - it("getHomework sends due_after", async () => { + it("getHomework sends pagination only — the endpoint has no due-date window", async () => { mockFetchSuccess({ items: [], total: 0 }); - await getHomework({ limit: 1, due_after: 1_700_000_000_000 }); - expect(lastFetchCall()[0]).toBe("/api/homework?limit=1&due_after=1700000000000"); + await getHomework({ limit: 1 }); + expect(lastFetchCall()[0]).toBe("/api/homework?limit=1"); }); it("getHomeworkById calls /homework/:id", async () => { diff --git a/src/api/__tests__/reports/reports.test.ts b/src/api/__tests__/reports/reports.test.ts index 4505a50..cf57452 100644 --- a/src/api/__tests__/reports/reports.test.ts +++ b/src/api/__tests__/reports/reports.test.ts @@ -23,10 +23,10 @@ describe("reports API", () => { expect(init?.method).toBe("GET"); }); - it("getMyCourses sends course filters", async () => { + it("getMyCourses sends pagination only — /courses/me takes no filters", async () => { mockFetchSuccess({ items: [], total: 0 }); - await getMyCourses({ kind: "club", q: "robot", term_id: "t1" }); - expect(lastFetchCall()[0]).toBe("/api/courses/me?kind=club&q=robot&term_id=t1"); + await getMyCourses({ limit: 5 }); + expect(lastFetchCall()[0]).toBe("/api/courses/me?limit=5"); }); it("getMyAttendance calls /attendance/me", async () => { diff --git a/src/api/courses/getCourses.ts b/src/api/courses/getCourses.ts index 0d75887..0d04635 100644 --- a/src/api/courses/getCourses.ts +++ b/src/api/courses/getCourses.ts @@ -1,20 +1,19 @@ import { client } from "../client"; import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; -import type { Course, CourseKind } from "../client"; +import type { Course } from "../client"; -export type CourseListParams = PageParams & { - kind?: CourseKind; - q?: string; - term_id?: string; -}; +/** + * `GET /courses` and `GET /courses/me` take `limit`/`offset` and nothing else — + * the backend has no kind/term/search filter, and serde drops unknown query + * keys silently, so any extra param would look applied while doing nothing. + * Narrow the list in the caller instead (see `courses-page.tsx`). + */ +export type CourseListParams = PageParams; export function courseListQuery(params?: CourseListParams): string { if (!params) return ""; const query = new URLSearchParams(); appendPageParams(query, params); - if (params.kind) query.set("kind", params.kind); - if (params.q) query.set("q", params.q); - if (params.term_id) query.set("term_id", params.term_id); const value = query.toString(); return value ? `?${value}` : ""; } diff --git a/src/api/homework/getHomework.ts b/src/api/homework/getHomework.ts index 0c11ea3..be1f600 100644 --- a/src/api/homework/getHomework.ts +++ b/src/api/homework/getHomework.ts @@ -2,12 +2,15 @@ import { client } from "../client"; import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; import type { Homework } from "../client"; -export type HomeworkListParams = PageParams & { due_after?: number }; +/** + * `GET /homework` takes `limit`/`offset` only — unlike events and exams it has + * no schedule window, so a due-date filter has to happen in the caller. + */ +export type HomeworkListParams = PageParams; export async function getHomework(params?: HomeworkListParams, signal?: AbortSignal): Promise> { const query = new URLSearchParams(); appendPageParams(query, params); - if (params?.due_after != null) query.set("due_after", String(params.due_after)); const suffix = query.size ? `?${query}` : ""; const data = await client(`/homework${suffix}`, { signal }); return normalizePage(data);