🔍 drop query filters the backend never implemented
Browse files at this commit18dcd69788a33e49c782ecefbcf759d19d408e62Parent: f923bbf- fix
- 🔍 drop query filters the backend never implemented
6 changed files +26 -22
- src/api/__tests__/contract/learning.contract.test.ts +4 -2
- src/api/__tests__/courses/courses.test.ts +3 -3
- src/api/__tests__/homework/homework.test.ts +3 -3
- src/api/__tests__/reports/reports.test.ts +3 -3
- src/api/courses/getCourses.ts +8 -9
- src/api/homework/getHomework.ts +5 -2
src/api/__tests__/contract/learning.contract.test.tsmodified+4 -2
| @@ -21,8 +21,10 @@ describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { | |||
| 21 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); | 21 | if (courseId) await api(`/courses/${courseId}`, { method: "DELETE" }); |
| 22 | }); | 22 | }); |
| 23 | 23 | ||
| 24 | - it("returns filtered courses through the standard page envelope", async () => { | 24 | + // `/courses` takes limit/offset only — kind/term/search filtering is the |
| 25 | - const page = await json<{ items: Array<{ id: string }> }>(`/courses?kind=course&q=contract-learning&limit=10`); | 25 | + // caller's job, so this asserts the envelope, not a server-side filter. |
| 26 | + it("returns courses through the standard page envelope", async () => { | ||
| 27 | + const page = await json<{ items: Array<{ id: string }> }>(`/courses?limit=10`); | ||
| 26 | expectPage(page); | 28 | expectPage(page); |
| 27 | expect(page.items.some((course) => course.id === courseId)).toBe(true); | 29 | expect(page.items.some((course) => course.id === courseId)).toBe(true); |
| 28 | }); | 30 | }); |
src/api/__tests__/courses/courses.test.tsmodified+3 -3
| @@ -60,10 +60,10 @@ describe("courses API", () => { | |||
| 60 | expect(init?.method).toBe("GET"); | 60 | expect(init?.method).toBe("GET"); |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | - it("getCourses sends server-side kind, search, and term filters", async () => { | 63 | + it("getCourses sends pagination only — the endpoint has no kind/term/search filter", async () => { |
| 64 | mockFetchSuccess({ items: [], total: 0 }); | 64 | mockFetchSuccess({ items: [], total: 0 }); |
| 65 | - await getCourses({ limit: 12, offset: 24, kind: "course", q: "math", term_id: "none" }); | 65 | + await getCourses({ limit: 12, offset: 24 }); |
| 66 | - expect(lastFetchCall()[0]).toBe("/api/courses?limit=12&offset=24&kind=course&q=math&term_id=none"); | 66 | + expect(lastFetchCall()[0]).toBe("/api/courses?limit=12&offset=24"); |
| 67 | }); | 67 | }); |
| 68 | 68 | ||
| 69 | it("getCourseById calls /courses/:id", async () => { | 69 | it("getCourseById calls /courses/:id", async () => { |
src/api/__tests__/homework/homework.test.tsmodified+3 -3
| @@ -37,10 +37,10 @@ describe("homework API", () => { | |||
| 37 | expect(init?.method).toBe("GET"); | 37 | expect(init?.method).toBe("GET"); |
| 38 | }); | 38 | }); |
| 39 | 39 | ||
| 40 | - it("getHomework sends due_after", async () => { | 40 | + it("getHomework sends pagination only — the endpoint has no due-date window", async () => { |
| 41 | mockFetchSuccess({ items: [], total: 0 }); | 41 | mockFetchSuccess({ items: [], total: 0 }); |
| 42 | - await getHomework({ limit: 1, due_after: 1_700_000_000_000 }); | 42 | + await getHomework({ limit: 1 }); |
| 43 | - expect(lastFetchCall()[0]).toBe("/api/homework?limit=1&due_after=1700000000000"); | 43 | + expect(lastFetchCall()[0]).toBe("/api/homework?limit=1"); |
| 44 | }); | 44 | }); |
| 45 | 45 | ||
| 46 | it("getHomeworkById calls /homework/:id", async () => { | 46 | it("getHomeworkById calls /homework/:id", async () => { |
src/api/__tests__/reports/reports.test.tsmodified+3 -3
| @@ -23,10 +23,10 @@ describe("reports API", () => { | |||
| 23 | expect(init?.method).toBe("GET"); | 23 | expect(init?.method).toBe("GET"); |
| 24 | }); | 24 | }); |
| 25 | 25 | ||
| 26 | - it("getMyCourses sends course filters", async () => { | 26 | + it("getMyCourses sends pagination only — /courses/me takes no filters", async () => { |
| 27 | mockFetchSuccess({ items: [], total: 0 }); | 27 | mockFetchSuccess({ items: [], total: 0 }); |
| 28 | - await getMyCourses({ kind: "club", q: "robot", term_id: "t1" }); | 28 | + await getMyCourses({ limit: 5 }); |
| 29 | - expect(lastFetchCall()[0]).toBe("/api/courses/me?kind=club&q=robot&term_id=t1"); | 29 | + expect(lastFetchCall()[0]).toBe("/api/courses/me?limit=5"); |
| 30 | }); | 30 | }); |
| 31 | 31 | ||
| 32 | it("getMyAttendance calls /attendance/me", async () => { | 32 | it("getMyAttendance calls /attendance/me", async () => { |
src/api/courses/getCourses.tsmodified+8 -9
| @@ -1,20 +1,19 @@ | |||
| 1 | import { client } from "../client"; | 1 | import { client } from "../client"; |
| 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; | 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; |
| 3 | -import type { Course, CourseKind } from "../client"; | 3 | +import type { Course } from "../client"; |
| 4 | 4 | ||
| 5 | -export type CourseListParams = PageParams & { | 5 | +/** |
| 6 | - kind?: CourseKind; | 6 | + * `GET /courses` and `GET /courses/me` take `limit`/`offset` and nothing else — |
| 7 | - q?: string; | 7 | + * the backend has no kind/term/search filter, and serde drops unknown query |
| 8 | - term_id?: string; | 8 | + * keys silently, so any extra param would look applied while doing nothing. |
| 9 | -}; | 9 | + * Narrow the list in the caller instead (see `courses-page.tsx`). |
| 10 | + */ | ||
| 11 | +export type CourseListParams = PageParams; | ||
| 10 | 12 | ||
| 11 | export function courseListQuery(params?: CourseListParams): string { | 13 | export function courseListQuery(params?: CourseListParams): string { |
| 12 | if (!params) return ""; | 14 | if (!params) return ""; |
| 13 | const query = new URLSearchParams(); | 15 | const query = new URLSearchParams(); |
| 14 | appendPageParams(query, params); | 16 | appendPageParams(query, params); |
| 15 | - if (params.kind) query.set("kind", params.kind); | ||
| 16 | - if (params.q) query.set("q", params.q); | ||
| 17 | - if (params.term_id) query.set("term_id", params.term_id); | ||
| 18 | const value = query.toString(); | 17 | const value = query.toString(); |
| 19 | return value ? `?${value}` : ""; | 18 | return value ? `?${value}` : ""; |
| 20 | } | 19 | } |
src/api/homework/getHomework.tsmodified+5 -2
| @@ -2,12 +2,15 @@ import { client } from "../client"; | |||
| 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; | 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; |
| 3 | import type { Homework } from "../client"; | 3 | import type { Homework } from "../client"; |
| 4 | 4 | ||
| 5 | -export type HomeworkListParams = PageParams & { due_after?: number }; | 5 | +/** |
| 6 | + * `GET /homework` takes `limit`/`offset` only — unlike events and exams it has | ||
| 7 | + * no schedule window, so a due-date filter has to happen in the caller. | ||
| 8 | + */ | ||
| 9 | +export type HomeworkListParams = PageParams; | ||
| 6 | 10 | ||
| 7 | export async function getHomework(params?: HomeworkListParams, signal?: AbortSignal): Promise<Page<Homework>> { | 11 | export async function getHomework(params?: HomeworkListParams, signal?: AbortSignal): Promise<Page<Homework>> { |
| 8 | const query = new URLSearchParams(); | 12 | const query = new URLSearchParams(); |
| 9 | appendPageParams(query, params); | 13 | appendPageParams(query, params); |
| 10 | - if (params?.due_after != null) query.set("due_after", String(params.due_after)); | ||
| 11 | const suffix = query.size ? `?${query}` : ""; | 14 | const suffix = query.size ? `?${query}` : ""; |
| 12 | const data = await client<unknown>(`/homework${suffix}`, { signal }); | 15 | const data = await client<unknown>(`/homework${suffix}`, { signal }); |
| 13 | return normalizePage<Homework>(data); | 16 | return normalizePage<Homework>(data); |