forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

homework-queue.test.ts45 lines, 1.5 KiBHistoryRawDownload
1import type { Homework, HomeworkRosterEntry } from "@/api/client";
2import { queueCandidates, queueRow } from "./homework-queue";
3
4const DAY = 24 * 60 * 60 * 1000;
5const now = Date.UTC(2026, 8, 19, 9);
6const hw = (id: string, due: number, createdBy = "t-1"): Homework => ({
7 id,
8 class_course: "i-1",
9 subject: "s-1",
10 title: id,
11 description: null,
12 due_at: due,
13 assigned: null,
14 created_by: createdBy,
15 created_at: now - 30 * DAY,
16});
17const row = (state: Partial<HomeworkRosterEntry>): HomeworkRosterEntry => ({
18 user: "u",
19 submission: null,
20 result: null,
21 missing: false,
22 unenrolled: false,
23 ...state,
24});
25
26it("keeps the teacher's own homework due around now, closest first", () => {
27 const picked = queueCandidates(
28 [hw("old", now - 20 * DAY), hw("yesterday", now - DAY), hw("other-teacher", now - DAY, "t-2"), hw("tomorrow", now + DAY), hw("next-week", now + 7 * DAY), hw("last-week", now - 7 * DAY)],
29 "t-1",
30 now,
31 );
32 expect(picked.map((item) => item.id)).toEqual(["yesterday", "tomorrow", "last-week"]);
33});
34
35it("counts missing and ungraded work, leaving unenrolled rows out", () => {
36 const submission = { text: "done", submitted_at: now, updated_at: now, late: false, files: [] };
37 const counts = queueRow(hw("h", now), [
38 row({ missing: true }),
39 row({ missing: true, unenrolled: true }),
40 row({ submission }),
41 row({ submission, result: { mark: 80 } as never }),
42 row({}),
43 ]);
44 expect(counts).toMatchObject({ missing: 1, toGrade: 1 });
45});