diff --git a/test/ajv-schemes.js b/test/ajv-schemes.js index 6b7167c3..8b2d79ad 100644 --- a/test/ajv-schemes.js +++ b/test/ajv-schemes.js @@ -137,5 +137,8 @@ function schemesV3_0_0(ajv) { ajv.addSchema(require('@common/avroSchema_v1.json')); ajv.addSchema(require('@common/openapiSchema_3_0.json')); + ajv.addSchema(require('@extensions/x/0.1.0/schema.json')); + ajv.addSchema(require('@extensions/linkedin/0.1.0/schema.json')); + return bindingSchemes(ajv); } diff --git a/test/definitions/3.0.0/models/channel/channel/channel.js b/test/definitions/3.0.0/models/channel/channel/channel.js index fe9aacec..71d7e053 100644 --- a/test/definitions/3.0.0/models/channel/channel/channel.js +++ b/test/definitions/3.0.0/models/channel/channel/channel.js @@ -1,64 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Channel'; -const jsonSchema = require('@definitions/3.0.0/channel.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Channel' +const validator = TestHelper.validator(require('@definitions/3.0.0/channel.json')) -describe.skip(`${jsonSchemaName}. Reason: multiple errors with bindings, externalDoc, ...`, () => { +describe.skip(`${title}. Reason: multiple errors with bindings, externalDoc, ...`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it('extended', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it('wrongly extended', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/channel/message/correlationId/correlationId.js b/test/definitions/3.0.0/models/channel/message/correlationId/correlationId.js index c2c73224..23afb34f 100644 --- a/test/definitions/3.0.0/models/channel/message/correlationId/correlationId.js +++ b/test/definitions/3.0.0/models/channel/message/correlationId/correlationId.js @@ -1,36 +1,23 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Correlation ID'; -const jsonSchema = require('@definitions/3.0.0/correlationId.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Correlation ID' +const validator = TestHelper.validator(require('@definitions/3.0.0/correlationId.json')) -describe(`${jsonSchemaName}`, () => { +describe(`${title}`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === false, `${title} with empty body is valid`); assert(validator.errors[0].message === 'must have required property \'location\''); assert(validator.errors.length === 1); }); @@ -39,7 +26,7 @@ describe(`${jsonSchemaName}`, () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === false, `${title} without required properties is valid`); assert(validator.errors[0].message === 'must have required property \'location\''); assert(validator.errors.length === 1); }); @@ -48,21 +35,21 @@ describe(`${jsonSchemaName}`, () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it('extended', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it('wrongly extended', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/channel/message/message/message.js b/test/definitions/3.0.0/models/channel/message/message/message.js index ce1ccbf0..4f6e5983 100644 --- a/test/definitions/3.0.0/models/channel/message/message/message.js +++ b/test/definitions/3.0.0/models/channel/message/message/message.js @@ -1,64 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Message'; -const jsonSchema = require('@definitions/3.0.0/messageObject.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Message' +const validator = TestHelper.validator(require('@definitions/3.0.0/messageObject.json')); -describe.skip(`${jsonSchemaName}. Issues with bindings`, () => { +describe.skip(`${title}. Issues with bindings`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema prohibites extendsion. Check', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema prohibites extendsion. Check', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/channel/message/messageExample/messageExample.js b/test/definitions/3.0.0/models/channel/message/messageExample/messageExample.js index 027c35d5..685a587a 100644 --- a/test/definitions/3.0.0/models/channel/message/messageExample/messageExample.js +++ b/test/definitions/3.0.0/models/channel/message/messageExample/messageExample.js @@ -1,36 +1,23 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Message example'; -const jsonSchema = require('@definitions/3.0.0/messageExampleObject.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Message example' +const validator = TestHelper.validator(require('@definitions/3.0.0/messageExampleObject.json')); -describe(`${jsonSchemaName}`, () => { +describe(`${title}`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === false, `${title} with empty body is valid`); assert(validator.errors[0].message === 'must have required property \'payload\''); assert(validator.errors[1].message === 'must have required property \'headers\''); assert(validator.errors[2].message === 'must match a schema in anyOf'); @@ -41,7 +28,7 @@ describe(`${jsonSchemaName}`, () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === false, `${title} without required properties is valid`); assert(validator.errors[0].message === 'must have required property \'payload\''); assert(validator.errors[1].message === 'must have required property \'headers\''); assert(validator.errors[2].message === 'must match a schema in anyOf'); @@ -52,21 +39,21 @@ describe(`${jsonSchemaName}`, () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema prohibites extendsion. Check', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema prohibites extendsion. Check', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/channel/message/messageTrait/messageTrait.js b/test/definitions/3.0.0/models/channel/message/messageTrait/messageTrait.js index f4e09e45..6643a4e0 100644 --- a/test/definitions/3.0.0/models/channel/message/messageTrait/messageTrait.js +++ b/test/definitions/3.0.0/models/channel/message/messageTrait/messageTrait.js @@ -1,64 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Message trait'; -const jsonSchema = require('@definitions/3.0.0/messageTrait.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Message trait' +const validator = TestHelper.validator(require('@definitions/3.0.0/messageTrait.json')); -describe.skip(`${jsonSchemaName}. Issues with bindings`, () => { +describe.skip(`${title}. Issues with bindings`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema prohibites extendsion. Check', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema prohibites extendsion. Check', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/channel/parameter/parameter.js b/test/definitions/3.0.0/models/channel/parameter/parameter.js index ccafba8d..93581587 100644 --- a/test/definitions/3.0.0/models/channel/parameter/parameter.js +++ b/test/definitions/3.0.0/models/channel/parameter/parameter.js @@ -1,66 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Parameter'; -const jsonSchema = require('@definitions/3.0.0/parameter.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@definitions/3.0.0/specificationExtension.json')) - .compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Parameter' +const validator = TestHelper.validator(require('@definitions/3.0.0/parameter.json')); -describe(`${jsonSchemaName}`, () => { +describe(`${title}`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it('extended', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it('wrongly extended', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/info/contact/contact.js b/test/definitions/3.0.0/models/info/contact/contact.js index bd100689..f717a76e 100644 --- a/test/definitions/3.0.0/models/info/contact/contact.js +++ b/test/definitions/3.0.0/models/info/contact/contact.js @@ -1,31 +1,16 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Contact'; -const jsonSchema = require('@definitions/3.0.0/contact.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@definitions/3.0.0/specificationExtension.json')) - .compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Contact' +const validator = TestHelper.validator(require('@definitions/3.0.0/contact.json')); describe('Contact', () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { diff --git a/test/definitions/3.0.0/models/info/info extensions/info-extension.js b/test/definitions/3.0.0/models/info/info extensions/info-extension.js index 66776db3..3552716a 100644 --- a/test/definitions/3.0.0/models/info/info extensions/info-extension.js +++ b/test/definitions/3.0.0/models/info/info extensions/info-extension.js @@ -1,32 +1,16 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Info Extensions'; -const jsonSchema = require('@definitions/3.0.0/infoExtensions.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@extensions/linkedin/0.1.0/schema.json')) - .addSchema(require('@extensions/x/0.1.0/schema.json')) - .compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Info Extensions'; +const validator = TestHelper.validator(require('@definitions/3.0.0/infoExtensions.json')); describe('InfoExtensions', () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { diff --git a/test/definitions/3.0.0/models/info/info/info.js b/test/definitions/3.0.0/models/info/info/info.js index 1c759419..284e0634 100644 --- a/test/definitions/3.0.0/models/info/info/info.js +++ b/test/definitions/3.0.0/models/info/info/info.js @@ -1,41 +1,16 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Info'; -const jsonSchema = require('@definitions/3.0.0/info.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@definitions/3.0.0/infoExtensions.json')) - .addSchema(require('@definitions/3.0.0/contact.json')) - .addSchema(require('@definitions/3.0.0/license.json')) - .addSchema(require('../../../../../../examples/3.0.0/ReferenceObject.json')) - .addSchema(require('@definitions/3.0.0/ReferenceObject.json')) - .addSchema(require('@definitions/3.0.0/Reference.json')) - .addSchema(require('@definitions/3.0.0/tag.json')) - .addSchema(require('@definitions/3.0.0/externalDocs.json')) - .addSchema(require('@definitions/3.0.0/specificationExtension.json')) - .addSchema(require('@extensions/linkedin/0.1.0/schema.json')) - .addSchema(require('@extensions/x/0.1.0/schema.json')) - .compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Info' +const validator = TestHelper.validator(require('@definitions/3.0.0/info.json')); describe('Info', () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { diff --git a/test/definitions/3.0.0/models/info/license/license.js b/test/definitions/3.0.0/models/info/license/license.js index 85739cea..6a34da67 100644 --- a/test/definitions/3.0.0/models/info/license/license.js +++ b/test/definitions/3.0.0/models/info/license/license.js @@ -1,31 +1,16 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'License'; -const infoJsonSchema = require('@definitions/3.0.0/license.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@definitions/3.0.0/specificationExtension.json')) - .compile(infoJsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'License'; +const validator = TestHelper.validator(require('@definitions/3.0.0/license.json')); describe('License', () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { diff --git a/test/definitions/3.0.0/models/operation/operation/operation.js b/test/definitions/3.0.0/models/operation/operation/operation.js index df4e0613..49090b52 100644 --- a/test/definitions/3.0.0/models/operation/operation/operation.js +++ b/test/definitions/3.0.0/models/operation/operation/operation.js @@ -1,64 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Operation'; -const jsonSchema = require('@definitions/3.0.0/operation.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Operation'; +const validator = TestHelper.validator(require('@definitions/3.0.0/operation.json')); -describe.skip(`${jsonSchemaName}. Reason: errors with bindings, external docs, ...`, () => { +describe.skip(`${title}. Reason: errors with bindings, external docs, ...`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/operation/operationReply/operationReply.js b/test/definitions/3.0.0/models/operation/operationReply/operationReply.js index 48643584..07477d4e 100644 --- a/test/definitions/3.0.0/models/operation/operationReply/operationReply.js +++ b/test/definitions/3.0.0/models/operation/operationReply/operationReply.js @@ -1,64 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Operation Reply'; -const jsonSchema = require('@definitions/3.0.0/operationReplyAddress.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Operation Reply'; +const validator = TestHelper.validator(require('@definitions/3.0.0/operationReply.json')); -describe.skip(`${jsonSchemaName}. uri-reference not compatible with #/components/...`, () => { +describe.skip(`${title}. uri-reference not compatible with #/components/...`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it('extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it('wrongly extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/operation/operationReplyAddress/operationReplyAddress.js b/test/definitions/3.0.0/models/operation/operationReplyAddress/operationReplyAddress.js index f026c46c..269a6f3b 100644 --- a/test/definitions/3.0.0/models/operation/operationReplyAddress/operationReplyAddress.js +++ b/test/definitions/3.0.0/models/operation/operationReplyAddress/operationReplyAddress.js @@ -1,36 +1,23 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Operation Reply Address'; -const jsonSchema = require('@definitions/3.0.0/operationReplyAddress.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Operation Reply Address'; +const validator = TestHelper.validator(require('@definitions/3.0.0/operationReplyAddress.json')); -describe(`${jsonSchemaName}`, () => { +describe(`${title}`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} with empty body is not valid`); + assert(validationResult === false, `${title} with empty body is not valid`); assert(validator.errors[0].message === 'must have required property \'location\''); assert(validator.errors.length === 1); }); @@ -39,7 +26,7 @@ describe(`${jsonSchemaName}`, () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === false, `${title} without required properties is valid`); assert(validator.errors[0].message === 'must have required property \'location\''); assert(validator.errors.length === 1); }); @@ -48,21 +35,21 @@ describe(`${jsonSchemaName}`, () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it('extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it('wrongly extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/operation/operationTrait/operationTrait.js b/test/definitions/3.0.0/models/operation/operationTrait/operationTrait.js index 354481db..fee12beb 100644 --- a/test/definitions/3.0.0/models/operation/operationTrait/operationTrait.js +++ b/test/definitions/3.0.0/models/operation/operationTrait/operationTrait.js @@ -1,64 +1,51 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Operation Trait'; -const jsonSchema = require('@definitions/3.0.0/operationTrait.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Operation Trait'; +const validator = TestHelper.validator(require('@definitions/3.0.0/operationTrait.json')); -describe.skip(`${jsonSchemaName} Reason: errors with bindings, external docs, ...`, () => { +describe.skip(`${title} Reason: errors with bindings, external docs, ...`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/wrongly extended.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/reference object/index.js b/test/definitions/3.0.0/models/reference object/index.js index 9a638241..fa35ed6f 100644 --- a/test/definitions/3.0.0/models/reference object/index.js +++ b/test/definitions/3.0.0/models/reference object/index.js @@ -1,25 +1,11 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const infoJsonSchema = require('@definitions/3.0.0/Reference.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addMetaSchema(require('@definitions/3.0.0/ReferenceObject.json')) - .compile(infoJsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Reference Object'; +const validator = TestHelper.validator(require('@definitions/3.0.0/Reference.json')); -describe('ReferenceObject', () => { +describe(`${title}`, () => { it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); diff --git a/test/definitions/3.0.0/models/reference/index.js b/test/definitions/3.0.0/models/reference/index.js index 6e30d430..b993d1aa 100644 --- a/test/definitions/3.0.0/models/reference/index.js +++ b/test/definitions/3.0.0/models/reference/index.js @@ -1,32 +1,16 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); -const path = require('path'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Reference'; -const infoJsonSchema = require('@definitions/3.0.0/Reference.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@definitions/3.0.0/ReferenceObject.json')) - .compile(infoJsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Reference'; +const validator = TestHelper.validator(require('@definitions/3.0.0/Reference.json')); describe('Reference', () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { diff --git a/test/definitions/3.0.0/models/server/server/index.js b/test/definitions/3.0.0/models/server/server/index.js index 94b5645e..e76fd0be 100644 --- a/test/definitions/3.0.0/models/server/server/index.js +++ b/test/definitions/3.0.0/models/server/server/index.js @@ -1,51 +1,37 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); -const path = require('path'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Server'; -const jsonSchema = require('@definitions/3.0.0/server.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Server'; +const validator = TestHelper.validator(require('@definitions/3.0.0/server.json')); -describe.skip(`${jsonSchemaName}. Reason: errors with bindings, external docs, ...`, () => { +describe.skip(`${title}. Reason: errors with bindings, external docs, ...`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema doesn\'t check for extensions', () => { @@ -53,7 +39,7 @@ describe.skip(`${jsonSchemaName}. Reason: errors with bindings, external docs, . const model = JSON.parse(fs.readFileSync(filePath, 'utf-8')); const validationResult = validator(model); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => { @@ -61,7 +47,7 @@ describe.skip(`${jsonSchemaName}. Reason: errors with bindings, external docs, . const model = JSON.parse(fs.readFileSync(filePath, 'utf-8')); const validationResult = validator(model); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/server/serverVariable/index.js b/test/definitions/3.0.0/models/server/serverVariable/index.js index e4f661c7..99c9389c 100644 --- a/test/definitions/3.0.0/models/server/serverVariable/index.js +++ b/test/definitions/3.0.0/models/server/serverVariable/index.js @@ -1,51 +1,37 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); -const path = require('path'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Server Variable'; -const jsonSchema = require('@definitions/3.0.0/serverVariable.json'); -import schemesV3_0_0 from '@test/ajv-schemes'; -const validator = schemesV3_0_0(ajv).compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Server Variable'; +const validator = TestHelper.validator(require('@definitions/3.0.0/serverVariable.json')); -describe(`${jsonSchemaName}`, () => { +describe(`${title}`, () => { it('example', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/empty.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} with empty body is valid`); + assert(validationResult === true, `${title} with empty body is valid`); }); it('without required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/without required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} without required properties is valid`); + assert(validationResult === true, `${title} without required properties is valid`); }); it('only required properties', () => { const info = JSON.parse(fs.readFileSync(`${__dirname}/only required properties.json`, 'utf-8')); const validationResult = validator(info); - assert(validationResult === true, `${jsonSchemaName} is valid with only required properties`); + assert(validationResult === true, `${title} is valid with only required properties`); }); it.skip('extended. Reason: schema doesn\'t check for extensions', () => { @@ -53,7 +39,7 @@ describe(`${jsonSchemaName}`, () => { const model = JSON.parse(fs.readFileSync(filePath, 'utf-8')); const validationResult = validator(model); - assert(validationResult === true, `${jsonSchemaName} can be extended`); + assert(validationResult === true, `${title} can be extended`); }); it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => { @@ -61,7 +47,7 @@ describe(`${jsonSchemaName}`, () => { const model = JSON.parse(fs.readFileSync(filePath, 'utf-8')); const validationResult = validator(model); - assert(validationResult === false, `${jsonSchemaName} is not valid when was wrongly extended`); + assert(validationResult === false, `${title} is not valid when was wrongly extended`); assert(validator.errors[0].message === 'must NOT have additional properties'); assert(validator.errors[0].params.additionalProperty === 'ext-number'); assert(validator.errors.length === 1); diff --git a/test/definitions/3.0.0/models/tag/index.js b/test/definitions/3.0.0/models/tag/index.js index 78f0caef..a4628ea4 100644 --- a/test/definitions/3.0.0/models/tag/index.js +++ b/test/definitions/3.0.0/models/tag/index.js @@ -1,35 +1,16 @@ -const Ajv = require('ajv'); -const assert = require('assert'); -const addFormats = require('ajv-formats'); -const fs = require('fs'); -const path = require('path'); - -const ajv = new Ajv({ - jsonPointers: true, - allErrors: true, - schemaId: '$id', - logger: false, - validateFormats: true, - strict: false, -}); -addFormats(ajv); +import TestHelper from '@test/test-helper'; -const jsonSchemaName = 'Tag'; -const jsonSchema = require('@definitions/3.0.0/tag.json'); -const validator = ajv - .addMetaSchema(require('@definitions/3.0.0/schema.json')) - .addSchema(require('@definitions/3.0.0/Reference.json')) - .addSchema(require('@definitions/3.0.0/ReferenceObject.json')) - .addSchema(require('@definitions/3.0.0/externalDocs.json')) - .addSchema(require('@definitions/3.0.0/specificationExtension.json')) - .compile(jsonSchema); +const fs = require('fs'); +const assert = require('assert'); +const title = 'Tag'; +const validator = TestHelper.validator(require('@definitions/3.0.0/tag.json')); -describe(`${jsonSchemaName}`, () => { +describe(`${title}`, () => { it('example', () => { const model = JSON.parse(fs.readFileSync(`${__dirname}/example.json`, 'utf-8')); const validationResult = validator(model); - assert(validationResult === true, `${jsonSchemaName} example MUST be valid`); + assert(validationResult === true, `${title} example MUST be valid`); }); it('empty', () => {