Skip to content

Commit

Permalink
add new fields and allowlist to course.yaml validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dmca-glasgow committed Apr 21, 2022
1 parent c93e5a4 commit 1583198
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 17 additions & 1 deletion compiler/src/course/load-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ import * as yup from 'yup';
import { readFile } from '../utils/utils';
import { CourseYaml } from './types';

export const validCatalogValues = [
'STATS5077',
'STATS5078',
'STATS5075',
'STATS5084',
'STATS5074',
'STATS5081',
'STATS5080',
'STATS5073',
'STATS5076',
'STATS5079',
'STATS5082',
'STATS5094',
'STATS5083',
];

const courseSchema = yup.object().shape({
title: yup.string().required(),
units: yup.array().of(
yup.object().shape({
src: yup.string().required(),
})
),
catalog: yup.string().required(),
catalog: yup.string().oneOf(validCatalogValues).required(),
authors: yup.string().required(),
academic_year: yup.string().required(),
});
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/course/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { VFile } from 'vfile';

export type CourseYaml = {
title: string;
catalog: string;
authors: string;
academic_year: string;
units: FileRef[];
};

Expand All @@ -22,6 +25,9 @@ export type Unit = {

export type Course = {
title: string;
catalog: string;
authors: string;
academic_year: string;
coursePath: string;
units: Unit[];
};
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/test-utils/test-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ async function createTestContext(md: string, options: Options = {}) {

const course = {
title: 'Test Course',
catalog: 'STATS5078',
authors: 'David McArthur',
academic_year: '2021-22',
coursePath: cacheDir,
units: [{ src: unitPath }],
};
Expand Down

0 comments on commit 1583198

Please sign in to comment.