From 0db634afc32744b67ec9e109746968eccb64c003 Mon Sep 17 00:00:00 2001 From: Liz Wendling <170662489+GovCIOLiz@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:59:45 -0800 Subject: [PATCH] Wip --- src/schemas/22-10215/schema.js | 56 +++++++++--------- test/schemas/22-10215/schema.spec.js | 87 ++++++++++++++++++++++++++-- 2 files changed, 112 insertions(+), 31 deletions(-) diff --git a/src/schemas/22-10215/schema.js b/src/schemas/22-10215/schema.js index 1d938592..4a936011 100644 --- a/src/schemas/22-10215/schema.js +++ b/src/schemas/22-10215/schema.js @@ -1,8 +1,6 @@ import _ from 'lodash'; import definitions from '../../common/definitions'; - const origDefinitions = _.cloneDeep(definitions); - const pickedDefinitions = _.pick(origDefinitions, ['date']); const schema = { @@ -11,6 +9,7 @@ const schema = { type: 'object', additionalProperties: false, definitions: pickedDefinitions, + required: ['institutionDetails', 'programs'], properties: { institutionDetails: { type: 'object', @@ -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', + }, }, }, }, diff --git a/test/schemas/22-10215/schema.spec.js b/test/schemas/22-10215/schema.spec.js index e9ef9647..678e0260 100644 --- a/test/schemas/22-10215/schema.spec.js +++ b/test/schemas/22-10215/schema.spec.js @@ -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', }, @@ -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); });