From cc2a21b968d8dbda2ce294f205eafaaf38b13df1 Mon Sep 17 00:00:00 2001 From: Christopher Goh Date: Mon, 17 Aug 2020 00:26:21 +0800 Subject: [PATCH 1/4] Fix ECMAScript target in tsconfig --- scrapers/nus-v2/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scrapers/nus-v2/tsconfig.json b/scrapers/nus-v2/tsconfig.json index 68c3eca705..f89dfae554 100644 --- a/scrapers/nus-v2/tsconfig.json +++ b/scrapers/nus-v2/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { "outDir": "build", - "target": "es2020", + "target": "es2018", + "lib": ["es2020", "dom"], "module": "commonjs", "baseUrl": "./src", "resolveJsonModule": true, From deec1f6605b1ca0f654c63ffab1797475a784e8c Mon Sep 17 00:00:00 2001 From: Christopher Goh Date: Mon, 17 Aug 2020 00:27:20 +0800 Subject: [PATCH 2/4] Save e-learning venues as E-Learning --- scrapers/nus-v2/src/tasks/GetSemesterTimetable.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scrapers/nus-v2/src/tasks/GetSemesterTimetable.ts b/scrapers/nus-v2/src/tasks/GetSemesterTimetable.ts index 92d6526b7c..2d1cb019de 100644 --- a/scrapers/nus-v2/src/tasks/GetSemesterTimetable.ts +++ b/scrapers/nus-v2/src/tasks/GetSemesterTimetable.ts @@ -111,7 +111,20 @@ export function transformModgrpToClassNo(modgrp: string, activity: string): stri } export function mapTimetableLesson(lesson: TimetableLesson, logger: Logger): TempRawLesson { - const { room, start_time, end_time, day, module, modgrp, activity, eventdate, csize } = lesson; + const { + room: providedRoom, + start_time, + end_time, + day, + module, + modgrp, + activity, + eventdate, + csize, + } = lesson; + + // Save E-Learn_* venues as E-Learning + const room = providedRoom?.startsWith('E-Learn_') ? 'E-Learning' : providedRoom; if (has(unrecognizedLessonTypes, activity)) { logger.warn( From eb46b9e1024e758ebbec011befecae8d81c4f42a Mon Sep 17 00:00:00 2001 From: Christopher Goh Date: Mon, 17 Aug 2020 00:27:43 +0800 Subject: [PATCH 3/4] Add tests --- .../src/tasks/GetSemesterTimetable.test.ts | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/scrapers/nus-v2/src/tasks/GetSemesterTimetable.test.ts b/scrapers/nus-v2/src/tasks/GetSemesterTimetable.test.ts index f40ada61be..4b574c248a 100644 --- a/scrapers/nus-v2/src/tasks/GetSemesterTimetable.test.ts +++ b/scrapers/nus-v2/src/tasks/GetSemesterTimetable.test.ts @@ -1611,6 +1611,117 @@ Object { }, ], } +`); + }); + + // Lessons with E-Learn_* in venue should have E-Learning as venue + test('should save venue of lessons with E-Learning venues correctly', async () => { + const task = createTask( + CS4238Timetable.map((lesson) => { + return { ...lesson, room: 'E-Learn_C' }; + }), + ); + const timetable = await task.run(); + + expect(timetable.CS4238).toMatchInlineSnapshot(` +Array [ + Object { + "classNo": "1", + "day": "Monday", + "endTime": "2030", + "lessonType": "Lecture", + "size": 40, + "startTime": "1830", + "venue": "E-Learning", + "weeks": Array [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + ], + }, + Object { + "classNo": "2", + "day": "Tuesday", + "endTime": "2030", + "lessonType": "Lecture", + "size": 40, + "startTime": "1830", + "venue": "E-Learning", + "weeks": Array [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + ], + }, + Object { + "classNo": "2", + "day": "Tuesday", + "endTime": "2130", + "lessonType": "Laboratory", + "size": 40, + "startTime": "2030", + "venue": "E-Learning", + "weeks": Array [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + ], + }, + Object { + "classNo": "1", + "day": "Monday", + "endTime": "2130", + "lessonType": "Laboratory", + "size": 40, + "startTime": "2030", + "venue": "E-Learning", + "weeks": Array [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + ], + }, +] `); }); }); From b0514b1f61aec8781923821a0273ceca2e35872c Mon Sep 17 00:00:00 2001 From: Christopher Goh Date: Mon, 17 Aug 2020 00:31:25 +0800 Subject: [PATCH 4/4] Alphabetical order for tsconfig lib --- scrapers/nus-v2/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrapers/nus-v2/tsconfig.json b/scrapers/nus-v2/tsconfig.json index f89dfae554..495266a558 100644 --- a/scrapers/nus-v2/tsconfig.json +++ b/scrapers/nus-v2/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "outDir": "build", "target": "es2018", - "lib": ["es2020", "dom"], + "lib": ["dom", "es2020"], "module": "commonjs", "baseUrl": "./src", "resolveJsonModule": true,