Skip to content

Commit

Permalink
Schemas and unit tests for 22-10216 (#964)
Browse files Browse the repository at this point in the history
* Adding schema and unit tests for form 10216

* updated version

* updated schema

* added unit test

---------

Co-authored-by: wafimohamed <[email protected]>
  • Loading branch information
fatmakhan0395 and wafimohamed authored Dec 11, 2024
1 parent a810daf commit ceebb27
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
55 changes: 55 additions & 0 deletions dist/22-10216-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "22-10216 5% EXEMPTION REQUEST FROM 85/15 REPORTING REQUIREMENT GENERAL INFORMATION (22-10216)",
"type": "object",
"additionalProperties": false,
"definitions": {
"date": {
"pattern": "^(\\d{4}|XXXX)-(0[1-9]|1[0-2]|XX)-(0[1-9]|[1-2][0-9]|3[0-1]|XX)$",
"type": "string"
}
},
"properties": {
"institutionDetails": {
"type": "object",
"required": [
"institutionName",
"facilityCode",
"termStartDate"
],
"properties": {
"institutionName": {
"type": "string"
},
"facilityCode": {
"type": "string"
},
"termStartDate": {
"$ref": "#/definitions/date"
}
}
},
"studentRatioCalcChapter": {
"type": "object",
"required": [
"beneficiaryStudent",
"numOfStudent",
"dateOfCalculation"
],
"properties": {
"beneficiaryStudent": {
"type": "integer"
},
"numOfStudent": {
"type": "integer"
},
"VaBeneficiaryStudentsPercentage": {
"type": "number"
},
"dateOfCalculation": {
"$ref": "#/definitions/date"
}
}
}
}
}
50 changes: 50 additions & 0 deletions src/schemas/22-10216/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import _ from 'lodash';
import definitions from '../../common/definitions';

const origDefinitions = _.cloneDeep(definitions);

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

const schema = {
$schema: 'http://json-schema.org/draft-04/schema#',
title: '22-10216 5% EXEMPTION REQUEST FROM 85/15 REPORTING REQUIREMENT GENERAL INFORMATION (22-10216)',
type: 'object',
additionalProperties: false,
definitions: pickedDefinitions,
properties: {
institutionDetails: {
type: 'object',
required: ['institutionName', 'facilityCode', 'termStartDate'],
properties: {
institutionName: {
type: 'string',
},
facilityCode: {
type: 'string',
},
termStartDate: {
$ref: '#/definitions/date',
},
},
},
studentRatioCalcChapter: {
type: 'object',
required: ['beneficiaryStudent', 'numOfStudent', 'dateOfCalculation'],
properties: {
beneficiaryStudent: {
type: 'integer',
},
numOfStudent: {
type: 'integer',
},
VaBeneficiaryStudentsPercentage: {
type: 'number',
},
dateOfCalculation: {
$ref: '#/definitions/date',
},
},
},
},
};
export default schema;
65 changes: 65 additions & 0 deletions test/schemas/22-10216/schema.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { expect } from 'chai';
import { it } from 'mocha';
import { cloneDeep } from 'lodash';
import schema from '../../../src/schemas/22-10216/schema';
import SchemaTestHelper from '../../support/schema-test-helper';

const schemaWithoutRequired = cloneDeep(schema);

const schemaTestHelper = new SchemaTestHelper(schemaWithoutRequired);

const testData = {
institutionDetails: {
valid: [
{
institutionName: 'Test Institution',
facilityCode: '12345678',
termStartDate: '2024-01-01',
},
],
invalid: [
{
institutionName: 'Test Institution',
facilityCode: '12345f6g',
termStartDate: '2024-01-01',
},
],
},
studentRatioCalcChapter: {
valid: [
{
beneficiaryStudent: 1,
numOfStudent: 1,
dateOfCalculation: '2024-01-01',
},
],
invalid: [
{
beneficiaryStudent: '1r',
numOfStudent: '1r',
dateOfCalculation: '20230101',
},
{
institutionName: 'Institution of Test',
facilityCode: 'IoT 123',
termStartDate: 'start date',
},
],
},
};
describe('10216 schema', () => {
it('should have required fields', () => {
expect(schema.properties.institutionDetails.required).to.deep.equal([
'institutionName',
'facilityCode',
'termStartDate',
]);
expect(schema.properties.studentRatioCalcChapter.required).to.deep.equal([
'beneficiaryStudent',
'numOfStudent',
'dateOfCalculation',
]);
schemaTestHelper.testValidAndInvalid('institutionDetails', testData.institutionDetails);
schemaTestHelper.testValidAndInvalid('studentRatioCalcChapter', testData.studentRatioCalcChapter);
});
});

0 comments on commit ceebb27

Please sign in to comment.