Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"lint": "eslint .",
"format": "prettier --write .",
"format:check": "prettier --check .",
"scrape:courses": "node scripts/scrape-courses.bin.ts"
"scrape:courses": "node scripts/scrape-courses.bin.ts",
"scrape:programs": "node scripts/scrape-programs.ts"
},
"dependencies": {
"@dagrejs/dagre": "^3.0.0",
Expand Down
914 changes: 914 additions & 0 deletions scripts/fixtures/computerscience_programs.html

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions scripts/scrape-programs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import fs from 'fs';
import * as cheerio from 'cheerio';
import { describe, expect, it } from 'vitest';

import { parseProgramRequirementsPage } from './scrape-programs';

const fixtureHtml = cheerio.load(
fs.readFileSync('scripts/fixtures/computerscience_programs.html', 'utf-8'),
);

describe('Computer Science Program Parser', () => {
// 1. Parse the local fixture
const manifest = parseProgramRequirementsPage(fixtureHtml);

it('should extract at least one program from the document', () => {
const programKeys = Object.keys(manifest);
expect(programKeys.length).toBeGreaterThan(0);
});

it('should parse the core BCS Honours program with standard required courses', () => {
// Find either the exact key or a match for BCS Honours
const bcsHonoursKey = Object.keys(manifest).find(
(key) => key.includes('bcs-honours') && !key.includes('stream')
) || Object.keys(manifest)[0];

const bcsHonours = manifest[bcsHonoursKey];
expect(bcsHonours).toBeDefined();

// Verify core foundational courses are correctly identified as required
expect(bcsHonours.requiredCourses).toContain('COMP 1405');
expect(bcsHonours.requiredCourses).toContain('COMP 1406');
expect(bcsHonours.requiredCourses).toContain('COMP 2401');
expect(bcsHonours.requiredCourses).toContain('COMP 3804');
});

it('should correctly parse streams with choice groups like game dev stream', () => {
// Find the Game Development stream program in the parsed manifest
const gameDevKey = Object.keys(manifest).find(
(key) => key.toLowerCase().includes('game')
);

// If the fixture does not contain the game dev stream, fallback to any stream program
const targetKey = gameDevKey || Object.keys(manifest).find((key) => key.includes('stream'));

if (!targetKey) {
// If there are no streams at all in this fixture, skip. This means the test will hopefully still pass when testing other programs
return;
}

const streamProgram = manifest[targetKey];
expect(streamProgram).toBeDefined();

// Streams must still inherit foundational core courses
expect(streamProgram.requiredCourses).toContain('COMP 1405');

// Verify the parser successfully extracted choice structures (e.g. "COMP 4905 and ... or COMP 4906")
expect(streamProgram.chooseGroups).toBeDefined();
expect(streamProgram.chooseGroups.length).toBeGreaterThan(0);

// Validate a specific choice layout structure (e.g., choose groups must specify credits and options)
const representativeGroup = streamProgram.chooseGroups[0];
expect(representativeGroup).toHaveProperty('credits');
expect(representativeGroup).toHaveProperty('courses');
expect(Array.isArray(representativeGroup.courses)).toBe(true);
expect(representativeGroup.courses.length).toBeGreaterThan(0);
});

it('should isolate electives from required core/choice blocks', () => {
// Look for any program with electives defined
const programWithElectives = Object.values(manifest).find(
(prog) => prog.electives && prog.electives.length > 0
);

if (programWithElectives) {
const freeElective = programWithElectives.electives.find(
(el) => el.category.toLowerCase().includes('free')
);

if (freeElective) {
expect(freeElective.credits).toBeGreaterThan(0);
}
}
});
});
Loading
Loading