diff --git a/test/definitions/3.0.0/models/index.mjs b/test/definitions/3.0.0/models/index.mjs index 323d0932..add80ec4 100644 --- a/test/definitions/3.0.0/models/index.mjs +++ b/test/definitions/3.0.0/models/index.mjs @@ -2,7 +2,6 @@ import {describe} from 'vitest'; describe('Models Test Suite', async () => { await import('./channel'); - await import('./info'); await import('./operation'); await import('./reference'); await import('./server'); diff --git a/test/definitions/3.0.0/models/info/contact.test.mjs b/test/definitions/3.0.0/models/info/contact.test.mjs new file mode 100644 index 00000000..c57244a9 --- /dev/null +++ b/test/definitions/3.0.0/models/info/contact.test.mjs @@ -0,0 +1,61 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const example = { + "name": "AsyncApi", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com" +} + +const onlyRequiredProperties = {} + +const withoutRequiredProperties = {} + +const extended = { + "name": "AsyncAPI", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } +} + +const wronglyExtended = { + "name": "AsyncAPI", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com", + "x-number": 0, + "x-string": "", + "x-object": { + "property" : { } + }, + "ext-number": 1 +} + +const jsonSchema = require('@definitions/3.0.0/contact.json'); + +const config = new JsonSchemaTestSuiteConfig( + false, + [], + true, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [example], + onlyRequiredProperties, + withoutRequiredProperties, + extended, + wronglyExtended +); + +describe('Contact', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); \ No newline at end of file diff --git a/test/definitions/3.0.0/models/info/contact/empty.json b/test/definitions/3.0.0/models/info/contact/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/contact/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/contact/example.json b/test/definitions/3.0.0/models/info/contact/example.json deleted file mode 100644 index 31cd246a..00000000 --- a/test/definitions/3.0.0/models/info/contact/example.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "AsyncApi", - "url": "https://www.asyncapi.com", - "email": "java@asyncapi.com" -} diff --git a/test/definitions/3.0.0/models/info/contact/extended.json b/test/definitions/3.0.0/models/info/contact/extended.json deleted file mode 100644 index fbc417ba..00000000 --- a/test/definitions/3.0.0/models/info/contact/extended.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name" : "AsyncAPI", - "url" : "https://www.asyncapi.com", - "email" : "java@asyncapi.com", - "x-number" : 0, - "x-string" : "", - "x-object" : { - "property" : { } - } -} diff --git a/test/definitions/3.0.0/models/info/contact/index.mjs b/test/definitions/3.0.0/models/info/contact/index.mjs deleted file mode 100644 index f181a7c3..00000000 --- a/test/definitions/3.0.0/models/info/contact/index.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/contact.json'); - -describe('Contact', () => { - it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it(TestHelper.canBeEmptyTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - )); - - it(TestHelper.isValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - )); - - it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json'), - )); - - it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './extended.json'), - )); - - it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, './wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/info/contact/only required properties.json b/test/definitions/3.0.0/models/info/contact/only required properties.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/contact/only required properties.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/contact/without required properties.json b/test/definitions/3.0.0/models/info/contact/without required properties.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/contact/without required properties.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/contact/wrongly extended.json b/test/definitions/3.0.0/models/info/contact/wrongly extended.json deleted file mode 100644 index fe3dcbfc..00000000 --- a/test/definitions/3.0.0/models/info/contact/wrongly extended.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name" : "AsyncAPI", - "url" : "https://www.asyncapi.com", - "email" : "java@asyncapi.com", - "x-number" : 0, - "x-string" : "", - "x-object" : { - "property" : { } - }, - "ext-number": 1 -} diff --git a/test/definitions/3.0.0/models/info/index.mjs b/test/definitions/3.0.0/models/info/index.mjs deleted file mode 100644 index d7c0a2ab..00000000 --- a/test/definitions/3.0.0/models/info/index.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import {describe} from 'vitest'; - -describe('Info Test Suite', async () => { - await import('./info'); - await import('./info extensions'); - await import('./contact'); - await import('./license'); -}); diff --git a/test/definitions/3.0.0/models/info/info extensions.test.mjs b/test/definitions/3.0.0/models/info/info extensions.test.mjs new file mode 100644 index 00000000..8e47cbb7 --- /dev/null +++ b/test/definitions/3.0.0/models/info/info extensions.test.mjs @@ -0,0 +1,58 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const example = { + "x-x": "PBodiachevskii", + "x-linkedin": "https://www.linkedin.com/company/asyncapi/" +} + +const onlyRequiredProperties = {} + +const withoutRequiredProperties = {} + +const extended = { + "x-number" : 0, + "x-string" : "", + "x-object" : { + "property" : { } + }, + "x-x": "PBodiachevskii", + "x-linkedin": "https://www.linkedin.com/company/asyncapi/" +} + +const wronglyExtended = { + "ext-number": 1, + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "x-x": "PBodiachevskii", + "x-linkedin": "https://www.linkedin.com/company/asyncapi/" +} + +const jsonSchema = require('@definitions/3.0.0/infoExtensions.json'); + +const config = new JsonSchemaTestSuiteConfig( + false, + [], + false, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [example], + onlyRequiredProperties, + withoutRequiredProperties, + extended, + wronglyExtended +); + +describe('Info Extensions', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); diff --git a/test/definitions/3.0.0/models/info/info extensions/empty.json b/test/definitions/3.0.0/models/info/info extensions/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/info extensions/example.json b/test/definitions/3.0.0/models/info/info extensions/example.json deleted file mode 100644 index 331d9f15..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/example.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "x-x": "PBodiachevskii", - "x-linkedin": "https://www.linkedin.com/company/asyncapi/" -} diff --git a/test/definitions/3.0.0/models/info/info extensions/extended.json b/test/definitions/3.0.0/models/info/info extensions/extended.json deleted file mode 100644 index edaedced..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/extended.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "x-number" : 0, - "x-string" : "", - "x-object" : { - "property" : { } - }, - "x-x": "PBodiachevskii", - "x-linkedin": "https://www.linkedin.com/company/asyncapi/" -} diff --git a/test/definitions/3.0.0/models/info/info extensions/index.mjs b/test/definitions/3.0.0/models/info/info extensions/index.mjs deleted file mode 100644 index 199dc128..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/index.mjs +++ /dev/null @@ -1,37 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/infoExtensions.json'); - -describe('Info Extensions', () => { - it('example', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it('empty', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - )); - - it('without required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - )); - - it('only required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json'), - )); - - it.skip('extended. Reason: schema doesn\'t check for extensions', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './extended.json'), - )); - - it.skip('wrongly extended. Reason: schema doesn\'t check for extensions', () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, './wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/info/info extensions/only required properties.json b/test/definitions/3.0.0/models/info/info extensions/only required properties.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/only required properties.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/info extensions/without required properties.json b/test/definitions/3.0.0/models/info/info extensions/without required properties.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/without required properties.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/info extensions/wrongly extended.json b/test/definitions/3.0.0/models/info/info extensions/wrongly extended.json deleted file mode 100644 index f9cd5905..00000000 --- a/test/definitions/3.0.0/models/info/info extensions/wrongly extended.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "ext-number": 1, - "x-number" : 0, - "x-string" : "", - "x-object" : { - "property" : { } - }, - "x-x": "PBodiachevskii", - "x-linkedin": "https://www.linkedin.com/company/asyncapi/" -} diff --git a/test/definitions/3.0.0/models/info/info/properties/contact.mjs b/test/definitions/3.0.0/models/info/info properties/contact.mjs similarity index 96% rename from test/definitions/3.0.0/models/info/info/properties/contact.mjs rename to test/definitions/3.0.0/models/info/info properties/contact.mjs index 8d1f6d5f..42d29468 100644 --- a/test/definitions/3.0.0/models/info/info/properties/contact.mjs +++ b/test/definitions/3.0.0/models/info/info properties/contact.mjs @@ -1,6 +1,5 @@ import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/info.json'); diff --git a/test/definitions/3.0.0/models/info/info/properties/description.mjs b/test/definitions/3.0.0/models/info/info properties/description.mjs similarity index 96% rename from test/definitions/3.0.0/models/info/info/properties/description.mjs rename to test/definitions/3.0.0/models/info/info properties/description.mjs index 315df5bc..7949530a 100644 --- a/test/definitions/3.0.0/models/info/info/properties/description.mjs +++ b/test/definitions/3.0.0/models/info/info properties/description.mjs @@ -1,6 +1,5 @@ import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/info.json'); diff --git a/test/definitions/3.0.0/models/info/info/properties/externalDocs.mjs b/test/definitions/3.0.0/models/info/info properties/externalDocs.mjs similarity index 97% rename from test/definitions/3.0.0/models/info/info/properties/externalDocs.mjs rename to test/definitions/3.0.0/models/info/info properties/externalDocs.mjs index ade365d7..14d0ede9 100644 --- a/test/definitions/3.0.0/models/info/info/properties/externalDocs.mjs +++ b/test/definitions/3.0.0/models/info/info properties/externalDocs.mjs @@ -1,6 +1,5 @@ import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/info.json'); diff --git a/test/definitions/3.0.0/models/info/info/properties/license.mjs b/test/definitions/3.0.0/models/info/info properties/license.mjs similarity index 96% rename from test/definitions/3.0.0/models/info/info/properties/license.mjs rename to test/definitions/3.0.0/models/info/info properties/license.mjs index 392db039..91442a7b 100644 --- a/test/definitions/3.0.0/models/info/info/properties/license.mjs +++ b/test/definitions/3.0.0/models/info/info properties/license.mjs @@ -1,6 +1,5 @@ import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/info.json'); diff --git a/test/definitions/3.0.0/models/info/info/properties/tags.mjs b/test/definitions/3.0.0/models/info/info properties/tags.mjs similarity index 98% rename from test/definitions/3.0.0/models/info/info/properties/tags.mjs rename to test/definitions/3.0.0/models/info/info properties/tags.mjs index 7dc1f770..6b4cc458 100644 --- a/test/definitions/3.0.0/models/info/info/properties/tags.mjs +++ b/test/definitions/3.0.0/models/info/info properties/tags.mjs @@ -1,6 +1,5 @@ import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/info.json'); diff --git a/test/definitions/3.0.0/models/info/info/properties/termsOfService.mjs b/test/definitions/3.0.0/models/info/info properties/termsOfService.mjs similarity index 96% rename from test/definitions/3.0.0/models/info/info/properties/termsOfService.mjs rename to test/definitions/3.0.0/models/info/info properties/termsOfService.mjs index b44a666b..54fcf8e6 100644 --- a/test/definitions/3.0.0/models/info/info/properties/termsOfService.mjs +++ b/test/definitions/3.0.0/models/info/info properties/termsOfService.mjs @@ -1,6 +1,5 @@ import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; +import TestHelper from '@test/test-helper.mjs'; const jsonSchema = require('@definitions/3.0.0/info.json'); diff --git a/test/definitions/3.0.0/models/info/info.test.mjs b/test/definitions/3.0.0/models/info/info.test.mjs new file mode 100644 index 00000000..b9398ec5 --- /dev/null +++ b/test/definitions/3.0.0/models/info/info.test.mjs @@ -0,0 +1,178 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const example = { + "title": "AsyncAPI sample", + "version": "2.0", + "description": "short description", + "termsOfService": "https://www.asyncapi.com/about/", + "contact": { + "name": "AsyncApi", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com" + }, + "license": { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/" + }, + "tags": [ + { + "name": "user", + "description": "User-related messages", + "externalDocs": { + "description" : "Find more info here", + "url" : "https://example.com" + } + } + ], + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + } +} + +const onlyRequiredProperties = { + "title": "AsyncApi sample", + "version": "1.2.34" +} + +const withoutRequiredProperties = { + "description": "Short description", + "termsOfService": "https://www.asyncapi.com/about/", + "contact": { + "name": "AsyncApi", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com" + }, + "license": { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/" + }, + "tags": [ + { + "name": "user", + "description": "User-related messages", + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + } + } + ], + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + } +} + +const extended = { + "title": "AsyncApi sample", + "version": "1.2.34", + "description": "Short description", + "termsOfService": "https://www.asyncapi.com/about/", + "contact": { + "name": "AsyncApi", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com" + }, + "license": { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/" + }, + "tags": [ + { + "name": "user", + "description": "User-related messages", + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + } + } + ], + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + }, + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "x-x": "PBodiachevskii", + "x-linkedin": "https://www.linkedin.com/company/asyncapi/" +} + +const wronglyExtended = { + "title": "AsyncApi sample", + "version": "1.2.34", + "description": "Short description", + "termsOfService": "https://www.asyncapi.com/about/", + "contact": { + "name": "AsyncApi", + "url": "https://www.asyncapi.com", + "email": "java@asyncapi.com" + }, + "license": { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/" + }, + "tags": [ + { + "name": "user", + "description": "User-related messages", + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + } + } + ], + "externalDocs": { + "description": "Find more info here", + "url": "https://example.com" + }, + "ext-number": 1, + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "x-x": "PBodiachevskii", + "x-linkedin": "https://www.linkedin.com/company/asyncapi/" +} + +const jsonSchema = require('@definitions/3.0.0/info.json'); + +const config = new JsonSchemaTestSuiteConfig( + true, + [ + 'must have required property \'version\'', + 'must have required property \'title\'' + ], + true, + [] +); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [example], + onlyRequiredProperties, + withoutRequiredProperties, + extended, + wronglyExtended +); + +describe('Info', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); + +describe('Info Properties', async () => { + await import('@test/definitions/3.0.0/models/info/info properties/description.mjs'); + await import('@test/definitions/3.0.0/models/info/info properties/termsOfService.mjs'); + await import('@test/definitions/3.0.0/models/info/info properties/contact.mjs'); + await import('@test/definitions/3.0.0/models/info/info properties/license.mjs'); + await import('@test/definitions/3.0.0/models/info/info properties/tags.mjs'); + await import('@test/definitions/3.0.0/models/info/info properties/externalDocs.mjs'); +}); diff --git a/test/definitions/3.0.0/models/info/info/empty.json b/test/definitions/3.0.0/models/info/info/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/info/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/info/example.json b/test/definitions/3.0.0/models/info/info/example.json deleted file mode 100644 index 8231edb9..00000000 --- a/test/definitions/3.0.0/models/info/info/example.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "title": "AsyncApi sample", - "version": "2.0", - "description": "short description", - "termsOfService": "https://www.asyncapi.com/about/", - "contact": { - "name": "AsyncApi", - "url": "https://www.asyncapi.com", - "email": "java@asyncapi.com" - }, - "license": { - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/" - }, - "tags": [ - { - "name": "user", - "description": "User-related messages", - "externalDocs": { - "description" : "Find more info here", - "url" : "https://example.com" - } - } - ], - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - } -} diff --git a/test/definitions/3.0.0/models/info/info/extended.json b/test/definitions/3.0.0/models/info/info/extended.json deleted file mode 100644 index 11b4eec2..00000000 --- a/test/definitions/3.0.0/models/info/info/extended.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "title": "AsyncApi sample", - "version": "1.2.34", - "description": "Short description", - "termsOfService": "https://www.asyncapi.com/about/", - "contact": { - "name": "AsyncApi", - "url": "https://www.asyncapi.com", - "email": "java@asyncapi.com" - }, - "license": { - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/" - }, - "tags": [ - { - "name": "user", - "description": "User-related messages", - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - } - } - ], - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - }, - "x-number" : 0, - "x-string" : "", - "x-object" : { - "property" : { } - }, - "x-x": "PBodiachevskii", - "x-linkedin": "https://www.linkedin.com/company/asyncapi/" -} diff --git a/test/definitions/3.0.0/models/info/info/index.mjs b/test/definitions/3.0.0/models/info/info/index.mjs deleted file mode 100644 index 3be3bc0e..00000000 --- a/test/definitions/3.0.0/models/info/info/index.mjs +++ /dev/null @@ -1,52 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/info.json'); - -describe('Info', async () => { - await import('./properties/description.mjs'); - await import('./properties/termsOfService.mjs'); - await import('./properties/contact.mjs'); - await import('./properties/license.mjs'); - await import('./properties/tags.mjs'); - await import('./properties/externalDocs.mjs'); - - it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it(TestHelper.cannotBeEmptyTestName, () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - [ - 'must have required property \'version\'', - 'must have required property \'title\'' - ] - )); - - it(TestHelper.isNotValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - [ - 'must have required property \'version\'', - 'must have required property \'title\'' - ] - )); - - it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json'), - )); - - it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './extended.json'), - )); - - it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, './wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/info/info/only required properties.json b/test/definitions/3.0.0/models/info/info/only required properties.json deleted file mode 100644 index e04a62ca..00000000 --- a/test/definitions/3.0.0/models/info/info/only required properties.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "title": "AsyncApi sample", - "version": "1.2.34" -} diff --git a/test/definitions/3.0.0/models/info/info/without required properties.json b/test/definitions/3.0.0/models/info/info/without required properties.json deleted file mode 100644 index 6c71665d..00000000 --- a/test/definitions/3.0.0/models/info/info/without required properties.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "description": "Short description", - "termsOfService": "https://www.asyncapi.com/about/", - "contact": { - "name": "AsyncApi", - "url": "https://www.asyncapi.com", - "email": "java@asyncapi.com" - }, - "license": { - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/" - }, - "tags": [ - { - "name": "user", - "description": "User-related messages", - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - } - } - ], - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - } -} diff --git a/test/definitions/3.0.0/models/info/info/wrongly extended.json b/test/definitions/3.0.0/models/info/info/wrongly extended.json deleted file mode 100644 index 2024806e..00000000 --- a/test/definitions/3.0.0/models/info/info/wrongly extended.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "title": "AsyncApi sample", - "version": "1.2.34", - "description": "Short description", - "termsOfService": "https://www.asyncapi.com/about/", - "contact": { - "name": "AsyncApi", - "url": "https://www.asyncapi.com", - "email": "java@asyncapi.com" - }, - "license": { - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/" - }, - "tags": [ - { - "name": "user", - "description": "User-related messages", - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - } - } - ], - "externalDocs": { - "description": "Find more info here", - "url": "https://example.com" - }, - "ext-number": 1, - "x-number" : 0, - "x-string" : "", - "x-object" : { - "property" : { } - }, - "x-x": "PBodiachevskii", - "x-linkedin": "https://www.linkedin.com/company/asyncapi/" -} diff --git a/test/definitions/3.0.0/models/info/licence.test.mjs b/test/definitions/3.0.0/models/info/licence.test.mjs new file mode 100644 index 00000000..944e8b91 --- /dev/null +++ b/test/definitions/3.0.0/models/info/licence.test.mjs @@ -0,0 +1,67 @@ +import {describe} from 'vitest'; +import { + JsonSchemaTestSuite, + JsonSchemaTestSuiteConfig, + JsonSchemaTestSuiteData +} from '@test/definitions/base-schema-test.mjs'; + +const example = { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/" +} + +const onlyRequiredProperties = { + "name": "Apache License 2.0" +} + +const withoutRequiredProperties = { + "url": "https://www.apache.org/licenses/", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } +} + +const extended = { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + } +} + +const wronglyExtended = { + "name": "Apache License 2.0", + "url": "https://www.apache.org/licenses/", + "x-number": 0, + "x-string": "", + "x-object": { + "property": {} + }, + "ext-number": 1 +} + +const jsonSchema = require('@definitions/3.0.0/license.json'); + +const data = new JsonSchemaTestSuiteData( + jsonSchema, + [example], + onlyRequiredProperties, + withoutRequiredProperties, + extended, + wronglyExtended +); + +const config = new JsonSchemaTestSuiteConfig( + true, + ['must have required property \'name\''], + false, + [] +); + +describe('License', () => { + new JsonSchemaTestSuite(data, config).testSuite() +}); \ No newline at end of file diff --git a/test/definitions/3.0.0/models/info/license/empty.json b/test/definitions/3.0.0/models/info/license/empty.json deleted file mode 100644 index 0967ef42..00000000 --- a/test/definitions/3.0.0/models/info/license/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/test/definitions/3.0.0/models/info/license/example.json b/test/definitions/3.0.0/models/info/license/example.json deleted file mode 100644 index 61436164..00000000 --- a/test/definitions/3.0.0/models/info/license/example.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/" -} diff --git a/test/definitions/3.0.0/models/info/license/extended.json b/test/definitions/3.0.0/models/info/license/extended.json deleted file mode 100644 index e68cd0c9..00000000 --- a/test/definitions/3.0.0/models/info/license/extended.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - } -} diff --git a/test/definitions/3.0.0/models/info/license/index.mjs b/test/definitions/3.0.0/models/info/license/index.mjs deleted file mode 100644 index 3ce5bdd8..00000000 --- a/test/definitions/3.0.0/models/info/license/index.mjs +++ /dev/null @@ -1,39 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@definitions/3.0.0/license.json'); - -describe('License', () => { - it('example', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './example.json'), - )); - - it('empty', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - ['must have required property \'name\''] - )); - - it('without required properties', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - ['must have required property \'name\''] - )); - - it('only required properties', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './only required properties.json'), - )); - - it('extended', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './extended.json'), - )); - - it('wrongly extended', () => TestHelper.wronglyExtended( - jsonSchema, - path.resolve(__dirname, './wrongly extended.json') - )); -}); diff --git a/test/definitions/3.0.0/models/info/license/only required properties.json b/test/definitions/3.0.0/models/info/license/only required properties.json deleted file mode 100644 index 79e4eb51..00000000 --- a/test/definitions/3.0.0/models/info/license/only required properties.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Apache License 2.0" -} diff --git a/test/definitions/3.0.0/models/info/license/without required properties.json b/test/definitions/3.0.0/models/info/license/without required properties.json deleted file mode 100644 index be63250b..00000000 --- a/test/definitions/3.0.0/models/info/license/without required properties.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "url": "http://www.apache.org/licenses/", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - } -} diff --git a/test/definitions/3.0.0/models/info/license/wrongly extended.json b/test/definitions/3.0.0/models/info/license/wrongly extended.json deleted file mode 100644 index a52ea20d..00000000 --- a/test/definitions/3.0.0/models/info/license/wrongly extended.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "Apache License 2.0", - "url": "http://www.apache.org/licenses/", - "x-number": 0, - "x-string": "", - "x-object": { - "property": {} - }, - "ext-number": 1 -} diff --git a/test/definitions/base-schema-test.mjs b/test/definitions/base-schema-test.mjs new file mode 100644 index 00000000..31c88720 --- /dev/null +++ b/test/definitions/base-schema-test.mjs @@ -0,0 +1,108 @@ +import {it} from 'vitest'; +import TestHelper from '@test/test-helper'; + +export class JsonSchemaTestSuiteData { + + constructor( + jsonSchema, + examples, + onlyRequiredProperties, + withoutRequiredProperties, + extended, + wronglyExtended + ) { + this.jsonSchema = jsonSchema; + this.examples = examples; + this.onlyRequiredProperties = onlyRequiredProperties; + this.withoutRequiredProperties = withoutRequiredProperties; + this.extended = extended; + this.wronglyExtended = wronglyExtended; + } + +} + +export class JsonSchemaTestSuiteConfig { + + constructor( + hasRequiredProperties= false, + expectedErrorsWhenIsWithoutRequiredProperties= [], + canBeExtended = true, + expectedErrorsWhenIsWronglyExtended= [], + ) { + this.hasRequiredProperties = hasRequiredProperties; + this.expectedErrorsWhenIsWithoutRequiredProperties = expectedErrorsWhenIsWithoutRequiredProperties; + this.canBeExtended = canBeExtended; + this.expectedErrorsWhenIsWronglyExtended = expectedErrorsWhenIsWronglyExtended; + } + +} + +export class JsonSchemaTestSuite { + + data; + config; + + /** + * Basic JsonSchema Test Suite. + * + * @param data test data + * @param config test suite config + */ + constructor(data, config = new JsonSchemaTestSuiteConfig()) { + this.data = data; + this.config = config; + } + + testSuite() { + + it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid( + this.data.jsonSchema, + this.data.examples[0], + )); + + if (this.config.hasRequiredProperties) { + + it(TestHelper.cannotBeEmptyTestName, () => TestHelper.objectIsNotValid( + this.data.jsonSchema, + {}, + this.config.expectedErrorsWhenIsWithoutRequiredProperties, + )); + + it(TestHelper.isNotValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsNotValid( + this.data.jsonSchema, + this.data.withoutRequiredProperties, + this.config.expectedErrorsWhenIsWithoutRequiredProperties + )); + + } else { + + it(TestHelper.canBeEmptyTestName, () => TestHelper.objectIsValid( + this.data.jsonSchema, + {}, + )); + + it(TestHelper.isValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsValid( + this.data.jsonSchema, + this.data.withoutRequiredProperties, + )); + + } + + it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid( + this.data.jsonSchema, + this.data.onlyRequiredProperties, + )); + + it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid( + this.data.jsonSchema, + this.data.extended, + )); + + it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended( + this.data.jsonSchema, + this.data.wronglyExtended, + )); + + } + +} \ No newline at end of file