diff --git a/test/integration/bundle/bundle.test.ts b/test/integration/bundle/bundle.test.ts index f1ac4bf776a..c9098f9f466 100644 --- a/test/integration/bundle/bundle.test.ts +++ b/test/integration/bundle/bundle.test.ts @@ -3,9 +3,12 @@ import fs from 'fs'; import path from 'path'; import { fileCleanup } from '../../helpers'; -const spec = fs.readFileSync('./test/integration/bundle/final-asyncapi.yaml', {encoding: 'utf-8'}); +const specV2NoXOrigin = fs.readFileSync('./test/integration/bundle/final-asyncapi.yaml', {encoding: 'utf-8'}); +const specV2WithXOrigin = fs.readFileSync('./test/integration/bundle/final-asyncapi-with-xorigin.yaml', {encoding: 'utf-8'}); +const specv3NoXOrigin = fs.readFileSync('./test/integration/bundle/final-asyncapiv3.yaml', {encoding: 'utf-8'}); +const specv3WithXOrigin = fs.readFileSync('./test/integration/bundle/final-asyncapiv3-with-xorigin.yaml', {encoding: 'utf-8'}); -function validateGeneratedSpec(filePath: string, spec: string) { +function validateGeneratedSpec(filePath: string, spec: string): boolean { const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' }); return generatedSPec === spec; } @@ -56,7 +59,7 @@ describe('bundle', () => { ]) .it('should be able to bundle multiple specs along with custom reference', (ctx, done) => { expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n'); - expect(validateGeneratedSpec('test/integration/bundle/final.yaml', spec)); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specV2NoXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -68,7 +71,19 @@ describe('bundle', () => { ]) .it('should be able to bundle correctly with overwriting base file', (ctx, done) => { expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n'); - expect(validateGeneratedSpec('test/integration/bundle/final-asyncapi.yaml', spec)); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specV2NoXOrigin)).to.equal(true); + fileCleanup('./test/integration/bundle/final.yaml'); + done(); + }); + + test + .stdout() + .command([ + 'bundle', './test/integration/bundle/first-asyncapi.yaml', './test/integration/bundle/feature.yaml', '--output=test/integration/bundle/final.yaml', '-x' + ]) + .it('should be able to bundle multiple specs including x-origin', (ctx, done) => { + expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n'); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specV2WithXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -82,6 +97,19 @@ describe('bundle spec v3', () => { '--output=test/integration/bundle/final.yaml', ]).it('should be able to bundle v3 spec correctly', (ctx, done) => { expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n'); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specv3NoXOrigin)).to.equal(true); + fileCleanup('./test/integration/bundle/final.yaml'); + done(); + }); + + test + .stdout() + .command([ + 'bundle', './test/integration/bundle/first-asyncapiv3.yaml', + '--output=test/integration/bundle/final.yaml', '-x' + ]).it('should be able to bundle v3 spec correctly including x-origin', (ctx, done) => { + expect(ctx.stdout).to.contain('Check out your shiny new bundled files at test/integration/bundle/final.yaml\n'); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specv3WithXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); diff --git a/test/integration/bundle/final-asyncapi-with-xorigin.yaml b/test/integration/bundle/final-asyncapi-with-xorigin.yaml new file mode 100644 index 00000000000..30953322b00 --- /dev/null +++ b/test/integration/bundle/final-asyncapi-with-xorigin.yaml @@ -0,0 +1,36 @@ +asyncapi: 2.6.0 +info: + title: Account Service + version: 1.0.0 + description: This service is in charge of processing user signups +channels: + user/signedup: + subscribe: + message: + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user + x-origin: ./test/integration/bundle/messages.yaml#/messages/UserSignedUp + user/loggedOut: + subscribe: + message: + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + userId: + type: string + description: Id the user + timestamp: + type: number + description: Time stamp when the user logged out + x-origin: ./test/integration/bundle/messages.yaml#/messages/UserLoggedOut diff --git a/test/integration/bundle/final-asyncapi.yaml b/test/integration/bundle/final-asyncapi.yaml index 9de32aa5d81..8bf8f1d8bc9 100644 --- a/test/integration/bundle/final-asyncapi.yaml +++ b/test/integration/bundle/final-asyncapi.yaml @@ -7,34 +7,28 @@ channels: user/signedup: subscribe: message: - $ref: '#/components/messages/UserSignedUp' + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user user/loggedOut: - unsubcribe: + subscribe: message: - $ref: '#/components/messages/UserLoggedOut' -components: - messages: - UserSignedUp: - payload: - type: object - properties: - displayName: - type: string - description: Name of the user - email: - type: string - format: email - description: Email of the user - UserLoggedOut: - payload: - type: object - properties: - displayName: - type: string - description: Name of the user - userId: - type: string - description: Id the user - timestamp: - type: number - descriptio: Time stamp when the user logged out + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + userId: + type: string + description: Id the user + timestamp: + type: number + description: Time stamp when the user logged out diff --git a/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml b/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml new file mode 100644 index 00000000000..0ab16bbc637 --- /dev/null +++ b/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml @@ -0,0 +1,50 @@ +asyncapi: 3.0.0 +info: + title: Example Service + version: 1.0.0 + description: Example Service. +channels: + commentLikedChannel: + address: comment/liked + x-origin: ./test/integration/bundle/channels.yaml#/channels/commentLikedChannel + userSignedup: + address: user/signedup + messages: + userSignedUpMessage: + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user + x-origin: ./test/integration/bundle/messages.yaml#/messages/UserSignedUp + test: + address: /test + messages: + testMessage: + payload: + type: string + x-origin: '#/components/messages/TestMessage' +operations: + UserSignedUp: + action: send + channel: + $ref: '#/channels/userSignedup' + messages: + - $ref: '#/channels/userSignedup/messages/userSignedUpMessage' + TestOpp: + action: send + channel: + $ref: '#/channels/test' + messages: + - $ref: '#/channels/test/messages/testMessage' +components: + messages: + TestMessage: + payload: + type: string + x-origin: '#/components/messages/TestMessage' diff --git a/test/integration/bundle/final-asyncapiv3.yaml b/test/integration/bundle/final-asyncapiv3.yaml new file mode 100644 index 00000000000..a1751b6f4de --- /dev/null +++ b/test/integration/bundle/final-asyncapiv3.yaml @@ -0,0 +1,46 @@ +asyncapi: 3.0.0 +info: + title: Example Service + version: 1.0.0 + description: Example Service. +channels: + commentLikedChannel: + address: comment/liked + userSignedup: + address: user/signedup + messages: + userSignedUpMessage: + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user + test: + address: /test + messages: + testMessage: + payload: + type: string +operations: + UserSignedUp: + action: send + channel: + $ref: '#/channels/userSignedup' + messages: + - $ref: '#/channels/userSignedup/messages/userSignedUpMessage' + TestOpp: + action: send + channel: + $ref: '#/channels/test' + messages: + - $ref: '#/channels/test/messages/testMessage' +components: + messages: + TestMessage: + payload: + type: string diff --git a/test/integration/bundle/first-asyncapi.yaml b/test/integration/bundle/first-asyncapi.yaml index d41ed4a2fec..850b201420a 100644 --- a/test/integration/bundle/first-asyncapi.yaml +++ b/test/integration/bundle/first-asyncapi.yaml @@ -7,4 +7,8 @@ channels: user/signedup: subscribe: message: - $ref: "./test/integration/bundle/messages.yaml#/messages/UserSignedUp" \ No newline at end of file + $ref: "./test/integration/bundle/messages.yaml#/messages/UserSignedUp" + user/loggedOut: + subscribe: + message: + $ref: "./test/integration/bundle/messages.yaml#/messages/UserLoggedOut" diff --git a/test/integration/bundle/first-asyncapiv3.yaml b/test/integration/bundle/first-asyncapiv3.yaml index d49bb67334c..00e7cf8b8ce 100644 --- a/test/integration/bundle/first-asyncapiv3.yaml +++ b/test/integration/bundle/first-asyncapiv3.yaml @@ -6,3 +6,31 @@ info: channels: commentLikedChannel: $ref: './test/integration/bundle/channels.yaml#/channels/commentLikedChannel' + userSignedup: + address: 'user/signedup' + messages: + userSignedUpMessage: + $ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp' + test: + address: '/test' + messages: + testMessage: + $ref: '#/components/messages/TestMessage' +operations: + UserSignedUp: + action: send + channel: + $ref: '#/channels/userSignedup' + messages: + - $ref: '#/channels/userSignedup/messages/userSignedUpMessage' + TestOpp: + action: send + channel: + $ref: '#/channels/test' + messages: + - $ref: '#/channels/test/messages/testMessage' +components: + messages: + TestMessage: + payload: + type: string