diff --git a/tests/unit/services/schema-validator.service.spec.js b/tests/unit/services/schema-validator.service.spec.js index 6d902d49..4a61e3fd 100644 --- a/tests/unit/services/schema-validator.service.spec.js +++ b/tests/unit/services/schema-validator.service.spec.js @@ -5,48 +5,50 @@ const { const wqJsonSchema = require('../../../server/services/json-schemas/sirp_json_schema_WQ_v0.3.json') const wqSampleResponse = require('../../samples/sample_water_quality_incident.json') -describe('validateDataAgainstSchema function', () => { - it('should validate correctly against a valid schema', () => { - const schema = { - type: 'object', - properties: { - name: { type: 'string' }, - age: { type: 'number' } - }, - required: ['name', 'age'] - } - - const data = { - name: 'John', - age: 30 - } - - const results = validateDataAgainstSchema(data, schema) - - expect(results).toBe(true) - }) - - it('should return false and log errors for invalid data against schema', () => { - const schema = { - type: 'object', - properties: { - email: { type: 'string', format: 'email' } - }, - required: ['email'] - } - - const data = { - email: 'notAnEmail' - } - - const results = validateDataAgainstSchema(data, schema) - - expect(results).toBe(false) - }) - - it('should compile and validate sample against a given schema', () => { - const results = validateDataAgainstSchema(wqSampleResponse,wqJsonSchema) - - expect(results).toBe(true) +describe('SchemaValidatorService', () => { + describe('validateDataAgainstSchema', () => { + it('should validate correctly against a valid schema', () => { + const schema = { + type: 'object', + properties: { + name: { type: 'string' }, + age: { type: 'number' } + }, + required: ['name', 'age'] + } + + const data = { + name: 'John', + age: 30 + } + + const results = validateDataAgainstSchema(data, schema) + + expect(results).toBe(true) + }) + + it('should return false and log errors for invalid data against schema', () => { + const schema = { + type: 'object', + properties: { + email: { type: 'string', format: 'email' } + }, + required: ['email'] + } + + const data = { + email: 'notAnEmail' + } + + const results = validateDataAgainstSchema(data, schema) + + expect(results).toBe(false) + }) + + it('should compile and validate sample against a given schema', () => { + const results = validateDataAgainstSchema(wqSampleResponse, wqJsonSchema) + + expect(results).toBe(true) + }) }) })