From f409644752e5403e5395a087c67d69e4986b55e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Fri, 25 Sep 2026 12:21:45 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=A7=A9=20API=20layer=20for=20grad?= =?UTF-8?q?e=20templates,=20section=20overrides=20and=20holidays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - offerings domain: CRUD for the (course, grade) template plus its subject selection, template week and exam-kind weights - instance override doors: title/description on PATCH, reset to inherit, own subjects, own weekly plan, own exam weights, and the dry-run/apply weekly-plan materializer - holidays domain: paged, window-filtered calendar with manager CRUD - per-domain vitest coverage for every new endpoint; grade-ladder fixtures in the contract suite and student-directory test --- .../contract/bank-questions.contract.test.ts | 2 +- .../contract/learning.contract.test.ts | 2 +- src/api/__tests__/holidays/holidays.test.ts | 65 ++++++++ src/api/__tests__/instances/instances.test.ts | 134 ++++++++++++++++- src/api/__tests__/offerings/offerings.test.ts | 141 ++++++++++++++++++ src/api/holidays/deleteHolidayById.ts | 6 + src/api/holidays/getHolidayById.ts | 6 + src/api/holidays/getHolidays.ts | 17 +++ src/api/holidays/index.ts | 5 + src/api/holidays/patchHolidayById.ts | 9 ++ src/api/holidays/postHoliday.ts | 10 ++ .../deleteInstanceExamWeightByKind.ts | 6 + .../instances/deleteInstanceExamWeights.ts | 6 + .../instances/deleteInstanceSubjectById.ts | 6 + src/api/instances/deleteInstanceSubjects.ts | 6 + src/api/instances/deleteInstanceWeeklyPlan.ts | 6 + .../instances/deleteInstanceWeeklySlotById.ts | 6 + src/api/instances/getInstanceExamWeights.ts | 8 + src/api/instances/getInstanceSubjects.ts | 8 + src/api/instances/getInstanceWeeklyPlan.ts | 8 + src/api/instances/index.ts | 14 ++ src/api/instances/patchInstanceById.ts | 7 +- src/api/instances/patchInstanceExamWeight.ts | 9 ++ src/api/instances/postInstanceReset.ts | 8 + src/api/instances/postInstanceSubject.ts | 8 + .../postInstanceWeeklyPlanMaterialize.ts | 11 ++ src/api/instances/postInstanceWeeklySlot.ts | 8 + src/api/offerings/deleteOfferingById.ts | 6 + .../deleteOfferingExamWeightByKind.ts | 6 + .../offerings/deleteOfferingSubjectById.ts | 5 + .../offerings/deleteOfferingWeeklySlotById.ts | 5 + src/api/offerings/getOfferingById.ts | 7 + src/api/offerings/getOfferingExamWeights.ts | 6 + src/api/offerings/getOfferingSubjects.ts | 7 + src/api/offerings/getOfferingWeeklyPlan.ts | 7 + src/api/offerings/getOfferings.ts | 15 ++ src/api/offerings/index.ts | 14 ++ src/api/offerings/patchOfferingById.ts | 15 ++ src/api/offerings/patchOfferingExamWeight.ts | 8 + src/api/offerings/postOffering.ts | 17 +++ src/api/offerings/postOfferingSubject.ts | 7 + src/api/offerings/postOfferingWeeklySlot.ts | 10 ++ src/lib/student-directory.test.ts | 18 +-- 43 files changed, 662 insertions(+), 13 deletions(-) create mode 100644 src/api/__tests__/holidays/holidays.test.ts create mode 100644 src/api/__tests__/offerings/offerings.test.ts create mode 100644 src/api/holidays/deleteHolidayById.ts create mode 100644 src/api/holidays/getHolidayById.ts create mode 100644 src/api/holidays/getHolidays.ts create mode 100644 src/api/holidays/index.ts create mode 100644 src/api/holidays/patchHolidayById.ts create mode 100644 src/api/holidays/postHoliday.ts create mode 100644 src/api/instances/deleteInstanceExamWeightByKind.ts create mode 100644 src/api/instances/deleteInstanceExamWeights.ts create mode 100644 src/api/instances/deleteInstanceSubjectById.ts create mode 100644 src/api/instances/deleteInstanceSubjects.ts create mode 100644 src/api/instances/deleteInstanceWeeklyPlan.ts create mode 100644 src/api/instances/deleteInstanceWeeklySlotById.ts create mode 100644 src/api/instances/getInstanceExamWeights.ts create mode 100644 src/api/instances/getInstanceSubjects.ts create mode 100644 src/api/instances/getInstanceWeeklyPlan.ts create mode 100644 src/api/instances/patchInstanceExamWeight.ts create mode 100644 src/api/instances/postInstanceReset.ts create mode 100644 src/api/instances/postInstanceSubject.ts create mode 100644 src/api/instances/postInstanceWeeklyPlanMaterialize.ts create mode 100644 src/api/instances/postInstanceWeeklySlot.ts create mode 100644 src/api/offerings/deleteOfferingById.ts create mode 100644 src/api/offerings/deleteOfferingExamWeightByKind.ts create mode 100644 src/api/offerings/deleteOfferingSubjectById.ts create mode 100644 src/api/offerings/deleteOfferingWeeklySlotById.ts create mode 100644 src/api/offerings/getOfferingById.ts create mode 100644 src/api/offerings/getOfferingExamWeights.ts create mode 100644 src/api/offerings/getOfferingSubjects.ts create mode 100644 src/api/offerings/getOfferingWeeklyPlan.ts create mode 100644 src/api/offerings/getOfferings.ts create mode 100644 src/api/offerings/index.ts create mode 100644 src/api/offerings/patchOfferingById.ts create mode 100644 src/api/offerings/patchOfferingExamWeight.ts create mode 100644 src/api/offerings/postOffering.ts create mode 100644 src/api/offerings/postOfferingSubject.ts create mode 100644 src/api/offerings/postOfferingWeeklySlot.ts diff --git a/src/api/__tests__/contract/bank-questions.contract.test.ts b/src/api/__tests__/contract/bank-questions.contract.test.ts index 137affd..f4d3e5e 100644 --- a/src/api/__tests__/contract/bank-questions.contract.test.ts +++ b/src/api/__tests__/contract/bank-questions.contract.test.ts @@ -32,7 +32,7 @@ describe.skipIf(!isLive)(`bank-questions contract @ ${contractBaseUrl}`, () => { // `class` is the row, and `skipped` is the pair report (empty here). const created = await json<{ class: { id: string }; skipped: unknown[] }>("/classes", { method: "POST", - body: { name: tag, grade: "9", year: yearId }, + body: { name: tag, grade_level: 9, year: yearId }, }); classId = created.class.id; expect(Array.isArray(created.skipped)).toBe(true); diff --git a/src/api/__tests__/contract/learning.contract.test.ts b/src/api/__tests__/contract/learning.contract.test.ts index fde504f..bfd70a3 100644 --- a/src/api/__tests__/contract/learning.contract.test.ts +++ b/src/api/__tests__/contract/learning.contract.test.ts @@ -34,7 +34,7 @@ describe.skipIf(!isLive)(`learning contract @ ${contractBaseUrl}`, () => { // `class` is the row, and `skipped` is the pair report (empty here). const created = await json<{ class: { id: string }; skipped: unknown[] }>("/classes", { method: "POST", - body: { name: tag, grade: "9", year: yearId }, + body: { name: tag, grade_level: 9, year: yearId }, }); classId = created.class.id; expect(Array.isArray(created.skipped)).toBe(true); diff --git a/src/api/__tests__/holidays/holidays.test.ts b/src/api/__tests__/holidays/holidays.test.ts new file mode 100644 index 0000000..5fb1b48 --- /dev/null +++ b/src/api/__tests__/holidays/holidays.test.ts @@ -0,0 +1,65 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { + deleteHolidayById, + getHolidayById, + getHolidays, + patchHolidayById, + postHoliday, +} from "../../holidays"; +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; + +describe("holidays API", () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("getHolidays GETs /holidays with paging and the overlap window", async () => { + mockFetchSuccess({ items: [], total: 0 }); + await getHolidays({ limit: 50, offset: 0, from: 1000, to: 2000 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/holidays?limit=50&offset=0&from=1000&to=2000"); + expect(init?.method).toBe("GET"); + }); + + it("getHolidays sends no query when unfiltered", async () => { + mockFetchSuccess({ items: [], total: 0 }); + await getHolidays(); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/holidays"); + expect(init?.method).toBe("GET"); + }); + + it("getHolidayById GETs /holidays/h1", async () => { + mockFetchSuccess({ id: "x1" }); + await getHolidayById("h1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/holidays/h1"); + expect(init?.method).toBe("GET"); + }); + + it("postHoliday POSTs /holidays", async () => { + mockFetchSuccess({ id: "x1" }); + await postHoliday({ name: "29 Ekim", kind: "resmi", starts_at: 1, ends_at: 2 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/holidays"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ name: "29 Ekim", kind: "resmi", starts_at: 1, ends_at: 2 })); + }); + + it("patchHolidayById PATCHs /holidays/h1", async () => { + mockFetchSuccess({ id: "x1" }); + await patchHolidayById("h1", { name: "Ara tatil" }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/holidays/h1"); + expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify({ name: "Ara tatil" })); + }); + + it("deleteHolidayById DELETEs /holidays/h1", async () => { + mockFetch204(); + await deleteHolidayById("h1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/holidays/h1"); + expect(init?.method).toBe("DELETE"); + }); +}); diff --git a/src/api/__tests__/instances/instances.test.ts b/src/api/__tests__/instances/instances.test.ts index 9544259..d44968c 100644 --- a/src/api/__tests__/instances/instances.test.ts +++ b/src/api/__tests__/instances/instances.test.ts @@ -14,6 +14,20 @@ import { postInstanceHomework, postInstanceSession, postInstanceTeacher, + deleteInstanceExamWeightByKind, + deleteInstanceExamWeights, + deleteInstanceSubjectById, + deleteInstanceSubjects, + deleteInstanceWeeklyPlan, + deleteInstanceWeeklySlotById, + getInstanceExamWeights, + getInstanceSubjects, + getInstanceWeeklyPlan, + patchInstanceExamWeight, + postInstanceReset, + postInstanceSubject, + postInstanceWeeklyPlanMaterialize, + postInstanceWeeklySlot, } from "../../instances"; import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; @@ -45,7 +59,7 @@ describe("instances API", () => { it("patchInstanceById PATCHes /instances/:id with the policy body", async () => { mockFetchSuccess({ id: "i1" }); - const body = { ders_saati: 4, counts_toward_karne: false }; + const body = { title: "9-A Matematik", description: "Sayısal", ders_saati: 4, counts_toward_karne: false }; await patchInstanceById("i1", body); @@ -168,4 +182,122 @@ describe("instances API", () => { expect(url).toBe("/api/instances/i1/teachers/t1"); expect(init?.method).toBe("DELETE"); }); + + // Per-section overrides over the grade-level offering. + it("postInstanceReset POSTs /instances/i1/reset", async () => { + mockFetchSuccess({ id: "x1" }); + await postInstanceReset("i1", ["title", "weekly_plan"]); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/reset"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ fields: ["title", "weekly_plan"] })); + }); + + it("getInstanceSubjects GETs /instances/i1/subjects", async () => { + mockFetchSuccess({ subjects: [], subjects_inherited: true }); + await getInstanceSubjects("i1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/subjects"); + expect(init?.method).toBe("GET"); + }); + + it("postInstanceSubject POSTs /instances/i1/subjects", async () => { + mockFetchSuccess({ id: "x1" }); + await postInstanceSubject("i1", "s1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/subjects"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ subject: "s1" })); + }); + + it("deleteInstanceSubjects DELETEs /instances/i1/subjects", async () => { + mockFetch204(); + await deleteInstanceSubjects("i1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/subjects"); + expect(init?.method).toBe("DELETE"); + }); + + it("deleteInstanceSubjectById DELETEs /instances/i1/subjects/s1", async () => { + mockFetch204(); + await deleteInstanceSubjectById("i1", "s1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/subjects/s1"); + expect(init?.method).toBe("DELETE"); + }); + + it("getInstanceWeeklyPlan GETs /instances/i1/weekly-plan", async () => { + mockFetchSuccess({ weekly_plan: [], weekly_plan_inherited: true }); + await getInstanceWeeklyPlan("i1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/weekly-plan"); + expect(init?.method).toBe("GET"); + }); + + it("postInstanceWeeklySlot POSTs /instances/i1/weekly-plan", async () => { + mockFetchSuccess({ id: "x1" }); + await postInstanceWeeklySlot("i1", { weekday: 3, starts_at: 600, ends_at: 640 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/weekly-plan"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ weekday: 3, starts_at: 600, ends_at: 640 })); + }); + + it("deleteInstanceWeeklyPlan DELETEs /instances/i1/weekly-plan", async () => { + mockFetch204(); + await deleteInstanceWeeklyPlan("i1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/weekly-plan"); + expect(init?.method).toBe("DELETE"); + }); + + it("deleteInstanceWeeklySlotById DELETEs /instances/i1/weekly-plan/sl1", async () => { + mockFetch204(); + await deleteInstanceWeeklySlotById("i1", "sl1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/weekly-plan/sl1"); + expect(init?.method).toBe("DELETE"); + }); + + it("postInstanceWeeklyPlanMaterialize POSTs the range as a dry run", async () => { + mockFetchSuccess({ applied: false, created: [] }); + await postInstanceWeeklyPlanMaterialize("i1", { from: 10, to: 20, apply: false }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/weekly-plan/materialize"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ from: 10, to: 20, apply: false })); + }); + + it("getInstanceExamWeights GETs /instances/i1/exam-weights", async () => { + mockFetchSuccess({ inherited: true, weights: [] }); + await getInstanceExamWeights("i1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/exam-weights"); + expect(init?.method).toBe("GET"); + }); + + it("patchInstanceExamWeight PATCHs /instances/i1/exam-weights", async () => { + mockFetchSuccess({ inherited: false, weights: [] }); + await patchInstanceExamWeight("i1", { kind: "quiz", weight: 10 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/exam-weights"); + expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify({ kind: "quiz", weight: 10 })); + }); + + it("deleteInstanceExamWeights DELETEs /instances/i1/exam-weights", async () => { + mockFetch204(); + await deleteInstanceExamWeights("i1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/exam-weights"); + expect(init?.method).toBe("DELETE"); + }); + + it("deleteInstanceExamWeightByKind DELETEs /instances/i1/exam-weights/quiz", async () => { + mockFetch204(); + await deleteInstanceExamWeightByKind("i1", "quiz"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/instances/i1/exam-weights/quiz"); + expect(init?.method).toBe("DELETE"); + }); }); diff --git a/src/api/__tests__/offerings/offerings.test.ts b/src/api/__tests__/offerings/offerings.test.ts new file mode 100644 index 0000000..0c9558a --- /dev/null +++ b/src/api/__tests__/offerings/offerings.test.ts @@ -0,0 +1,141 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { + deleteOfferingById, + deleteOfferingExamWeightByKind, + deleteOfferingSubjectById, + deleteOfferingWeeklySlotById, + getOfferingById, + getOfferingExamWeights, + getOfferingSubjects, + getOfferingWeeklyPlan, + getOfferings, + patchOfferingById, + patchOfferingExamWeight, + postOffering, + postOfferingSubject, + postOfferingWeeklySlot, +} from "../../offerings"; +import { lastFetchCall, mockFetch204, mockFetchSuccess } from "../helpers/mock-fetch"; + +describe("offerings API", () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it("getOfferings GETs /offerings narrowed by course and grade level (0 included)", async () => { + mockFetchSuccess({ items: [], total: 0 }); + await getOfferings({ course: "co1", grade_level: 0, limit: 20 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings?limit=20&course=co1&grade_level=0"); + expect(init?.method).toBe("GET"); + }); + + it("getOfferingById GETs /offerings/o1", async () => { + mockFetchSuccess({ id: "x1" }); + await getOfferingById("o1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1"); + expect(init?.method).toBe("GET"); + }); + + it("postOffering POSTs /offerings", async () => { + mockFetchSuccess({ id: "x1" }); + await postOffering({ course: "co1", grade_level: 9, default_ders_saati: 4 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ course: "co1", grade_level: 9, default_ders_saati: 4 })); + }); + + it("patchOfferingById PATCHes /offerings/o1 and sends null to clear back to inherit", async () => { + mockFetchSuccess({ id: "x1" }); + await patchOfferingById("o1", { title: null, default_counts_toward_karne: false }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1"); + expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify({ title: null, default_counts_toward_karne: false })); + }); + + it("deleteOfferingById DELETEs /offerings/o1", async () => { + mockFetch204(); + await deleteOfferingById("o1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1"); + expect(init?.method).toBe("DELETE"); + }); + + it("getOfferingSubjects GETs /offerings/o1/subjects", async () => { + mockFetchSuccess([]); + await getOfferingSubjects("o1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/subjects"); + expect(init?.method).toBe("GET"); + }); + + it("postOfferingSubject POSTs /offerings/o1/subjects", async () => { + mockFetchSuccess({ id: "x1" }); + await postOfferingSubject("o1", "s1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/subjects"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ subject: "s1" })); + }); + + it("deleteOfferingSubjectById DELETEs /offerings/o1/subjects/s1", async () => { + mockFetch204(); + await deleteOfferingSubjectById("o1", "s1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/subjects/s1"); + expect(init?.method).toBe("DELETE"); + }); + + it("getOfferingWeeklyPlan GETs /offerings/o1/weekly-plan", async () => { + mockFetchSuccess([]); + await getOfferingWeeklyPlan("o1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/weekly-plan"); + expect(init?.method).toBe("GET"); + }); + + it("postOfferingWeeklySlot POSTs /offerings/o1/weekly-plan", async () => { + mockFetchSuccess({ id: "x1" }); + await postOfferingWeeklySlot("o1", { weekday: 1, starts_at: 540, ends_at: 580, topic: null }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/weekly-plan"); + expect(init?.method).toBe("POST"); + expect(init?.body).toBe(JSON.stringify({ weekday: 1, starts_at: 540, ends_at: 580, topic: null })); + }); + + it("deleteOfferingWeeklySlotById DELETEs /offerings/o1/weekly-plan/sl1", async () => { + mockFetch204(); + await deleteOfferingWeeklySlotById("o1", "sl1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/weekly-plan/sl1"); + expect(init?.method).toBe("DELETE"); + }); + + it("getOfferingExamWeights GETs /offerings/o1/exam-weights", async () => { + mockFetchSuccess({ weights: [] }); + await getOfferingExamWeights("o1"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/exam-weights"); + expect(init?.method).toBe("GET"); + }); + + it("patchOfferingExamWeight PATCHs /offerings/o1/exam-weights", async () => { + mockFetchSuccess({ weights: [] }); + await patchOfferingExamWeight("o1", { kind: "midterm", weight: 40 }); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/exam-weights"); + expect(init?.method).toBe("PATCH"); + expect(init?.body).toBe(JSON.stringify({ kind: "midterm", weight: 40 })); + }); + + it("deleteOfferingExamWeightByKind encodes the kind in the path", async () => { + mockFetch204(); + await deleteOfferingExamWeightByKind("o1", "ara sınav"); + const [url, init] = lastFetchCall(); + expect(url).toBe("/api/offerings/o1/exam-weights/ara%20s%C4%B1nav"); + expect(init?.method).toBe("DELETE"); + }); +}); diff --git a/src/api/holidays/deleteHolidayById.ts b/src/api/holidays/deleteHolidayById.ts new file mode 100644 index 0000000..7a1c7db --- /dev/null +++ b/src/api/holidays/deleteHolidayById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Manager+. Lessons already generated on those days stay where they are. +export function deleteHolidayById(id: string): Promise { + return client(`/holidays/${id}`, { method: "DELETE" }); +} diff --git a/src/api/holidays/getHolidayById.ts b/src/api/holidays/getHolidayById.ts new file mode 100644 index 0000000..8b0d299 --- /dev/null +++ b/src/api/holidays/getHolidayById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { Holiday } from "../client"; + +export function getHolidayById(id: string, signal?: AbortSignal): Promise { + return client(`/holidays/${id}`, { signal }); +} diff --git a/src/api/holidays/getHolidays.ts b/src/api/holidays/getHolidays.ts new file mode 100644 index 0000000..ed0797f --- /dev/null +++ b/src/api/holidays/getHolidays.ts @@ -0,0 +1,17 @@ +import { client } from "../client"; +import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; +import type { Holiday } from "../client"; + +/** `from`/`to` (UTC unix-millis) keep the holidays overlapping that window. */ +export type HolidayListParams = PageParams & { from?: number; to?: number }; + +// Any signed-in session reads the calendar; newest start first. +export async function getHolidays(params?: HolidayListParams, signal?: AbortSignal): Promise> { + const query = new URLSearchParams(); + appendPageParams(query, params); + if (params?.from != null) query.set("from", String(params.from)); + if (params?.to != null) query.set("to", String(params.to)); + const value = query.toString(); + const data = await client(`/holidays${value ? `?${value}` : ""}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/holidays/index.ts b/src/api/holidays/index.ts new file mode 100644 index 0000000..646722d --- /dev/null +++ b/src/api/holidays/index.ts @@ -0,0 +1,5 @@ +export * from "./getHolidays"; +export * from "./getHolidayById"; +export * from "./postHoliday"; +export * from "./patchHolidayById"; +export * from "./deleteHolidayById"; diff --git a/src/api/holidays/patchHolidayById.ts b/src/api/holidays/patchHolidayById.ts new file mode 100644 index 0000000..2d0a8a1 --- /dev/null +++ b/src/api/holidays/patchHolidayById.ts @@ -0,0 +1,9 @@ +import { client } from "../client"; +import type { Holiday } from "../client"; + +/** Omit a field to keep it; the merged range must stay ordered. */ +export type UpdateHolidayBody = Partial<{ name: string; kind: string; starts_at: number; ends_at: number }>; + +export function patchHolidayById(id: string, body: UpdateHolidayBody): Promise { + return client(`/holidays/${id}`, { method: "PATCH", body }); +} diff --git a/src/api/holidays/postHoliday.ts b/src/api/holidays/postHoliday.ts new file mode 100644 index 0000000..148ed89 --- /dev/null +++ b/src/api/holidays/postHoliday.ts @@ -0,0 +1,10 @@ +import { client } from "../client"; +import type { Holiday } from "../client"; + +/** `starts_at`/`ends_at` are the first and last blocked instants, UTC unix-millis. */ +export type CreateHolidayBody = { name: string; kind: string; starts_at: number; ends_at: number }; + +// Manager+. Past ranges are allowed — the calendar is a record. +export function postHoliday(body: CreateHolidayBody): Promise { + return client("/holidays", { method: "POST", body }); +} diff --git a/src/api/instances/deleteInstanceExamWeightByKind.ts b/src/api/instances/deleteInstanceExamWeightByKind.ts new file mode 100644 index 0000000..8c1e179 --- /dev/null +++ b/src/api/instances/deleteInstanceExamWeightByKind.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Drops one kind's row; the map stays the section's own. +export function deleteInstanceExamWeightByKind(id: string, kind: string): Promise { + return client(`/instances/${id}/exam-weights/${encodeURIComponent(kind)}`, { method: "DELETE" }); +} diff --git a/src/api/instances/deleteInstanceExamWeights.ts b/src/api/instances/deleteInstanceExamWeights.ts new file mode 100644 index 0000000..5f34583 --- /dev/null +++ b/src/api/instances/deleteInstanceExamWeights.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Resets the weights to inherit (offering, then settings, then 1). +export function deleteInstanceExamWeights(id: string): Promise { + return client(`/instances/${id}/exam-weights`, { method: "DELETE" }); +} diff --git a/src/api/instances/deleteInstanceSubjectById.ts b/src/api/instances/deleteInstanceSubjectById.ts new file mode 100644 index 0000000..b43ae65 --- /dev/null +++ b/src/api/instances/deleteInstanceSubjectById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Drops one topic from the section's own set; the set stays the section's own. +export function deleteInstanceSubjectById(id: string, subjectId: string): Promise { + return client(`/instances/${id}/subjects/${subjectId}`, { method: "DELETE" }); +} diff --git a/src/api/instances/deleteInstanceSubjects.ts b/src/api/instances/deleteInstanceSubjects.ts new file mode 100644 index 0000000..205beb2 --- /dev/null +++ b/src/api/instances/deleteInstanceSubjects.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Restores inheritance: drops the section's own topics, the offering's apply. +export function deleteInstanceSubjects(id: string): Promise { + return client(`/instances/${id}/subjects`, { method: "DELETE" }); +} diff --git a/src/api/instances/deleteInstanceWeeklyPlan.ts b/src/api/instances/deleteInstanceWeeklyPlan.ts new file mode 100644 index 0000000..b641a0f --- /dev/null +++ b/src/api/instances/deleteInstanceWeeklyPlan.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Resets the week to inherit: drops every own slot, the template applies again. +export function deleteInstanceWeeklyPlan(id: string): Promise { + return client(`/instances/${id}/weekly-plan`, { method: "DELETE" }); +} diff --git a/src/api/instances/deleteInstanceWeeklySlotById.ts b/src/api/instances/deleteInstanceWeeklySlotById.ts new file mode 100644 index 0000000..423fba3 --- /dev/null +++ b/src/api/instances/deleteInstanceWeeklySlotById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Dropping the last own slot leaves an empty own plan, not a return to inherit. +export function deleteInstanceWeeklySlotById(id: string, slotId: string): Promise { + return client(`/instances/${id}/weekly-plan/${slotId}`, { method: "DELETE" }); +} diff --git a/src/api/instances/getInstanceExamWeights.ts b/src/api/instances/getInstanceExamWeights.ts new file mode 100644 index 0000000..f63c41b --- /dev/null +++ b/src/api/instances/getInstanceExamWeights.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { ExamWeightEntry } from "../client"; + +export type InstanceExamWeights = { inherited: boolean; weights: ExamWeightEntry[] }; + +export function getInstanceExamWeights(id: string, signal?: AbortSignal): Promise { + return client(`/instances/${id}/exam-weights`, { signal }); +} diff --git a/src/api/instances/getInstanceSubjects.ts b/src/api/instances/getInstanceSubjects.ts new file mode 100644 index 0000000..6115932 --- /dev/null +++ b/src/api/instances/getInstanceSubjects.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { Subject } from "../client"; + +export type ResolvedSubjects = { subjects: Subject[]; subjects_inherited: boolean }; + +export function getInstanceSubjects(id: string, signal?: AbortSignal): Promise { + return client(`/instances/${id}/subjects`, { signal }); +} diff --git a/src/api/instances/getInstanceWeeklyPlan.ts b/src/api/instances/getInstanceWeeklyPlan.ts new file mode 100644 index 0000000..e9a1539 --- /dev/null +++ b/src/api/instances/getInstanceWeeklyPlan.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { WeeklySlot } from "../client"; + +export type InstanceWeeklyPlan = { weekly_plan: WeeklySlot[]; weekly_plan_inherited: boolean }; + +export function getInstanceWeeklyPlan(id: string, signal?: AbortSignal): Promise { + return client(`/instances/${id}/weekly-plan`, { signal }); +} diff --git a/src/api/instances/index.ts b/src/api/instances/index.ts index e628488..0b46c49 100644 --- a/src/api/instances/index.ts +++ b/src/api/instances/index.ts @@ -12,3 +12,17 @@ export * from "./getInstanceSessions"; export * from "./postInstanceSession"; export * from "./postInstanceTeacher"; export * from "./deleteInstanceTeacherByUserId"; +export * from "./postInstanceReset"; +export * from "./getInstanceSubjects"; +export * from "./postInstanceSubject"; +export * from "./deleteInstanceSubjects"; +export * from "./deleteInstanceSubjectById"; +export * from "./getInstanceWeeklyPlan"; +export * from "./postInstanceWeeklySlot"; +export * from "./deleteInstanceWeeklyPlan"; +export * from "./deleteInstanceWeeklySlotById"; +export * from "./postInstanceWeeklyPlanMaterialize"; +export * from "./getInstanceExamWeights"; +export * from "./patchInstanceExamWeight"; +export * from "./deleteInstanceExamWeights"; +export * from "./deleteInstanceExamWeightByKind"; diff --git a/src/api/instances/patchInstanceById.ts b/src/api/instances/patchInstanceById.ts index 43bed9c..902bbc9 100644 --- a/src/api/instances/patchInstanceById.ts +++ b/src/api/instances/patchInstanceById.ts @@ -1,8 +1,13 @@ import { client } from "../client"; import type { Instance } from "../client"; -/** Both fields are non-clearable: omit to keep, never send null. */ +/** + * The section's own overrides. Omit to keep; a PATCH sets, it never clears — + * clearing back to inherit is postInstanceReset. Never send null. + */ export type PatchInstanceBody = { + title?: string; + description?: string; ders_saati?: number; counts_toward_karne?: boolean; }; diff --git a/src/api/instances/patchInstanceExamWeight.ts b/src/api/instances/patchInstanceExamWeight.ts new file mode 100644 index 0000000..9043aca --- /dev/null +++ b/src/api/instances/patchInstanceExamWeight.ts @@ -0,0 +1,9 @@ +import { client } from "../client"; +import type { ExamWeightEntry } from "../client"; +import type { InstanceExamWeights } from "./getInstanceExamWeights"; + +// Sets one kind's weight and takes the whole map own: kinds without a row +// then weigh 1 here instead of following the offering. +export function patchInstanceExamWeight(id: string, body: ExamWeightEntry): Promise { + return client(`/instances/${id}/exam-weights`, { method: "PATCH", body }); +} diff --git a/src/api/instances/postInstanceReset.ts b/src/api/instances/postInstanceReset.ts new file mode 100644 index 0000000..a59180d --- /dev/null +++ b/src/api/instances/postInstanceReset.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { Instance, InstanceOverrideField } from "../client"; + +// Clears the named overrides back to inherit; a set field (subjects, +// exam_weights, weekly_plan) flips its flag back to inherited. +export function postInstanceReset(id: string, fields: InstanceOverrideField[]): Promise { + return client(`/instances/${id}/reset`, { method: "POST", body: { fields } }); +} diff --git a/src/api/instances/postInstanceSubject.ts b/src/api/instances/postInstanceSubject.ts new file mode 100644 index 0000000..ec0fd3d --- /dev/null +++ b/src/api/instances/postInstanceSubject.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { Subject } from "../client"; + +// Selects a topic for the section's own set — the set becomes the section's +// own (not the offering's) from this call on. +export function postInstanceSubject(id: string, subjectId: string): Promise { + return client(`/instances/${id}/subjects`, { method: "POST", body: { subject: subjectId } }); +} diff --git a/src/api/instances/postInstanceWeeklyPlanMaterialize.ts b/src/api/instances/postInstanceWeeklyPlanMaterialize.ts new file mode 100644 index 0000000..c2993a7 --- /dev/null +++ b/src/api/instances/postInstanceWeeklyPlanMaterialize.ts @@ -0,0 +1,11 @@ +import { client } from "../client"; +import type { MaterializeReport } from "../client"; + +/** `from`/`to` are UTC unix-millis naming school days; `apply: false` is a dry run. */ +export type MaterializeBody = { from: number; to: number; apply?: boolean }; + +// Expands the resolved week into dated lessons. Additive and idempotent: +// holiday days and already-scheduled starts are skipped and counted. +export function postInstanceWeeklyPlanMaterialize(id: string, body: MaterializeBody): Promise { + return client(`/instances/${id}/weekly-plan/materialize`, { method: "POST", body }); +} diff --git a/src/api/instances/postInstanceWeeklySlot.ts b/src/api/instances/postInstanceWeeklySlot.ts new file mode 100644 index 0000000..342795d --- /dev/null +++ b/src/api/instances/postInstanceWeeklySlot.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { WeeklySlot } from "../client"; +import type { CreateWeeklySlotBody } from "../offerings/postOfferingWeeklySlot"; + +// Adds a slot to the section's own week; from here its own rows are the plan. +export function postInstanceWeeklySlot(id: string, body: CreateWeeklySlotBody): Promise { + return client(`/instances/${id}/weekly-plan`, { method: "POST", body }); +} diff --git a/src/api/offerings/deleteOfferingById.ts b/src/api/offerings/deleteOfferingById.ts new file mode 100644 index 0000000..75f3fc1 --- /dev/null +++ b/src/api/offerings/deleteOfferingById.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Manager+. A 409 `offering_in_use` while any section still teaches from it. +export function deleteOfferingById(id: string): Promise { + return client(`/offerings/${id}`, { method: "DELETE" }); +} diff --git a/src/api/offerings/deleteOfferingExamWeightByKind.ts b/src/api/offerings/deleteOfferingExamWeightByKind.ts new file mode 100644 index 0000000..424215f --- /dev/null +++ b/src/api/offerings/deleteOfferingExamWeightByKind.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; + +// Drops the template's row; the settings weight applies again. +export function deleteOfferingExamWeightByKind(id: string, kind: string): Promise { + return client(`/offerings/${id}/exam-weights/${encodeURIComponent(kind)}`, { method: "DELETE" }); +} diff --git a/src/api/offerings/deleteOfferingSubjectById.ts b/src/api/offerings/deleteOfferingSubjectById.ts new file mode 100644 index 0000000..de7df40 --- /dev/null +++ b/src/api/offerings/deleteOfferingSubjectById.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteOfferingSubjectById(id: string, subjectId: string): Promise { + return client(`/offerings/${id}/subjects/${subjectId}`, { method: "DELETE" }); +} diff --git a/src/api/offerings/deleteOfferingWeeklySlotById.ts b/src/api/offerings/deleteOfferingWeeklySlotById.ts new file mode 100644 index 0000000..84e7768 --- /dev/null +++ b/src/api/offerings/deleteOfferingWeeklySlotById.ts @@ -0,0 +1,5 @@ +import { client } from "../client"; + +export function deleteOfferingWeeklySlotById(id: string, slotId: string): Promise { + return client(`/offerings/${id}/weekly-plan/${slotId}`, { method: "DELETE" }); +} diff --git a/src/api/offerings/getOfferingById.ts b/src/api/offerings/getOfferingById.ts new file mode 100644 index 0000000..e42c615 --- /dev/null +++ b/src/api/offerings/getOfferingById.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { Offering } from "../client"; + +// The raw template row: a null field inherits, it is not the resolved value. +export function getOfferingById(id: string, signal?: AbortSignal): Promise { + return client(`/offerings/${id}`, { signal }); +} diff --git a/src/api/offerings/getOfferingExamWeights.ts b/src/api/offerings/getOfferingExamWeights.ts new file mode 100644 index 0000000..64b14cd --- /dev/null +++ b/src/api/offerings/getOfferingExamWeights.ts @@ -0,0 +1,6 @@ +import { client } from "../client"; +import type { ExamWeightEntry } from "../client"; + +export function getOfferingExamWeights(id: string, signal?: AbortSignal): Promise<{ weights: ExamWeightEntry[] }> { + return client<{ weights: ExamWeightEntry[] }>(`/offerings/${id}/exam-weights`, { signal }); +} diff --git a/src/api/offerings/getOfferingSubjects.ts b/src/api/offerings/getOfferingSubjects.ts new file mode 100644 index 0000000..a3858ae --- /dev/null +++ b/src/api/offerings/getOfferingSubjects.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { Subject } from "../client"; + +// The topics every inheriting section at this grade teaches. +export function getOfferingSubjects(id: string, signal?: AbortSignal): Promise { + return client(`/offerings/${id}/subjects`, { signal }); +} diff --git a/src/api/offerings/getOfferingWeeklyPlan.ts b/src/api/offerings/getOfferingWeeklyPlan.ts new file mode 100644 index 0000000..1097041 --- /dev/null +++ b/src/api/offerings/getOfferingWeeklyPlan.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { WeeklySlot } from "../client"; + +// The template week, weekday first, then start time. +export function getOfferingWeeklyPlan(id: string, signal?: AbortSignal): Promise { + return client(`/offerings/${id}/weekly-plan`, { signal }); +} diff --git a/src/api/offerings/getOfferings.ts b/src/api/offerings/getOfferings.ts new file mode 100644 index 0000000..cd89a60 --- /dev/null +++ b/src/api/offerings/getOfferings.ts @@ -0,0 +1,15 @@ +import { client } from "../client"; +import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; +import type { Offering } from "../client"; + +export type OfferingListParams = PageParams & { course?: string; grade_level?: number }; + +export async function getOfferings(params?: OfferingListParams, signal?: AbortSignal): Promise> { + const query = new URLSearchParams(); + appendPageParams(query, params); + if (params?.course) query.set("course", params.course); + if (params?.grade_level != null) query.set("grade_level", String(params.grade_level)); + const value = query.toString(); + const data = await client(`/offerings${value ? `?${value}` : ""}`, { signal }); + return normalizePage(data); +} diff --git a/src/api/offerings/index.ts b/src/api/offerings/index.ts new file mode 100644 index 0000000..8f1372d --- /dev/null +++ b/src/api/offerings/index.ts @@ -0,0 +1,14 @@ +export * from "./getOfferings"; +export * from "./getOfferingById"; +export * from "./postOffering"; +export * from "./patchOfferingById"; +export * from "./deleteOfferingById"; +export * from "./getOfferingSubjects"; +export * from "./postOfferingSubject"; +export * from "./deleteOfferingSubjectById"; +export * from "./getOfferingWeeklyPlan"; +export * from "./postOfferingWeeklySlot"; +export * from "./deleteOfferingWeeklySlotById"; +export * from "./getOfferingExamWeights"; +export * from "./patchOfferingExamWeight"; +export * from "./deleteOfferingExamWeightByKind"; diff --git a/src/api/offerings/patchOfferingById.ts b/src/api/offerings/patchOfferingById.ts new file mode 100644 index 0000000..2ad7de0 --- /dev/null +++ b/src/api/offerings/patchOfferingById.ts @@ -0,0 +1,15 @@ +import { client } from "../client"; +import type { Offering } from "../client"; + +/** Omit to keep; an explicit null clears the field back to inherit. */ +export type UpdateOfferingBody = Partial<{ + title: string | null; + description: string | null; + default_ders_saati: number | null; + default_counts_toward_karne: boolean | null; +}>; + +// Manager+. Sections without their own override follow the change at once. +export function patchOfferingById(id: string, body: UpdateOfferingBody): Promise { + return client(`/offerings/${id}`, { method: "PATCH", body }); +} diff --git a/src/api/offerings/patchOfferingExamWeight.ts b/src/api/offerings/patchOfferingExamWeight.ts new file mode 100644 index 0000000..1e37aaa --- /dev/null +++ b/src/api/offerings/patchOfferingExamWeight.ts @@ -0,0 +1,8 @@ +import { client } from "../client"; +import type { ExamWeightEntry } from "../client"; + +// Manager+. `kind` must be one the school runs (400 `unknown_exam_kind`); +// `weight` 1..100. Inheriting sections pick the change up at once. +export function patchOfferingExamWeight(id: string, body: ExamWeightEntry): Promise<{ weights: ExamWeightEntry[] }> { + return client<{ weights: ExamWeightEntry[] }>(`/offerings/${id}/exam-weights`, { method: "PATCH", body }); +} diff --git a/src/api/offerings/postOffering.ts b/src/api/offerings/postOffering.ts new file mode 100644 index 0000000..9b9c6c0 --- /dev/null +++ b/src/api/offerings/postOffering.ts @@ -0,0 +1,17 @@ +import { client } from "../client"; +import type { Offering } from "../client"; + +export type CreateOfferingBody = { + course: string; + grade_level: number; + title?: string | null; + description?: string | null; + default_ders_saati?: number | null; + default_counts_toward_karne?: boolean | null; +}; + +// Manager+. Only a `course`-kind ders has a grade axis; a second template for +// the same (course, grade) is a 409 `offering_exists`. +export function postOffering(body: CreateOfferingBody): Promise { + return client("/offerings", { method: "POST", body }); +} diff --git a/src/api/offerings/postOfferingSubject.ts b/src/api/offerings/postOfferingSubject.ts new file mode 100644 index 0000000..fc95d42 --- /dev/null +++ b/src/api/offerings/postOfferingSubject.ts @@ -0,0 +1,7 @@ +import { client } from "../client"; +import type { Subject } from "../client"; + +// Manager+. Re-selecting an already selected topic is a no-op success. +export function postOfferingSubject(id: string, subjectId: string): Promise { + return client(`/offerings/${id}/subjects`, { method: "POST", body: { subject: subjectId } }); +} diff --git a/src/api/offerings/postOfferingWeeklySlot.ts b/src/api/offerings/postOfferingWeeklySlot.ts new file mode 100644 index 0000000..539d13c --- /dev/null +++ b/src/api/offerings/postOfferingWeeklySlot.ts @@ -0,0 +1,10 @@ +import { client } from "../client"; +import type { WeeklySlot } from "../client"; + +/** Minutes past midnight; `weekday` 1 (Monday) .. 7. A null topic uses the title. */ +export type CreateWeeklySlotBody = { weekday: number; starts_at: number; ends_at: number; topic?: string | null }; + +// Manager+. 409 `slot_overlap` for an intersecting window, `slot_cap` when full. +export function postOfferingWeeklySlot(id: string, body: CreateWeeklySlotBody): Promise { + return client(`/offerings/${id}/weekly-plan`, { method: "POST", body }); +} diff --git a/src/lib/student-directory.test.ts b/src/lib/student-directory.test.ts index 9467a9a..3c12d61 100644 --- a/src/lib/student-directory.test.ts +++ b/src/lib/student-directory.test.ts @@ -2,8 +2,8 @@ import { describe, expect, test } from "vitest"; import type { ClassGroup, PersonRef } from "@/api/client"; import { sortByClass } from "@/lib/student-directory"; -const cls = (name: string, grade: string | null): ClassGroup => ({ - id: name, creator: null, name, grade, year: null, teacher: null, +const cls = (name: string, gradeLevel: number): ClassGroup => ({ + id: name, creator: null, name, grade_level: gradeLevel, year: null, teacher: null, }); const person = (name: string): PersonRef => ({ id: name, username: name.toLowerCase(), display_name: name, student_number: null, @@ -12,12 +12,12 @@ const person = (name: string): PersonRef => ({ describe("sortByClass", () => { test("orders by grade, then şube, then name; classless students last", () => { const rows = [ - { person: person("Zeynep"), classes: [cls("10-B", "10")] }, + { person: person("Zeynep"), classes: [cls("10-B", 10)] }, { person: person("Ali"), classes: [] }, - { person: person("Can"), classes: [cls("9-A", "9")] }, - { person: person("Ayşe"), classes: [cls("10-A", "10")] }, - { person: person("Burak"), classes: [cls("10-B", "10")] }, - { person: person("Deniz"), classes: [cls("9-B", "9")] }, + { person: person("Can"), classes: [cls("9-A", 9)] }, + { person: person("Ayşe"), classes: [cls("10-A", 10)] }, + { person: person("Burak"), classes: [cls("10-B", 10)] }, + { person: person("Deniz"), classes: [cls("9-B", 9)] }, ]; expect(sortByClass(rows).map((row) => row.person.display_name)) .toEqual(["Can", "Deniz", "Ayşe", "Burak", "Zeynep", "Ali"]); @@ -25,8 +25,8 @@ describe("sortByClass", () => { test("files a student in several classes under the earliest one", () => { const rows = [ - { person: person("Ece"), classes: [cls("10-B", "10"), cls("9-A", "9")] }, - { person: person("Mert"), classes: [cls("9-B", "9")] }, + { person: person("Ece"), classes: [cls("10-B", 10), cls("9-A", 9)] }, + { person: person("Mert"), classes: [cls("9-B", 9)] }, ]; const sorted = sortByClass(rows); expect(sorted.map((row) => row.person.display_name)).toEqual(["Ece", "Mert"]);