From 18dcd69788a33e49c782ecefbcf759d19d408e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Mon, 3 Aug 2026 10:29:23 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=8D=20drop=20query=20filters=20?= =?UTF-8?q?the=20backend=20never=20implemented=20-=20GET=20/homework=20tak?= =?UTF-8?q?es=20limit/offset=20only,=20yet=20getHomework=20advertised=20a?= =?UTF-8?q?=20=20=20due=5Fafter=20window;=20GET=20/courses=20and=20/course?= =?UTF-8?q?s/me=20likewise=20take=20no=20=20=20kind/q/term=5Fid.=20Serde?= =?UTF-8?q?=20drops=20unknown=20query=20keys=20silently,=20so=20every=20on?= =?UTF-8?q?e=20=20=20of=20these=20looked=20applied=20while=20the=20respons?= =?UTF-8?q?e=20came=20back=20unfiltered=20-=20the=20visible=20symptom=20wa?= =?UTF-8?q?s=20the=20homepage=20"courses"=20stat,=20which=20asked=20for=20?= =?UTF-8?q?=20=20kind=3Dcourse=20and=20counted=20studies=20and=20clubs=20a?= =?UTF-8?q?long=20with=20it;=20it=20now=20counts=20=20=20over=20the=20unpa?= =?UTF-8?q?ged=20list=20client-side,=20the=20way=20the=20courses=20page=20?= =?UTF-8?q?already=20did=20-=20three=20unit=20tests=20and=20one=20contract?= =?UTF-8?q?=20test=20encoded=20the=20phantom=20filters=20=E2=80=94=20=20?= =?UTF-8?q?=20the=20contract=20test=20claimed=20"returns=20filtered=20cour?= =?UTF-8?q?ses"=20and=20passed=20only=20=20=20because=20the=20backend=20ig?= =?UTF-8?q?nored=20the=20filters=20it=20sent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contract/learning.contract.test.ts | 6 ++++-- src/api/__tests__/courses/courses.test.ts | 6 +++--- src/api/__tests__/homework/homework.test.ts | 6 +++--- src/api/__tests__/reports/reports.test.ts | 6 +++--- src/api/courses/getCourses.ts | 17 ++++++++--------- src/api/homework/getHomework.ts | 7 +++++-- 6 files changed, 26 insertions(+), 22 deletions(-) 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);