diff --git a/apps/client/src/consumers/sbhsApi/__snapshots__/useDtt.test.ts.snap b/apps/client/src/consumers/sbhsApi/__snapshots__/useDtt.test.ts.snap new file mode 100644 index 0000000..5a52a1d --- /dev/null +++ b/apps/client/src/consumers/sbhsApi/__snapshots__/useDtt.test.ts.snap @@ -0,0 +1,192 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`the schema > parses a day timetable with no periods 1`] = ` +{ + "date": "2023-09-20T00:00:00.000+10:00", + "periods": [ + { + "date": "2023-09-20", + "endTime": "2023-09-20T08:00:00.000+10:00", + "key": "0-transition", + "name": "Transition to Period 0", + "shortName": "transition", + "startTime": "2023-09-20T00:00:00.000+10:00", + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T08:57:00.000+10:00", + "key": "0", + "name": "Period 0", + "room": undefined, + "roomTo": undefined, + "shortName": "0", + "startTime": "2023-09-20T08:00:00.000+10:00", + "teacher": undefined, + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T09:00:00.000+10:00", + "key": "RC", + "name": "Roll Call", + "room": undefined, + "roomTo": undefined, + "shortName": "RC", + "startTime": "2023-09-20T08:57:00.000+10:00", + "teacher": undefined, + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T10:00:00.000+10:00", + "key": "1", + "name": "Period 1", + "room": undefined, + "roomTo": undefined, + "shortName": "1", + "startTime": "2023-09-20T09:00:00.000+10:00", + "teacher": undefined, + }, + { + "date": "2023-09-20", + "endTime": "2023-09-20T10:05:00.000+10:00", + "key": "2-transition", + "name": "Transition to Period 2", + "shortName": "transition", + "startTime": "2023-09-20T10:00:00.000+10:00", + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T11:05:00.000+10:00", + "key": "2", + "name": "Period 2", + "room": undefined, + "roomTo": undefined, + "shortName": "2", + "startTime": "2023-09-20T10:05:00.000+10:00", + "teacher": undefined, + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T11:22:00.000+10:00", + "key": "R", + "name": "Recess", + "room": undefined, + "roomTo": undefined, + "shortName": "R", + "startTime": "2023-09-20T11:05:00.000+10:00", + "teacher": undefined, + }, + { + "date": "2023-09-20", + "endTime": "2023-09-20T11:25:00.000+10:00", + "key": "3-transition", + "name": "Transition to Period 3", + "shortName": "transition", + "startTime": "2023-09-20T11:22:00.000+10:00", + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T12:25:00.000+10:00", + "key": "3", + "name": "Period 3", + "room": undefined, + "roomTo": undefined, + "shortName": "3", + "startTime": "2023-09-20T11:25:00.000+10:00", + "teacher": undefined, + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T12:45:00.000+10:00", + "key": "WFL1", + "name": "Lunch 1", + "room": undefined, + "roomTo": undefined, + "shortName": "WFL1", + "startTime": "2023-09-20T12:25:00.000+10:00", + "teacher": undefined, + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T13:02:00.000+10:00", + "key": "WFL2", + "name": "Lunch 2", + "room": undefined, + "roomTo": undefined, + "shortName": "WFL2", + "startTime": "2023-09-20T12:45:00.000+10:00", + "teacher": undefined, + }, + { + "date": "2023-09-20", + "endTime": "2023-09-20T13:05:00.000+10:00", + "key": "4-transition", + "name": "Transition to Period 4", + "shortName": "transition", + "startTime": "2023-09-20T13:02:00.000+10:00", + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T14:05:00.000+10:00", + "key": "4", + "name": "Period 4", + "room": undefined, + "roomTo": undefined, + "shortName": "4", + "startTime": "2023-09-20T13:05:00.000+10:00", + "teacher": undefined, + }, + { + "date": "2023-09-20", + "endTime": "2023-09-20T14:10:00.000+10:00", + "key": "5-transition", + "name": "Transition to Period 5", + "shortName": "transition", + "startTime": "2023-09-20T14:05:00.000+10:00", + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": "2023-09-20T15:10:00.000+10:00", + "key": "5", + "name": "Period 5", + "room": undefined, + "roomTo": undefined, + "shortName": "5", + "startTime": "2023-09-20T14:10:00.000+10:00", + "teacher": undefined, + }, + { + "casual": undefined, + "colour": "transparent", + "date": "2023-09-20", + "endTime": null, + "key": "EoD", + "name": "End of Day", + "room": undefined, + "roomTo": undefined, + "shortName": "EoD", + "startTime": "2023-09-20T15:10:00.000+10:00", + "teacher": undefined, + }, + ], +} +`; \ No newline at end of file diff --git a/apps/client/src/consumers/sbhsApi/__snapshots__/useTimetable.test.ts.snap b/apps/client/src/consumers/sbhsApi/__snapshots__/useTimetable.test.ts.snap new file mode 100644 index 0000000..d0a18db --- /dev/null +++ b/apps/client/src/consumers/sbhsApi/__snapshots__/useTimetable.test.ts.snap @@ -0,0 +1,1474 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`the schema > parses a schema with morning periods 1`] = ` +{ + "days": [ + { + "dayname": "MonA", + "periods": { + "1": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + "2": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "3": { + "room": "507", + "teacher": "ROWJ", + "title": "COM CX", + "year": "9", + }, + "4": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "5": { + "room": "507", + "teacher": "ROWJ", + "title": "COM CX", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "TueA", + "periods": { + "1": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "2": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "5": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "WedA", + "periods": { + "1": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "2": { + "room": "202", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "3": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + "4": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "5": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "ThuA", + "periods": { + "1": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "2": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "3": { + "room": "506", + "teacher": "MARD", + "title": "COM CX", + "year": "9", + }, + "4": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + "5": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "FriA", + "periods": { + "0": { + "room": null, + "teacher": "KAYJ", + "title": "Scripture 9", + "year": "9", + }, + "1": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "2": { + "room": "208", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "3": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "4": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "5": { + "room": "205", + "teacher": "PAUV", + "title": "VED A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "MonB", + "periods": { + "1": { + "room": "507", + "teacher": "ROWJ", + "title": "COM CX", + "year": "9", + }, + "2": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "3": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "4": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "TueB", + "periods": { + "1": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "2": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "3": { + "room": "203", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "5": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "WedB", + "periods": { + "1": { + "room": "205", + "teacher": "PAUV", + "title": "VED A", + "year": "9", + }, + "2": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "3": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + "4": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "5": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "ThuB", + "periods": { + "1": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "2": { + "room": "301", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "3": { + "room": "506", + "teacher": "MARD", + "title": "COM CX", + "year": "9", + }, + "4": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + "5": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "FriB", + "periods": { + "0": { + "room": null, + "teacher": "KAYJ", + "title": "Scripture 9", + "year": "9", + }, + "1": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "2": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "5": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "MonC", + "periods": { + "1": { + "room": "608", + "teacher": "ROWJ", + "title": "COM CX", + "year": "9", + }, + "2": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "3": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "4": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "TueC", + "periods": { + "1": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "2": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "3": { + "room": "507", + "teacher": "ROWJ", + "title": "COM CX", + "year": "9", + }, + "4": { + "room": "403", + "teacher": "GENM", + "title": "HIS CY", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "WedC", + "periods": { + "1": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "2": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "3": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "4": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "ThuC", + "periods": { + "1": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "2": { + "room": "611", + "teacher": "STEL", + "title": "PDM CZ", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + "5": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "FriC", + "periods": { + "0": { + "room": null, + "teacher": "KAYJ", + "title": "Scripture 9", + "year": "9", + }, + "1": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "2": { + "room": "102", + "teacher": "ZHEM", + "title": "MAT B", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "5": { + "room": "205", + "teacher": "PAUV", + "title": "VED A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "STEL", + "title": "RC 9S", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + ], + "subjects": [ + { + "colour": "7f5252", + "fullTeacher": "", + "shortTitle": "SP 9", + "subject": "Sport Yr9", + "teacher": null, + "title": "9 Sport 9", + "year": "9", + }, + { + "colour": "640064", + "fullTeacher": "V Paul", + "shortTitle": "VED A", + "subject": "Values Education Yr9", + "teacher": "PAUV", + "title": "9 Values Education A", + "year": "9", + }, + { + "colour": "004040", + "fullTeacher": "B Hayman", + "shortTitle": "PDH A", + "subject": "PDHPE Yr9", + "teacher": "HAYB", + "title": "9 PDHPE A", + "year": "9", + }, + { + "colour": "008080", + "fullTeacher": "J Rowlands", + "shortTitle": "COM CX", + "subject": "Commerce Yr9", + "teacher": "ROWJ", + "title": "9 Commerce CX", + "year": "9", + }, + { + "colour": "dc5221", + "fullTeacher": "M Zheng", + "shortTitle": "MAT B", + "subject": "Mathematics 5.3 Yr9", + "teacher": "ZHEM", + "title": "9 Mathematics 5.3 B", + "year": "9", + }, + { + "colour": "c0c0c0", + "fullTeacher": "K Rich", + "shortTitle": "YA RST", + "subject": "Year Adviser", + "teacher": "RICK", + "title": "9 Year RST", + "year": "9", + }, + { + "colour": "c0c0c0", + "fullTeacher": "J Kay", + "shortTitle": "Scripture 9", + "subject": "Scripture Yr9", + "teacher": "KAYJ", + "title": "9 Scripture 9", + "year": "9", + }, + { + "colour": "008080", + "fullTeacher": "H Stephens", + "shortTitle": "GEO A", + "subject": "Geography Yr9", + "teacher": "STEH", + "title": "9 Geography A", + "year": "9", + }, + { + "colour": "ffd718", + "fullTeacher": "N Lau", + "shortTitle": "ENG A", + "subject": "English Yr9", + "teacher": "LAUN", + "title": "9 English A", + "year": "9", + }, + { + "colour": "c488ff", + "fullTeacher": "L Stewart", + "shortTitle": "PDM CZ", + "subject": "Photography & Digital Media Yr9", + "teacher": "STEL", + "title": "9 Photography & Digital Media CZ", + "year": "9", + }, + { + "colour": "2ee8d7", + "fullTeacher": "O The", + "shortTitle": "SCI A", + "subject": "Science Yr9", + "teacher": "THEO", + "title": "9 Science A", + "year": "9", + }, + { + "colour": "9d9d4f", + "fullTeacher": "M Genias", + "shortTitle": "HIS CY", + "subject": "History Yr9", + "teacher": "GENM", + "title": "9 History CY", + "year": "9", + }, + ], +} +`; + +exports[`the schema > parses a timetable with no morning periods 1`] = ` +{ + "days": [ + { + "dayname": "MonA", + "periods": { + "1": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + "2": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "3": { + "room": "403", + "teacher": "GENM", + "title": "HIS BX", + "year": "9", + }, + "4": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "5": { + "room": "403", + "teacher": "GENM", + "title": "HIS BX", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "TueA", + "periods": { + "1": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "2": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "502", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "5": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "WedA", + "periods": { + "1": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "2": { + "room": "202", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "3": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + "4": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "5": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "ThuA", + "periods": { + "1": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "2": { + "room": "502", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "3": { + "room": "403", + "teacher": "PAUV", + "title": "HIS BX", + "year": "9", + }, + "4": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + "5": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "FriA", + "periods": { + "1": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "2": { + "room": "208", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "3": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "4": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "5": { + "room": "205", + "teacher": "PAUV", + "title": "VED A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "MonB", + "periods": { + "1": { + "room": "403", + "teacher": "GENM", + "title": "HIS BX", + "year": "9", + }, + "2": { + "room": "802", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "3": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "4": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "TueB", + "periods": { + "1": { + "room": "502", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "2": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "3": { + "room": "203", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "5": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "WedB", + "periods": { + "1": { + "room": "205", + "teacher": "PAUV", + "title": "VED A", + "year": "9", + }, + "2": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "3": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + "4": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "5": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "ThuB", + "periods": { + "1": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "2": { + "room": "301", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "3": { + "room": "403", + "teacher": "PAUV", + "title": "HIS BX", + "year": "9", + }, + "4": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + "5": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "FriB", + "periods": { + "1": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "2": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "5": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "MonC", + "periods": { + "1": { + "room": "403", + "teacher": "GENM", + "title": "HIS BX", + "year": "9", + }, + "2": { + "room": "502", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "3": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "4": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "TueC", + "periods": { + "1": { + "room": "502", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "2": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "3": { + "room": "403", + "teacher": "GENM", + "title": "HIS BX", + "year": "9", + }, + "4": { + "room": "504", + "teacher": "HUYD", + "title": "GRT BY", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,4,MTL1,MTL2,5", + }, + { + "dayname": "WedC", + "periods": { + "1": { + "room": "902", + "teacher": "HAYB", + "title": "PDH A", + "year": "9", + }, + "2": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "3": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "4": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "5": { + "room": "202", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "ThuC", + "periods": { + "1": { + "room": "106", + "teacher": "WANA", + "title": "MAT A", + "year": "9", + }, + "2": { + "room": "802", + "teacher": "GIFR", + "title": "D&T CZ", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + "5": { + "room": null, + "teacher": null, + "title": "SP 9", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + { + "dayname": "FriC", + "periods": { + "1": { + "room": "213", + "teacher": "LAUN", + "title": "ENG A", + "year": "9", + }, + "2": { + "room": "105", + "teacher": "JAMJ", + "title": "MAT A", + "year": "9", + }, + "3": { + "room": "702", + "teacher": "THEO", + "title": "SCI A", + "year": "9", + }, + "4": { + "room": "506", + "teacher": "STEH", + "title": "GEO A", + "year": "9", + }, + "5": { + "room": "205", + "teacher": "PAUV", + "title": "VED A", + "year": "9", + }, + }, + "rollcall": { + "room": null, + "teacher": "JACB", + "title": "RC 9E", + }, + "routine": "0,RC,1,2,R,3,WFL1,WFL2,4,5", + }, + ], + "subjects": [ + { + "colour": "448ae6", + "fullTeacher": "R Gifford", + "shortTitle": "D&T CZ", + "subject": "Design & Technology Yr9", + "teacher": "GIFR", + "title": "9 Design & Technology CZ", + "year": "9", + }, + { + "colour": "7f5252", + "fullTeacher": "", + "shortTitle": "SP 9", + "subject": "Sport Yr9", + "teacher": null, + "title": "9 Sport 9", + "year": "9", + }, + { + "colour": "640064", + "fullTeacher": "V Paul", + "shortTitle": "VED A", + "subject": "Values Education Yr9", + "teacher": "PAUV", + "title": "9 Values Education A", + "year": "9", + }, + { + "colour": "004040", + "fullTeacher": "B Hayman", + "shortTitle": "PDH A", + "subject": "PDHPE Yr9", + "teacher": "HAYB", + "title": "9 PDHPE A", + "year": "9", + }, + { + "colour": "c0c0c0", + "fullTeacher": "J James", + "shortTitle": "YA EFM", + "subject": "Year Adviser", + "teacher": "JAMJ", + "title": "9 Year EFM", + "year": "9", + }, + { + "colour": "9d9d4f", + "fullTeacher": "M Genias", + "shortTitle": "HIS BX", + "subject": "History Yr9", + "teacher": "GENM", + "title": "9 History BX", + "year": "9", + }, + { + "colour": "008080", + "fullTeacher": "H Stephens", + "shortTitle": "GEO A", + "subject": "Geography Yr9", + "teacher": "STEH", + "title": "9 Geography A", + "year": "9", + }, + { + "colour": "dc5221", + "fullTeacher": "A Wang", + "shortTitle": "MAT A", + "subject": "Mathematics 5.3 Yr9", + "teacher": "WANA", + "title": "9 Mathematics 5.3 A", + "year": "9", + }, + { + "colour": "448ae6", + "fullTeacher": "D Huynh", + "shortTitle": "GRT BY", + "subject": "Graphics Technology Yr9", + "teacher": "HUYD", + "title": "9 Graphics Technology BY", + "year": "9", + }, + { + "colour": "ffd718", + "fullTeacher": "N Lau", + "shortTitle": "ENG A", + "subject": "English Yr9", + "teacher": "LAUN", + "title": "9 English A", + "year": "9", + }, + { + "colour": "2ee8d7", + "fullTeacher": "O The", + "shortTitle": "SCI A", + "subject": "Science Yr9", + "teacher": "THEO", + "title": "9 Science A", + "year": "9", + }, + ], +} +`; diff --git a/apps/client/src/consumers/sbhsApi/useDtt.test.ts b/apps/client/src/consumers/sbhsApi/useDtt.test.ts new file mode 100644 index 0000000..4d6911d --- /dev/null +++ b/apps/client/src/consumers/sbhsApi/useDtt.test.ts @@ -0,0 +1,124 @@ +import { dttSchema } from "./schemas"; +import { describe, expect, test } from "vitest"; + +describe("the schema", () => { + test("parses a day timetable with no periods", () => { + const dtt = { + status: "OK", + date: "2023-09-20", + bells: [ + { + period: "0", + startTime: "08:00", + endTime: "08:57", + type: "O", + time: "08:00", + bell: "0", + bellDisplay: "Period 0", + }, + { + period: "RC", + startTime: "08:57", + endTime: "09:00", + type: "O", + time: "08:57", + bell: "RC", + bellDisplay: "Roll Call", + }, + { + period: "1", + startTime: "09:00", + endTime: "10:00", + type: "T", + time: "09:00", + bell: "1", + bellDisplay: "Period 1", + }, + { + period: "2", + startTime: "10:05", + endTime: "11:05", + type: "T", + time: "10:05", + bell: "2", + bellDisplay: "Period 2", + }, + { + period: "R", + startTime: "11:05", + endTime: "11:22", + type: "R", + time: "11:05", + bell: "R", + bellDisplay: "Recess", + }, + { + period: "3", + startTime: "11:25", + endTime: "12:25", + type: "T", + time: "11:25", + bell: "3", + bellDisplay: "Period 3", + }, + { + period: "WFL1", + startTime: "12:25", + endTime: "12:45", + type: "R", + time: "12:25", + bell: "WFL1", + bellDisplay: "Lunch 1", + }, + { + period: "WFL2", + startTime: "12:45", + endTime: "13:02", + type: "R", + time: "12:45", + bell: "WFL2", + bellDisplay: "Lunch 2", + }, + { + period: "4", + startTime: "13:05", + endTime: "14:05", + type: "T", + time: "13:05", + bell: "4", + bellDisplay: "Period 4", + }, + { + period: "5", + startTime: "14:10", + endTime: "15:10", + type: "T", + time: "14:10", + bell: "5", + bellDisplay: "Period 5", + }, + { + period: "EoD", + startTime: "15:10", + endTime: null, + type: "O", + time: "15:10", + bell: "EoD", + bellDisplay: "End of Day", + }, + ], + timetable: { + timetable: { + periods: [], + }, + subjects: [], + }, + roomVariations: [], + classVariations: [], + serverTimezone: "36000", + shouldDisplayVariations: true, + }; + + expect(dttSchema.parse(dtt)).toMatchSnapshot(); + }); +}); diff --git a/apps/client/src/consumers/sbhsApi/useTimetable.test.ts b/apps/client/src/consumers/sbhsApi/useTimetable.test.ts new file mode 100644 index 0000000..c7c0a32 --- /dev/null +++ b/apps/client/src/consumers/sbhsApi/useTimetable.test.ts @@ -0,0 +1,1706 @@ +import { timetableSchema } from "./schemas"; +import { describe, expect, test } from "vitest"; + +describe("the schema", () => { + test("parses a timetable with no morning periods", () => { + const timetable = { + student: { + surname: "DOE", + givenname: "John", + gender: "M", + DOB: null, + roll: "RC.9E", + BoSNumber: null, + year: "9", + years: ["9"], + studentId: "444125345", + }, + subjects: [ + { + title: "9 Design & Technology CZ", + shortTitle: "D&T CZ", + teacher: "GIFR", + subject: "Design & Technology Yr9", + fullTeacher: "R Gifford", + year: "9", + colour: "448ae6", + }, + { + title: "9 Sport 9", + shortTitle: "SP 9", + teacher: null, + subject: "Sport Yr9", + fullTeacher: "", + year: "9", + colour: "7f5252", + }, + { + title: "9 Values Education A", + shortTitle: "VED A", + teacher: "PAUV", + subject: "Values Education Yr9", + fullTeacher: "V Paul", + year: "9", + colour: "640064", + }, + { + title: "9 PDHPE A", + shortTitle: "PDH A", + teacher: "HAYB", + subject: "PDHPE Yr9", + fullTeacher: "B Hayman", + year: "9", + colour: "004040", + }, + { + title: "9 Year EFM", + shortTitle: "YA EFM", + teacher: "JAMJ", + subject: "Year Adviser", + fullTeacher: "J James", + year: "9", + colour: "c0c0c0", + }, + { + title: "9 History BX", + shortTitle: "HIS BX", + teacher: "GENM", + subject: "History Yr9", + fullTeacher: "M Genias", + year: "9", + colour: "9d9d4f", + }, + { + title: "9 Geography A", + shortTitle: "GEO A", + teacher: "STEH", + subject: "Geography Yr9", + fullTeacher: "H Stephens", + year: "9", + colour: "008080", + }, + { + title: "9 Mathematics 5.3 A", + shortTitle: "MAT A", + teacher: "WANA", + subject: "Mathematics 5.3 Yr9", + fullTeacher: "A Wang", + year: "9", + colour: "dc5221", + }, + { + title: "9 Graphics Technology BY", + shortTitle: "GRT BY", + teacher: "HUYD", + subject: "Graphics Technology Yr9", + fullTeacher: "D Huynh", + year: "9", + colour: "448ae6", + }, + { + title: "9 English A", + shortTitle: "ENG A", + teacher: "LAUN", + subject: "English Yr9", + fullTeacher: "N Lau", + year: "9", + colour: "ffd718", + }, + { + title: "9 Science A", + shortTitle: "SCI A", + teacher: "THEO", + subject: "Science Yr9", + fullTeacher: "O The", + year: "9", + colour: "2ee8d7", + }, + ], + days: { + "1": { + dayname: "MonA", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + "2": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "3": { + title: "HIS BX", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "4": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "5": { + title: "HIS BX", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + }, + dayNumber: "1", + }, + "2": { + dayname: "TueA", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "2": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "D&T CZ", + teacher: "GIFR", + room: "502", + fullTeacher: "R Gifford", + year: "9", + }, + "5": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + }, + dayNumber: "2", + }, + "3": { + dayname: "WedA", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + "2": { + title: "PDH A", + teacher: "HAYB", + room: "202", + fullTeacher: "B Hayman", + year: "9", + }, + "3": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + "4": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "5": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + }, + dayNumber: "3", + }, + "4": { + dayname: "ThuA", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "2": { + title: "D&T CZ", + teacher: "GIFR", + room: "502", + fullTeacher: "R Gifford", + year: "9", + }, + "3": { + title: "HIS BX", + teacher: "PAUV", + room: "403", + fullTeacher: "V Paul", + year: "9", + }, + "4": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + "5": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + }, + dayNumber: "4", + }, + "5": { + dayname: "FriA", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "2": { + title: "ENG A", + teacher: "LAUN", + room: "208", + fullTeacher: "N Lau", + year: "9", + }, + "3": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "4": { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + "5": { + title: "VED A", + teacher: "PAUV", + room: "205", + fullTeacher: "V Paul", + year: "9", + }, + }, + dayNumber: "5", + }, + "6": { + dayname: "MonB", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "HIS BX", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "2": { + title: "D&T CZ", + teacher: "GIFR", + room: "802", + fullTeacher: "R Gifford", + year: "9", + }, + "3": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "4": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "6", + }, + "7": { + dayname: "TueB", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "D&T CZ", + teacher: "GIFR", + room: "502", + fullTeacher: "R Gifford", + year: "9", + }, + "2": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "203", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "5": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + }, + dayNumber: "7", + }, + "8": { + dayname: "WedB", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "VED A", + teacher: "PAUV", + room: "205", + fullTeacher: "V Paul", + year: "9", + }, + "2": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + "3": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + "4": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "5": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + }, + dayNumber: "8", + }, + "9": { + dayname: "ThuB", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "2": { + title: "SCI A", + teacher: "THEO", + room: "301", + fullTeacher: "O The", + year: "9", + }, + "3": { + title: "HIS BX", + teacher: "PAUV", + room: "403", + fullTeacher: "V Paul", + year: "9", + }, + "4": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + "5": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + }, + dayNumber: "9", + }, + "10": { + dayname: "FriB", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "2": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + "5": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + }, + dayNumber: "10", + }, + "11": { + dayname: "MonC", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "HIS BX", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "2": { + title: "D&T CZ", + teacher: "GIFR", + room: "502", + fullTeacher: "R Gifford", + year: "9", + }, + "3": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "4": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "11", + }, + "12": { + dayname: "TueC", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "D&T CZ", + teacher: "GIFR", + room: "502", + fullTeacher: "R Gifford", + year: "9", + }, + "2": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "3": { + title: "HIS BX", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "4": { + title: "GRT BY", + teacher: "HUYD", + room: "504", + fullTeacher: "D Huynh", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "12", + }, + "13": { + dayname: "WedC", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "2": { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + "3": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "4": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "13", + }, + "14": { + dayname: "ThuC", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "MAT A", + teacher: "WANA", + room: "106", + fullTeacher: "A Wang", + year: "9", + }, + "2": { + title: "D&T CZ", + teacher: "GIFR", + room: "802", + fullTeacher: "R Gifford", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + "5": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + }, + dayNumber: "14", + }, + "15": { + dayname: "FriC", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9E", + teacher: "JACB", + room: null, + }, + periods: { + "1": { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + "2": { + title: "MAT A", + teacher: "JAMJ", + room: "105", + fullTeacher: "J James", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "5": { + title: "VED A", + teacher: "PAUV", + room: "205", + fullTeacher: "V Paul", + year: "9", + }, + }, + dayNumber: "15", + }, + }, + rollcall: { + title: "Roll Call 9E", + shortTitle: "RC 9E", + teacher: "JACB", + subject: "Roll Call RC", + fullTeacher: "B Jackson", + year: "0", + colour: "000000", + }, + advisor: "", + }; + + expect(timetableSchema.parse(timetable)).toMatchSnapshot(); + }); + + test("parses a schema with morning periods", () => { + const timetable = { + student: { + surname: "DOE", + givenname: "John", + gender: "M", + DOB: null, + roll: "RC.9S", + BoSNumber: null, + year: "9", + years: ["9"], + studentId: "44412345", + }, + subjects: [ + { + title: "9 Sport 9", + shortTitle: "SP 9", + teacher: null, + subject: "Sport Yr9", + fullTeacher: "", + year: "9", + colour: "7f5252", + }, + { + title: "9 Values Education A", + shortTitle: "VED A", + teacher: "PAUV", + subject: "Values Education Yr9", + fullTeacher: "V Paul", + year: "9", + colour: "640064", + }, + { + title: "9 PDHPE A", + shortTitle: "PDH A", + teacher: "HAYB", + subject: "PDHPE Yr9", + fullTeacher: "B Hayman", + year: "9", + colour: "004040", + }, + { + title: "9 Commerce CX", + shortTitle: "COM CX", + teacher: "ROWJ", + subject: "Commerce Yr9", + fullTeacher: "J Rowlands", + year: "9", + colour: "008080", + }, + { + title: "9 Mathematics 5.3 B", + shortTitle: "MAT B", + teacher: "ZHEM", + subject: "Mathematics 5.3 Yr9", + fullTeacher: "M Zheng", + year: "9", + colour: "dc5221", + }, + { + title: "9 Year RST", + shortTitle: "YA RST", + teacher: "RICK", + subject: "Year Adviser", + fullTeacher: "K Rich", + year: "9", + colour: "c0c0c0", + }, + { + title: "9 Scripture 9", + shortTitle: "Scripture 9", + teacher: "KAYJ", + subject: "Scripture Yr9", + fullTeacher: "J Kay", + year: "9", + colour: "c0c0c0", + }, + { + title: "9 Geography A", + shortTitle: "GEO A", + teacher: "STEH", + subject: "Geography Yr9", + fullTeacher: "H Stephens", + year: "9", + colour: "008080", + }, + { + title: "9 English A", + shortTitle: "ENG A", + teacher: "LAUN", + subject: "English Yr9", + fullTeacher: "N Lau", + year: "9", + colour: "ffd718", + }, + { + title: "9 Photography & Digital Media CZ", + shortTitle: "PDM CZ", + teacher: "STEL", + subject: "Photography & Digital Media Yr9", + fullTeacher: "L Stewart", + year: "9", + colour: "c488ff", + }, + { + title: "9 Science A", + shortTitle: "SCI A", + teacher: "THEO", + subject: "Science Yr9", + fullTeacher: "O The", + year: "9", + colour: "2ee8d7", + }, + { + title: "9 History CY", + shortTitle: "HIS CY", + teacher: "GENM", + subject: "History Yr9", + fullTeacher: "M Genias", + year: "9", + colour: "9d9d4f", + }, + ], + days: { + "1": { + dayname: "MonA", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "2": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "3": { + title: "COM CX", + teacher: "ROWJ", + room: "507", + fullTeacher: "J Rowlands", + year: "9", + }, + "4": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "5": { + title: "COM CX", + teacher: "ROWJ", + room: "507", + fullTeacher: "J Rowlands", + year: "9", + }, + }, + dayNumber: "1", + }, + "2": { + dayname: "TueA", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "2": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "5": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + }, + dayNumber: "2", + }, + "3": { + dayname: "WedA", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + "2": { + title: "PDH A", + teacher: "HAYB", + room: "202", + fullTeacher: "B Hayman", + year: "9", + }, + "3": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "4": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "5": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + }, + dayNumber: "3", + }, + "4": { + dayname: "ThuA", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "2": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "3": { + title: "COM CX", + teacher: "MARD", + room: "506", + fullTeacher: "D Marsh", + year: "9", + }, + "4": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + "5": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + }, + dayNumber: "4", + }, + "5": { + dayname: "FriA", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: [ + { + title: "Scripture 9", + teacher: "KAYJ", + room: null, + fullTeacher: "J Kay", + year: "9", + }, + { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + { + title: "ENG A", + teacher: "LAUN", + room: "208", + fullTeacher: "N Lau", + year: "9", + }, + { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + { + title: "VED A", + teacher: "PAUV", + room: "205", + fullTeacher: "V Paul", + year: "9", + }, + ], + dayNumber: "5", + }, + "6": { + dayname: "MonB", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "COM CX", + teacher: "ROWJ", + room: "507", + fullTeacher: "J Rowlands", + year: "9", + }, + "2": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "3": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "4": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "6", + }, + "7": { + dayname: "TueB", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "2": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "203", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "5": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + }, + dayNumber: "7", + }, + "8": { + dayname: "WedB", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "VED A", + teacher: "PAUV", + room: "205", + fullTeacher: "V Paul", + year: "9", + }, + "2": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + "3": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "4": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "5": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + }, + dayNumber: "8", + }, + "9": { + dayname: "ThuB", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "2": { + title: "SCI A", + teacher: "THEO", + room: "301", + fullTeacher: "O The", + year: "9", + }, + "3": { + title: "COM CX", + teacher: "MARD", + room: "506", + fullTeacher: "D Marsh", + year: "9", + }, + "4": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + "5": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + }, + dayNumber: "9", + }, + "10": { + dayname: "FriB", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: [ + { + title: "Scripture 9", + teacher: "KAYJ", + room: null, + fullTeacher: "J Kay", + year: "9", + }, + { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + ], + dayNumber: "10", + }, + "11": { + dayname: "MonC", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "COM CX", + teacher: "ROWJ", + room: "608", + fullTeacher: "J Rowlands", + year: "9", + }, + "2": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "3": { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + "4": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "11", + }, + "12": { + dayname: "TueC", + routine: "0,RC,1,2,R,3,4,MTL1,MTL2,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "2": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "3": { + title: "COM CX", + teacher: "ROWJ", + room: "507", + fullTeacher: "J Rowlands", + year: "9", + }, + "4": { + title: "HIS CY", + teacher: "GENM", + room: "403", + fullTeacher: "M Genias", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "12", + }, + "13": { + dayname: "WedC", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "PDH A", + teacher: "HAYB", + room: "902", + fullTeacher: "B Hayman", + year: "9", + }, + "2": { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + "3": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "4": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "5": { + title: "ENG A", + teacher: "LAUN", + room: "202", + fullTeacher: "N Lau", + year: "9", + }, + }, + dayNumber: "13", + }, + "14": { + dayname: "ThuC", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: { + "1": { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + "2": { + title: "PDM CZ", + teacher: "STEL", + room: "611", + fullTeacher: "L Stewart", + year: "9", + }, + "3": { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + "4": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + "5": { + title: "SP 9", + teacher: null, + room: null, + fullTeacher: "", + year: "9", + }, + }, + dayNumber: "14", + }, + "15": { + dayname: "FriC", + routine: "0,RC,1,2,R,3,WFL1,WFL2,4,5", + rollcall: { + title: "RC 9S", + teacher: "STEL", + room: null, + }, + periods: [ + { + title: "Scripture 9", + teacher: "KAYJ", + room: null, + fullTeacher: "J Kay", + year: "9", + }, + { + title: "ENG A", + teacher: "LAUN", + room: "213", + fullTeacher: "N Lau", + year: "9", + }, + { + title: "MAT B", + teacher: "ZHEM", + room: "102", + fullTeacher: "M Zheng", + year: "9", + }, + { + title: "SCI A", + teacher: "THEO", + room: "702", + fullTeacher: "O The", + year: "9", + }, + { + title: "GEO A", + teacher: "STEH", + room: "506", + fullTeacher: "H Stephens", + year: "9", + }, + { + title: "VED A", + teacher: "PAUV", + room: "205", + fullTeacher: "V Paul", + year: "9", + }, + ], + dayNumber: "15", + }, + }, + rollcall: { + title: "Roll Call 9S", + shortTitle: "RC 9S", + teacher: "STEL", + subject: "Roll Call RC", + fullTeacher: "L Stewart", + year: "0", + colour: "000000", + }, + advisor: "", + }; + + expect(timetableSchema.parse(timetable)).toMatchSnapshot(); + }); +}); diff --git a/apps/client/src/services/OAuth2Actions/OAuth2Actions.test.ts b/apps/client/src/services/OAuth2Actions/OAuth2Actions.test.ts deleted file mode 100644 index bcedef3..0000000 --- a/apps/client/src/services/OAuth2Actions/OAuth2Actions.test.ts +++ /dev/null @@ -1,248 +0,0 @@ -import HTTPError from "../../errors/HTTPError"; -import NetworkError from "../../errors/NetworkError"; -import { FetchWrapper } from "../../interfaces/FetchWrapper"; -import { Notifier } from "../../interfaces/Notifier"; -import { AuthStatus } from "../../stores/auth"; -import OAuth2Actions, { AuthStore } from "./OAuth2Actions"; -import { OAuth2Client } from "@badgateway/oauth2-client"; -import { QueryClient } from "@tanstack/react-query"; -import { vitest, describe, beforeEach, expect, test } from "vitest"; - -describe("OAuth2Actions", () => { - let authStore: AuthStore; - let queryClient: QueryClient; - let oauthClient: OAuth2Client; - let fetchWrapper: FetchWrapper; - let toast: Notifier; - let oauth2Actions: OAuth2Actions; - - beforeEach(() => { - authStore = { - setState: vitest.fn(), - getState: vitest.fn(), - }; - queryClient = new QueryClient(); - oauthClient = new OAuth2Client({ - clientId: "test-client-id", - clientSecret: "test-client-secret", - authorizationEndpoint: "https://example.com/authorize", - tokenEndpoint: "https://example.com/token", - }); - fetchWrapper = { - fetch: vitest.fn(), - }; - toast = { - notify: vitest.fn(), - getContainer: vitest.fn(), - }; - oauth2Actions = new OAuth2Actions( - authStore, - queryClient, - oauthClient, - fetchWrapper, - toast - ); - }); - - describe("login", () => { - test("should set the codeVerifier, pkceState, and status in the authStore", async () => { - const codeVerifier = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - const pkceState = - "00000000000000000000000000000000000000000000000000000000"; - const authorizeUri = "https://example.com/authorize"; - - vitest - .spyOn(window.crypto, "getRandomValues") - .mockReturnValue( - new Uint32Array([ - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, - ]) - ); - - vitest - .spyOn(oauthClient.authorizationCode, "getAuthorizeUri") - .mockResolvedValueOnce(authorizeUri); - - await oauth2Actions.login(); - - expect(authStore.setState).toHaveBeenCalledWith({ - codeVerifier, - pkceState, - status: AuthStatus.PENDING, - }); - }); - }); - - describe("resolve", () => { - test("should set the status to logged out and clear the pkceState and codeVerifier in the authStore if the query string contains an error", async () => { - const query = { - error: "test-error", - error_description: "Test error description", - }; - - history.replaceState( - history.state, - "", - `?error=${query.error}&error_description=${query.error_description}` - ); - - await oauth2Actions.resolve(); - - expect(toast.notify).toHaveBeenCalledWith({ - title: "Error", - message: query.error_description, - status: "error", - }); - expect(authStore.setState).toHaveBeenCalledWith({ - status: AuthStatus.LOGGED_OUT, - pkceState: "", - codeVerifier: "", - }); - }); - - test("should attempt to exchange the authorization code for an access token if the query string contains a code", async () => { - const pkceState = "test_pkce_state"; - - // Redirect - history.replaceState( - history.state, - "", - `?code=test_oauth_code&state=${pkceState}` - ); - - vitest.spyOn(authStore, "getState").mockReturnValueOnce({ - codeVerifier: "JZWfp9wbBrl2hN0uKfZbkEbHgrZPR9p1gohoMoX90F0", - pkceState, - status: AuthStatus.PENDING, - token: null, - }); - - await oauth2Actions.resolve(); - - expect( - oauthClient.authorizationCode.getTokenFromCodeRedirect - ).toHaveBeenCalledWith(document.location.toString(), { - redirectUri: "https://example.com/redirect", - state: "", - codeVerifier: "", - }); - expect(window.history.replaceState).toHaveBeenCalledWith( - {}, - "", - location.pathname - ); - expect(authStore.setState).toHaveBeenCalledWith({ - token: oauth2Token, - status: AuthStatus.LOGGED_IN, - pkceState: "", - codeVerifier: "", - }); - }); - - test("should set the status to logged out and clear the pkceState and codeVerifier in the authStore if the query string does not contain a code and the status is pending", async () => { - vitest.spyOn(window.location, "search", "get").mockReturnValueOnce(""); - - authStore.getState.mockReturnValueOnce({ - status: AuthStatus.PENDING, - }); - - await oauth2Actions.resolve(); - - expect(authStore.setState).toHaveBeenCalledWith({ - status: AuthStatus.LOGGED_OUT, - pkceState: "", - codeVerifier: "", - }); - }); - }); - - describe("logout", () => { - test("should clear localstorage, reset the query cache, and set the status to logged out and clear the token in the authStore", async () => { - await oauth2Actions.logout(); - - expect(localStorage.clear).toHaveBeenCalled(); - expect(queryClient.clear).toHaveBeenCalled(); - expect(authStore.setState).toHaveBeenCalledWith({ - status: AuthStatus.LOGGED_OUT, - token: null, - }); - }); - }); - - describe("fetchAuthenticated", () => { - test("should call fetchWrapper.fetch with the correct URL and options", async () => { - const endpoint = "details/userinfo.json"; - const options = { - testOption: "test-value", - }; - const response = { - ok: true, - json: vitest.fn().mockResolvedValueOnce({}), - }; - - vitest.spyOn(fetchWrapper, "fetch").mockResolvedValueOnce(response); - - await oauth2Actions.fetchAuthenticated(endpoint, options); - - expect(fetchWrapper.fetch).toHaveBeenCalledWith( - "https://student.sbhs.net.au/api/details/userinfo.json?testOption=test-value" - ); - }); - - test("should throw a NetworkError if fetchWrapper.fetch throws a TypeError", async () => { - const endpoint = "details/userinfo.json"; - const options = { - testOption: "test-value", - }; - const error = new TypeError("Network error"); - - vitest.spyOn(fetchWrapper, "fetch").mockRejectedValueOnce(error); - - await expect( - oauth2Actions.fetchAuthenticated(endpoint, options) - ).rejects.toThrow(NetworkError); - expect(document.dispatchEvent).toHaveBeenCalledWith( - new CustomEvent("onlinechange", { detail: { online: false } }) - ); - }); - - test("should throw the error if fetchWrapper.fetch returns a non-ok response", async () => { - const endpoint = "details/userinfo.json"; - const options = { - testOption: "test-value", - }; - const response = { - ok: false, - status: 404, - }; - - vitest.spyOn(fetchWrapper, "fetch").mockResolvedValueOnce(response); - - await expect( - oauth2Actions.fetchAuthenticated(endpoint, options) - ).rejects.toThrow(HTTPError); - }); - - test("should return the JSON response if fetchWrapper.fetch returns an ok response", async () => { - const endpoint = "details/userinfo.json"; - const options = { - testOption: "test-value", - }; - const response = { - ok: true, - json: vitest.fn().mockResolvedValueOnce({}), - }; - - vitest.spyOn(fetchWrapper, "fetch").mockResolvedValueOnce(response); - - const result = await oauth2Actions.fetchAuthenticated(endpoint, options); - - expect(result).toEqual({}); - }); - }); -});