Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Hours can have a "or" in them. #127

Merged
merged 5 commits into from
Jun 8, 2021
Merged
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
12 changes: 7 additions & 5 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ const expectSENG360 = (pid: string, courseDetails: KualiCourseItemParsed) => {
chosen: 'fixed',
});
expect(courseDetails.crossListedCourses).toBeUndefined();
expect(courseDetails.hoursCatalog).toStrictEqual({
lecture: '3',
lab: '2',
tutorial: '0',
});
expect(courseDetails.hoursCatalog).toStrictEqual([
{
lecture: '3',
lab: '2',
tutorial: '0',
},
]);
expect(courseDetails.__catalogCourseId).toEqual('SENG360');
expect(courseDetails.__passedCatalogQuery).toBeTruthy();
expect(courseDetails.dateStart).toEqual('2020-01-01');
Expand Down
31 changes: 31 additions & 0 deletions src/kuali/__tests__/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ describe('KualiCatalogItemParser', () => {
});
});

describe('hourscatalog test (multiple hours)', () => {
describe('PHIL207A', () => {
it('gets parsed correctly', () => {
const details = getCourseDetailByPidSync('202101', 'HkxKERd67E');

const response = KualiCourseItemParser(details);
expect(response.hoursCatalog).toStrictEqual([
{ lecture: '3', lab: '0', tutorial: '0' },
{ lecture: '2', lab: '1', tutorial: '0' },
]);
expect(response.credits.credits).toStrictEqual({ min: '1.5', max: '1.5' });
expect(response.credits.value).toEqual('1.5');
expect(response.credits.chosen).toEqual('fixed');
});
});
});

describe('hourscatalog test (single hour)', () => {
describe('AE103B', () => {
it('gets parsed correctly', () => {
const details = getCourseDetailByPidSync('202101', 'HJagTwaQN');

const response = KualiCourseItemParser(details);
expect(response.hoursCatalog).toStrictEqual([{ lecture: '3', lab: '0', tutorial: '0' }]);
expect(response.credits.credits).toStrictEqual({ min: '1.5', max: '1.5' });
expect(response.credits.value).toEqual('1.5');
expect(response.credits.chosen).toEqual('fixed');
});
});
});

describe('ASTR490 (when credits value are a range)', () => {
it('gets parsed correctly', () => {
const details = getCourseDetailByPidSync('202101', 'Sye6yAwTQV');
Expand Down
18 changes: 16 additions & 2 deletions src/kuali/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,30 @@ function parsePreCoReqs(preCoReqs: string): Array<NestedPreCoRequisites | Course
return reqs;
}

function hoursCatalog(hours: string[]) {
const eachHour: { lecture: string; lab: string; tutorial: string }[] = [];

//store the hours in a new array.
hours.forEach((element) => {
const temp = element.split('-');
eachHour.push({ lecture: temp[0], lab: temp[1], tutorial: temp[2] });
});

return eachHour;
}

export function KualiCourseItemParser(course: KualiCourseItem): KualiCourseItemParsed {
// strip HTML tags from courseDetails.description
course.description = course.description.replace(/(<([^>]+)>)/gi, '');

const { hoursCatalogText, preAndCorequisites, preOrCorequisites } = course;
const hours = hoursCatalogText?.split('-');

//split the hours if we have more than one.
const hours = hoursCatalogText?.split(' or ');

return {
...course,
hoursCatalog: hours ? { lecture: hours[0], lab: hours[1], tutorial: hours[2] } : undefined,
hoursCatalog: hours ? hoursCatalog(hours) : undefined,
preAndCorequisites: preAndCorequisites ? parsePreCoReqs(preAndCorequisites) : undefined,
preOrCorequisites: preOrCorequisites ? parsePreCoReqs(preOrCorequisites) : undefined,
};
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type KualiCourseItemParsed = Omit<
lecture: string;
tutorial: string;
lab: string;
};
}[];
preAndCorequisites?: Array<NestedPreCoRequisites | Course | string>;
preOrCorequisites?: Array<NestedPreCoRequisites | Course | string>;
};
Expand Down