From ce4bd278541deb56128921274e598fbcc23b9a21 Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Fri, 14 Jun 2024 16:18:23 +0400 Subject: [PATCH] test(definitions): use .each for anypointmq tests https://github.com/asyncapi/spec-json-schemas/issues/539 --- .../anypointmq/0.0.1/channel/empty.json | 1 - .../anypointmq/0.0.1/channel/index.mjs | 37 --------- .../anypointmq/0.0.1/message/empty.json | 1 - .../anypointmq/0.0.1/message/index.mjs | 37 --------- test/bindings/anypointmq/anypointmq.test.mjs | 75 +++++++++++++++++++ test/bindings/anypointmq/index.mjs | 8 -- test/bindings/bindings.suite.mjs | 1 - vite.config.ts | 1 + 8 files changed, 76 insertions(+), 85 deletions(-) delete mode 100644 test/bindings/anypointmq/0.0.1/channel/empty.json delete mode 100644 test/bindings/anypointmq/0.0.1/channel/index.mjs delete mode 100644 test/bindings/anypointmq/0.0.1/message/empty.json delete mode 100644 test/bindings/anypointmq/0.0.1/message/index.mjs create mode 100644 test/bindings/anypointmq/anypointmq.test.mjs delete mode 100644 test/bindings/anypointmq/index.mjs diff --git a/test/bindings/anypointmq/0.0.1/channel/empty.json b/test/bindings/anypointmq/0.0.1/channel/empty.json deleted file mode 100644 index 9e26dfee..00000000 --- a/test/bindings/anypointmq/0.0.1/channel/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/test/bindings/anypointmq/0.0.1/channel/index.mjs b/test/bindings/anypointmq/0.0.1/channel/index.mjs deleted file mode 100644 index c72f1e70..00000000 --- a/test/bindings/anypointmq/0.0.1/channel/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/anypointmq/0.0.1/channel.json'); - -describe('Channel', () => { - 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/anypointmq/0.0.1/message/empty.json b/test/bindings/anypointmq/0.0.1/message/empty.json deleted file mode 100644 index 9e26dfee..00000000 --- a/test/bindings/anypointmq/0.0.1/message/empty.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/test/bindings/anypointmq/0.0.1/message/index.mjs b/test/bindings/anypointmq/0.0.1/message/index.mjs deleted file mode 100644 index 67be721a..00000000 --- a/test/bindings/anypointmq/0.0.1/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/anypointmq/0.0.1/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/anypointmq/anypointmq.test.mjs b/test/bindings/anypointmq/anypointmq.test.mjs new file mode 100644 index 00000000..0aa3fbe6 --- /dev/null +++ b/test/bindings/anypointmq/anypointmq.test.mjs @@ -0,0 +1,75 @@ +import {it} from 'vitest'; +import TestHelper from '@test/test-helper.mjs'; +import path from 'path'; + +describe.each([ + '0.0.1' +])('Anypoint MQ bindings v%s', async (bindingVersion) => { + + const channelSchema = await import(`@bindings/anypointmq/${bindingVersion}/channel.json`); + const messageSchema = await import(`@bindings/anypointmq/${bindingVersion}/message.json`); + + describe('channel', () => { + it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/example.json`), + )); + + it(TestHelper.canBeEmptyTestName, () => TestHelper.objectIsValid( + channelSchema, + {} + )); + + it(TestHelper.isValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsValid( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/without required properties.json`), + )); + + it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid( + channelSchema, + path.resolve(__dirname, `./${bindingVersion}/channel/only required properties.json`), + )); + + 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`), + )); + }) +}) \ No newline at end of file diff --git a/test/bindings/anypointmq/index.mjs b/test/bindings/anypointmq/index.mjs deleted file mode 100644 index 11a70172..00000000 --- a/test/bindings/anypointmq/index.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import {describe} from 'vitest'; - -describe('Anypoint MQ Test Suite', () => { - describe('0.0.1', async () => { - await import('./0.0.1/channel'); - await import('./0.0.1/message'); - }); -}) \ No newline at end of file diff --git a/test/bindings/bindings.suite.mjs b/test/bindings/bindings.suite.mjs index 39e74095..cb6ca93c 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/anypointmq/index.mjs'); await import('@test/bindings/googlepubsub/index.mjs'); await import('@test/bindings/http/index.mjs'); await import('@test/bindings/ibmmq/index.mjs'); diff --git a/vite.config.ts b/vite.config.ts index 6694dfe6..6efe3c13 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,6 +12,7 @@ export default defineConfig({ '**/test/index.test.mjs', '**/test/bindings/bindings.suite.mjs', '**/test/bindings/amqp/amqp.test.mjs', + '**/test/bindings/anypointmq/anypointmq.test.mjs', '**/test/definitions/3.0.0/definitions.suite.mjs', ], reporters: ['verbose'] // https://vitest.dev/guide/reporters#custom-reporters