Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GovCIOLiz committed Dec 11, 2024
1 parent 5b6db1b commit 0db634a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 31 deletions.
56 changes: 29 additions & 27 deletions src/schemas/22-10215/schema.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import _ from 'lodash';
import definitions from '../../common/definitions';

const origDefinitions = _.cloneDeep(definitions);

const pickedDefinitions = _.pick(origDefinitions, ['date']);

const schema = {
Expand All @@ -11,6 +9,7 @@ const schema = {
type: 'object',
additionalProperties: false,
definitions: pickedDefinitions,
required: ['institutionDetails', 'programs'],
properties: {
institutionDetails: {
type: 'object',
Expand All @@ -32,31 +31,34 @@ const schema = {
},
programs: {
type: 'array',
required: ['programName', 'studentsEnrolled', 'supportedStudents'],
properties: {
programName: {
type: 'string',
},
studentsEnrolled: {
type: 'integer',
},
supportedStudents: {
type: 'integer',
},
fte: {
type: 'object',
properties: {
supported: {
type: 'integer',
},
nonSupported: {
type: 'integer',
},
totalFTE: {
type: 'integer',
},
supportedPercentageFTE: {
type: 'number',
items: {
type: 'object',
required: ['programName', 'studentsEnrolled', 'supportedStudents'],
properties: {
programName: {
type: 'string',
},
studentsEnrolled: {
type: 'integer',
},
supportedStudents: {
type: 'integer',
},
fte: {
type: 'object',
properties: {
supported: {
type: 'integer',
},
nonSupported: {
type: 'integer',
},
totalFTE: {
type: 'integer',
},
supportedPercentageFTE: {
type: 'number',
},
},
},
},
Expand Down
87 changes: 83 additions & 4 deletions test/schemas/22-10215/schema.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { expect } from 'chai';
import { it } from 'mocha';
import { cloneDeep } from 'lodash';
import { cloneDeep, omit } from 'lodash';
import schema from '../../../src/schemas/22-10215/schema';
import SchemaTestHelper from '../../support/schema-test-helper';

const schemaClone = cloneDeep(schema);

const schemaTestHelper = new SchemaTestHelper(schemaClone);
const schemaTestHelper = new SchemaTestHelper(omit(schemaClone, 'required'));

const testData = {
institutionDetails: {
valid: [
{
institutionName: 'Institution of Test',
facilityCode: 'IoT 123',
facilityCode: '12345678',
termStartDate: '2024-11-25',
dateOfCalculations: '2024-11-28',
},
{
institutionName: 'Institution of Test',
facilityCode: '23456789',
termStartDate: '2024-11-25',
dateOfCalculations: '2024-11-28',
},
Expand Down Expand Up @@ -45,17 +50,91 @@ const testData = {
},
],
},
programs: {
valid: [
[{
programName: 'Computer Science',
studentsEnrolled: 100,
supportedStudents: 80,
fte: {
supported: 20,
nonSupported: 10,
totalFTE: 30,
supportedPercentageFTE: 66.67,
},
}],
[{
programName: 'Computer Science',
studentsEnrolled: 10,
supportedStudents: 8,
}],
],
invalid: [
[{
programName: null,
studentsEnrolled: 100,
supportedStudents: 80,
fte: {
supported: 9.5,
nonSupported: 7,
totalFTE: 80,
supportedPercentageFTE: 62.5,
},
}],
[{
programName: 'Computer Science',
studentsEnrolled: '100',
supportedStudents: 80,
fte: {
supported: 9,
nonSupported: 7,
},
}],
[{
programName: 'Computer Science',
studentsEnrolled: null,
supportedStudents: 80,
fte: {
supported: 50,
nonSupported: 30,
totalFTE: 80,
supportedPercentageFTE: 62.5,
},
}],
[{
programName: 'Computer Science',
studentsEnrolled: 100,
supportedStudents: undefined,
fte: {
supported: 50,
nonSupported: 30,
totalFTE: 80,
supportedPercentageFTE: 62.5,
},
}],
],
},
};

describe('22-10215 Schema', () => {
it('should have required fields', () => {
expect(schema.required).to.deep.equal([
'institutionDetails',
'programs',
]);
expect(schema.properties.institutionDetails.required).to.deep.equal([
'institutionName',
'facilityCode',
'termStartDate',
'dateOfCalculations',
]);
expect(schema.properties.programs.items.required).to.deep.equal([
'programName',
'studentsEnrolled',
'supportedStudents'
]);
});

schemaTestHelper.testValidAndInvalid('institutionDetails', testData.institutionDetails);
schemaTestHelper.testValidAndInvalid('programs', testData.programs);
});

0 comments on commit 0db634a

Please sign in to comment.