From e930ef18731755bab7fd9cd009de31d2a12e74de Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Fri, 14 Jun 2024 15:27:04 +0400 Subject: [PATCH] test(definitions): use .each for amqp tests https://github.com/asyncapi/spec-json-schemas/issues/539 --- test/ajv-schemes.js | 4 +- test/bindings/amqp/0.2.0/channel/index.mjs | 44 ------- test/bindings/amqp/0.2.0/message/index.mjs | 37 ------ test/bindings/amqp/0.2.0/operation/index.mjs | 37 ------ test/bindings/amqp/0.3.0/channel/index.mjs | 44 ------- test/bindings/amqp/0.3.0/message/index.mjs | 37 ------ test/bindings/amqp/0.3.0/operation/index.mjs | 37 ------ test/bindings/amqp/amqp.test.mjs | 125 +++++++++++++++++++ test/bindings/amqp/index.mjs | 15 --- test/bindings/bindings.suite.mjs | 1 - test/test-helper.mjs | 1 + vite.config.ts | 1 + 12 files changed, 129 insertions(+), 254 deletions(-) delete mode 100644 test/bindings/amqp/0.2.0/channel/index.mjs delete mode 100644 test/bindings/amqp/0.2.0/message/index.mjs delete mode 100644 test/bindings/amqp/0.2.0/operation/index.mjs delete mode 100644 test/bindings/amqp/0.3.0/channel/index.mjs delete mode 100644 test/bindings/amqp/0.3.0/message/index.mjs delete mode 100644 test/bindings/amqp/0.3.0/operation/index.mjs create mode 100644 test/bindings/amqp/amqp.test.mjs delete mode 100644 test/bindings/amqp/index.mjs diff --git a/test/ajv-schemes.js b/test/ajv-schemes.js index 8b2d79ad..b2c4bbab 100644 --- a/test/ajv-schemes.js +++ b/test/ajv-schemes.js @@ -1,10 +1,10 @@ module.exports = schemesV3_0_0; function bindingSchemes(ajv) { - ajv.addSchema(require('@bindings/amqp/0.2.0/channel.json')); + // ajv.addSchema(require('@bindings/amqp/0.2.0/channel.json')); ajv.addSchema(require('@bindings/amqp/0.2.0/message.json')); ajv.addSchema(require('@bindings/amqp/0.2.0/operation.json')); - ajv.addSchema(require('@bindings/amqp/0.3.0/channel.json')); + // ajv.addSchema(require('@bindings/amqp/0.3.0/channel.json')); ajv.addSchema(require('@bindings/amqp/0.3.0/message.json')); ajv.addSchema(require('@bindings/amqp/0.3.0/operation.json')); diff --git a/test/bindings/amqp/0.2.0/channel/index.mjs b/test/bindings/amqp/0.2.0/channel/index.mjs deleted file mode 100644 index d9a3fc1b..00000000 --- a/test/bindings/amqp/0.2.0/channel/index.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@bindings/amqp/0.2.0/channel.json'); - -describe('Channel', () => { - it('is: routingKey', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './examples/is routing key.json'), - )); - - it('is: queue', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './examples/is queue.json'), - )); - - it.skip('empty', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - ['must have required property \'is\''] - )); - - it.skip('without required properties', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - ['must have required property \'is\''] - )); - - it.skip('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/bindings/amqp/0.2.0/message/index.mjs b/test/bindings/amqp/0.2.0/message/index.mjs deleted file mode 100644 index 3b33d9ca..00000000 --- a/test/bindings/amqp/0.2.0/message/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('@bindings/amqp/0.2.0/message.json'); - -describe('Message', () => { - 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('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/bindings/amqp/0.2.0/operation/index.mjs b/test/bindings/amqp/0.2.0/operation/index.mjs deleted file mode 100644 index 20024800..00000000 --- a/test/bindings/amqp/0.2.0/operation/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('@bindings/amqp/0.2.0/operation.json'); - -describe('Operation', () => { - 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('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/bindings/amqp/0.3.0/channel/index.mjs b/test/bindings/amqp/0.3.0/channel/index.mjs deleted file mode 100644 index 79713f8a..00000000 --- a/test/bindings/amqp/0.3.0/channel/index.mjs +++ /dev/null @@ -1,44 +0,0 @@ -import {describe, it} from 'vitest'; -import TestHelper from '@test/test-helper'; -import path from 'path'; - -const jsonSchema = require('@bindings/amqp/0.3.0/channel.json'); - -describe('Channel', () => { - it('is: routingKey', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './examples/is routing key.json'), - )); - - it('is: queue', () => TestHelper.objectIsValid( - jsonSchema, - path.resolve(__dirname, './examples/is queue.json'), - )); - - it.skip('empty', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './empty.json'), - ['must have required property \'is\''] - )); - - it.skip('without required properties', () => TestHelper.objectIsNotValid( - jsonSchema, - path.resolve(__dirname, './without required properties.json'), - ['must have required property \'is\''] - )); - - it.skip('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/bindings/amqp/0.3.0/message/index.mjs b/test/bindings/amqp/0.3.0/message/index.mjs deleted file mode 100644 index 7ce6a8ec..00000000 --- a/test/bindings/amqp/0.3.0/message/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('@bindings/amqp/0.3.0/message.json'); - -describe('Message', () => { - 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('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/bindings/amqp/0.3.0/operation/index.mjs b/test/bindings/amqp/0.3.0/operation/index.mjs deleted file mode 100644 index 91ce821c..00000000 --- a/test/bindings/amqp/0.3.0/operation/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('@bindings/amqp/0.3.0/operation.json'); - -describe('Operation', () => { - 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('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/bindings/amqp/amqp.test.mjs b/test/bindings/amqp/amqp.test.mjs new file mode 100644 index 00000000..f9025e76 --- /dev/null +++ b/test/bindings/amqp/amqp.test.mjs @@ -0,0 +1,125 @@ +import {it, test} from 'vitest'; +import TestHelper from '@test/test-helper.mjs'; +import path from 'path'; + +describe.each([ + '0.2.0', + '0.3.0' +])('AMQP bindings v%s', async (bindingVersion) => { + + const channelSchema = await import(`@bindings/amqp/${bindingVersion}/channel.json`); + const messageSchema = await import(`@bindings/amqp/${bindingVersion}/message.json`); + const operationSchema = await import(`@bindings/amqp/${bindingVersion}/operation.json`); + + describe('channel', () => { + it('is: routingKey', () => TestHelper.objectIsValid( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/examples/is routing key.json`), + )); + + it('is: queue', () => TestHelper.objectIsValid( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/examples/is queue.json`), + )); + + it(TestHelper.cannotBeEmptyTestName, () => TestHelper.objectIsNotValid( + channelSchema, + {}, + [ + 'must have required property \'exchange\'', + 'must have required property \'queue\'', + 'must match exactly one schema in oneOf' + ] + )); + + it.todo('without required properties - \'is\' must be required property?', () => TestHelper.objectIsNotValid( + channelSchema, + { + bindingVersion: bindingVersion + }, + [] + )); + + it.todo('only required properties - \'is\' must be required property?', () => TestHelper.objectIsNotValid( + channelSchema, + { + bindingVersion: bindingVersion + }, + [] + )); + + it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/extended.json`), + )); + + it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/wrongly extended.json`), + )); + }) + + describe('message', () => { + it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid( + messageSchema, + path.resolve(__dirname, `./${bindingVersion}/message/example.json`), + )); + + it(TestHelper.canBeEmptyTestName, () => TestHelper.objectIsValid( + messageSchema, + {} + )); + + it(TestHelper.isValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsValid( + messageSchema, + path.resolve(__dirname, `./${bindingVersion}/message/without required properties.json`), + )); + + it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid( + messageSchema, + path.resolve(__dirname, `./${bindingVersion}/message/only required properties.json`), + )); + + it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid( + messageSchema, + path.resolve(__dirname, `./${bindingVersion}/message/extended.json`), + )); + + it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended( + messageSchema, + path.resolve(__dirname, `./${bindingVersion}/message/wrongly extended.json`), + )); + }) + + describe('operation', () => { + it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid( + operationSchema, + path.resolve(__dirname, `./${bindingVersion}/operation/example.json`), + )); + + it(TestHelper.canBeEmptyTestName, () => TestHelper.objectIsValid( + operationSchema, + {} + )); + + it(TestHelper.isValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsValid( + operationSchema, + path.resolve(__dirname, `./${bindingVersion}/operation/without required properties.json`), + )); + + it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid( + operationSchema, + path.resolve(__dirname, `./${bindingVersion}/operation/only required properties.json`), + )); + + it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid( + operationSchema, + path.resolve(__dirname, `./${bindingVersion}/operation/extended.json`), + )); + + it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended( + operationSchema, + path.resolve(__dirname, `./${bindingVersion}/operation/wrongly extended.json`), + )); + }) +}) \ No newline at end of file diff --git a/test/bindings/amqp/index.mjs b/test/bindings/amqp/index.mjs deleted file mode 100644 index 95bfd3c6..00000000 --- a/test/bindings/amqp/index.mjs +++ /dev/null @@ -1,15 +0,0 @@ -import {describe} from 'vitest'; - -describe('AMQP Test Suite', () => { - describe('0.2.0', async () => { - await import('./0.2.0/channel'); - await import('./0.2.0/message'); - await import('./0.2.0/operation'); - }); - - describe('0.3.0', async () => { - await import('./0.3.0/channel'); - await import('./0.3.0/message'); - await import('./0.3.0/operation'); - }); -}) \ No newline at end of file diff --git a/test/bindings/bindings.suite.mjs b/test/bindings/bindings.suite.mjs index 88cbee8d..39e74095 100644 --- a/test/bindings/bindings.suite.mjs +++ b/test/bindings/bindings.suite.mjs @@ -1,7 +1,6 @@ import {describe} from 'vitest'; describe('Bindings Test Suite', async () => { - await import('@test/bindings/amqp/index.mjs'); await import('@test/bindings/anypointmq/index.mjs'); await import('@test/bindings/googlepubsub/index.mjs'); await import('@test/bindings/http/index.mjs'); diff --git a/test/test-helper.mjs b/test/test-helper.mjs index 999bb90f..532822c7 100644 --- a/test/test-helper.mjs +++ b/test/test-helper.mjs @@ -76,6 +76,7 @@ export default class TestHelper { ; const validationResult = validator(model); + // console.log(validator.errors); assert(validationResult === true, `Object MUST be valid`); } diff --git a/vite.config.ts b/vite.config.ts index 12bbf616..6694dfe6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,6 +11,7 @@ export default defineConfig({ '**/test/bundler.mjs', '**/test/index.test.mjs', '**/test/bindings/bindings.suite.mjs', + '**/test/bindings/amqp/amqp.test.mjs', '**/test/definitions/3.0.0/definitions.suite.mjs', ], reporters: ['verbose'] // https://vitest.dev/guide/reporters#custom-reporters