forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

insight-students.test.ts43 lines, 1.6 KiBHistoryRawDownload
1import type { PersonRef, StudentInsight } from "@/api/client";
2import { insightOverview, loadStudentSignals } from "./insight-students";
3import { toStudentSignal } from "./insight-run-report";
4
5const person = (id: string): PersonRef => ({ id, username: id, display_name: id.toUpperCase() });
6const insight = (id: string, average: number, rate: number, attention: number): StudentInsight => ({
7 user_id: id,
8 summary: {
9 confidence: "high",
10 computed_at: 1,
11 marks: { courses: { c1: { n_marks: 2, average } } },
12 attendance: { overall: { rate, n_obs: 10 } },
13 } as never,
14 attention: Array.from({ length: attention }, () => ({}) as never),
15 cards: [],
16 segments: [],
17});
18
19it("reads every student, turning a failed read into that row's error", async () => {
20 const rows: string[] = [];
21 await loadStudentSignals([person("a"), person("b")], (row) => rows.push(`${row.id}:${row.state}`), async (id) => {
22 if (id === "b") throw new Error("boom");
23 return insight(id, 80, 0.9, 0);
24 });
25 expect(rows.sort()).toEqual(["a:ok", "b:error"]);
26});
27
28it("summarises only what the summaries measured", () => {
29 const signals = [
30 toStudentSignal({ id: "a", name: "A" }, insight("a", 80, 0.9, 2), null),
31 toStudentSignal({ id: "b", name: "B" }, insight("b", 60, 0.7, 0), null),
32 toStudentSignal({ id: "c", name: "C" }, { user_id: "c", summary: null, attention: [], cards: [], segments: [] }, null),
33 toStudentSignal({ id: "d", name: "D" }, null, null),
34 ];
35 expect(insightOverview(signals, 5)).toEqual({
36 total: 5,
37 loaded: 3,
38 analysed: 2,
39 needAttention: 1,
40 marksAverage: 70,
41 attendanceRate: 0.8,
42 });
43});