From b432838654988c268dffcf91974ad710d3e28c18 Mon Sep 17 00:00:00 2001 From: Franco Cassar Manghi Date: Wed, 24 Apr 2024 12:53:55 +0100 Subject: [PATCH 1/6] test: replicate incorrect bundling and missing assertions part of #1323 --- test/integration/bundle/bundle.test.ts | 6 +- test/integration/bundle/final-asyncapiv3.yaml | 62 +++++++++++++++++++ test/integration/bundle/first-asyncapiv3.yaml | 15 +++-- 3 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 test/integration/bundle/final-asyncapiv3.yaml diff --git a/test/integration/bundle/bundle.test.ts b/test/integration/bundle/bundle.test.ts index 0cc20e7cb31..4b32fa243a5 100644 --- a/test/integration/bundle/bundle.test.ts +++ b/test/integration/bundle/bundle.test.ts @@ -4,6 +4,7 @@ import path from 'path'; import { fileCleanup } from '../../helpers'; const spec = fs.readFileSync('./test/integration/bundle/final-asyncapi.yaml', {encoding: 'utf-8'}); +const specv3 = fs.readFileSync('./test/integration/bundle/final-asyncapiv3.yaml', {encoding: 'utf-8'}); function validateGeneratedSpec(filePath: string, spec: string) { const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' }); @@ -67,7 +68,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', spec)).to.be.true; fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -79,7 +80,7 @@ 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-asyncapi.yaml', spec)).to.be.true; fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -93,6 +94,7 @@ 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', specv3)).to.be.true fileCleanup('./test/integration/bundle/final.yaml'); done(); }); diff --git a/test/integration/bundle/final-asyncapiv3.yaml b/test/integration/bundle/final-asyncapiv3.yaml new file mode 100644 index 00000000000..9d09321960f --- /dev/null +++ b/test/integration/bundle/final-asyncapiv3.yaml @@ -0,0 +1,62 @@ +asyncapi: 3.0.0 +info: + title: Account Service + version: 1.0.0 + description: This service is in charge of processing user signups +channels: + userSignedup: + address: 'user/signedup' + messages: + userSignedUpMessage: + $ref: '#/components/messages/UserSignedUp' + test: + address: '/test' + messages: + testMessage: + $ref: '#/components/messages/TestMessage' +operations: + UserSignedUp: + action: send + channel: + $ref: '#/channels/userSignedup' + TestOpp: + action: send + channel: + $ref: '#/channels/test' +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 + description: Time stamp when the user logged out + TestMessage: + payload: + type: object + properties: + foo: + type: string + extObjRef: + oneOf: + - $ref: '#/components/messages/UserSignedUp' + - $ref: '#/components/messages/UserLoggedOut' + diff --git a/test/integration/bundle/first-asyncapiv3.yaml b/test/integration/bundle/first-asyncapiv3.yaml index 117d7bad68c..d48dfbcbe8b 100644 --- a/test/integration/bundle/first-asyncapiv3.yaml +++ b/test/integration/bundle/first-asyncapiv3.yaml @@ -12,23 +12,26 @@ channels: test: address: '/test' messages: - testMessage: + message: $ref: '#/components/messages/TestMessage' operations: UserSignedUp: action: send channel: $ref: '#/channels/userSignedup' - messages: - - $ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp' TestOpp: action: send channel: $ref: '#/channels/test' - messages: - - $ref: '#/components/messages/TestMessage' components: messages: TestMessage: payload: - type: string \ No newline at end of file + type: object + properties: + foo: + type: string + extObjRef: + oneOf: + - $ref: './test/integration/bundle/messages.yaml#/messages/UserSignedUp' + - $ref: './test/integration/bundle/messages.yaml#/messages/UserLoggedOut' From 03ce3a6d25219a497d46469430bdeed9c5c8ae82 Mon Sep 17 00:00:00 2001 From: Franco Cassar Manghi Date: Fri, 26 Apr 2024 19:54:49 +0100 Subject: [PATCH 2/6] Updated assertion styles as per PR feedback as part of https://github.com/asyncapi/cli/issues/1323 --- test/integration/bundle/bundle.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/bundle/bundle.test.ts b/test/integration/bundle/bundle.test.ts index 4b32fa243a5..0a8f77b58c5 100644 --- a/test/integration/bundle/bundle.test.ts +++ b/test/integration/bundle/bundle.test.ts @@ -68,7 +68,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)).to.be.true; + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', spec)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -80,7 +80,7 @@ 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)).to.be.true; + expect(validateGeneratedSpec('test/integration/bundle/final-asyncapi.yaml', spec)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -94,7 +94,7 @@ 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', specv3)).to.be.true + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specv3)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); From e719f24b75305a583bb91957a1ff1cc2b74e890b Mon Sep 17 00:00:00 2001 From: Franco Cassar Manghi Date: Fri, 26 Apr 2024 20:21:29 +0100 Subject: [PATCH 3/6] Fixed incorrect test and incorrect expected files as part of https://github.com/asyncapi/cli/issues/1323 --- test/integration/bundle/bundle.test.ts | 10 +++++----- test/integration/bundle/final-asyncapi.yaml | 3 +-- test/integration/bundle/final-asyncapiv3.yaml | 7 +++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/integration/bundle/bundle.test.ts b/test/integration/bundle/bundle.test.ts index 0a8f77b58c5..e11a31a07ef 100644 --- a/test/integration/bundle/bundle.test.ts +++ b/test/integration/bundle/bundle.test.ts @@ -6,9 +6,9 @@ import { fileCleanup } from '../../helpers'; const spec = fs.readFileSync('./test/integration/bundle/final-asyncapi.yaml', {encoding: 'utf-8'}); const specv3 = fs.readFileSync('./test/integration/bundle/final-asyncapiv3.yaml', {encoding: 'utf-8'}); -function validateGeneratedSpec(filePath: string, spec: string) { +function assertSpecsEqual(filePath: string, spec: string) { const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' }); - return generatedSPec === spec; + expect(generatedSPec).to.equal(spec); } describe('bundle', () => { @@ -68,7 +68,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)).to.equal(true); + assertSpecsEqual('test/integration/bundle/final.yaml', spec); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -80,7 +80,7 @@ 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)).to.equal(true); + assertSpecsEqual('test/integration/bundle/final.yaml', spec); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -94,7 +94,7 @@ 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', specv3)).to.equal(true); + assertSpecsEqual('test/integration/bundle/final.yaml', specv3); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); diff --git a/test/integration/bundle/final-asyncapi.yaml b/test/integration/bundle/final-asyncapi.yaml index 4624b746503..abf2b44148b 100644 --- a/test/integration/bundle/final-asyncapi.yaml +++ b/test/integration/bundle/final-asyncapi.yaml @@ -37,5 +37,4 @@ components: description: Id the user timestamp: type: number - descriptio: Time stamp when the user logged out - + description: Time stamp when the user logged out diff --git a/test/integration/bundle/final-asyncapiv3.yaml b/test/integration/bundle/final-asyncapiv3.yaml index 9d09321960f..f435bd592bf 100644 --- a/test/integration/bundle/final-asyncapiv3.yaml +++ b/test/integration/bundle/final-asyncapiv3.yaml @@ -5,14 +5,14 @@ info: description: This service is in charge of processing user signups channels: userSignedup: - address: 'user/signedup' + address: user/signedup messages: userSignedUpMessage: $ref: '#/components/messages/UserSignedUp' test: - address: '/test' + address: /test messages: - testMessage: + message: $ref: '#/components/messages/TestMessage' operations: UserSignedUp: @@ -59,4 +59,3 @@ components: oneOf: - $ref: '#/components/messages/UserSignedUp' - $ref: '#/components/messages/UserLoggedOut' - From 104affbd67adc023e92979bee8bd21379458e6ed Mon Sep 17 00:00:00 2001 From: Franco Cassar Manghi Date: Mon, 13 May 2024 12:08:58 +0100 Subject: [PATCH 4/6] As per issue raised in https://github.com/APIDevTools/json-schema-ref-parser/issues/349 this scope of this PR will ignore the extra component block --- .../integration/bundle/final-asyncapiv3-with-xorigin.yaml | 8 +++++++- test/integration/bundle/final-asyncapiv3.yaml | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml b/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml index 9afca33e260..0ab16bbc637 100644 --- a/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml +++ b/test/integration/bundle/final-asyncapiv3-with-xorigin.yaml @@ -21,7 +21,7 @@ channels: type: string format: email description: Email of the user - x-origin: ./test/integration/bundle/messages.yaml#/messages/UserSignedUp + x-origin: ./test/integration/bundle/messages.yaml#/messages/UserSignedUp test: address: /test messages: @@ -42,3 +42,9 @@ operations: $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 index 5d0af90e951..a1751b6f4de 100644 --- a/test/integration/bundle/final-asyncapiv3.yaml +++ b/test/integration/bundle/final-asyncapiv3.yaml @@ -39,3 +39,8 @@ operations: $ref: '#/channels/test' messages: - $ref: '#/channels/test/messages/testMessage' +components: + messages: + TestMessage: + payload: + type: string From 3bcdee9c65ebc1e9a90a9ea09e9af2a07e5069c7 Mon Sep 17 00:00:00 2001 From: Franco Cassar Manghi Date: Mon, 13 May 2024 13:27:25 +0100 Subject: [PATCH 5/6] Moved back to validateGeneratedSpec with explicit expects as per PR comments in #1389. --- test/integration/bundle/bundle.test.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/integration/bundle/bundle.test.ts b/test/integration/bundle/bundle.test.ts index f62fe5c63a3..d7f3d0af7eb 100644 --- a/test/integration/bundle/bundle.test.ts +++ b/test/integration/bundle/bundle.test.ts @@ -8,9 +8,9 @@ const specV2WithXOrigin = fs.readFileSync('./test/integration/bundle/final-async 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 assertSpecsEqual(filePath: string, spec: string) { +function validateGeneratedSpec(filePath: string, spec: string): boolean { const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' }); - expect(generatedSPec).to.equal(spec); + return generatedSPec === spec; } describe('bundle', () => { @@ -59,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'); - assertSpecsEqual('test/integration/bundle/final.yaml', specV2NoXOrigin); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specV2NoXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -71,7 +71,7 @@ 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'); - assertSpecsEqual('test/integration/bundle/final.yaml', specV2NoXOrigin); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specV2NoXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -83,7 +83,7 @@ describe('bundle', () => { ]) .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'); - assertSpecsEqual('test/integration/bundle/final.yaml', specV2WithXOrigin); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specV2WithXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -97,7 +97,7 @@ 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'); - assertSpecsEqual('test/integration/bundle/final.yaml', specv3NoXOrigin); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specv3NoXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); @@ -109,7 +109,7 @@ describe('bundle spec v3', () => { '--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'); - assertSpecsEqual('test/integration/bundle/final.yaml', specv3WithXOrigin); + expect(validateGeneratedSpec('test/integration/bundle/final.yaml', specv3WithXOrigin)).to.equal(true); fileCleanup('./test/integration/bundle/final.yaml'); done(); }); From c761c8cdcc0823596c2f1d907765007a79c57b4d Mon Sep 17 00:00:00 2001 From: Franco Cassar Manghi Date: Wed, 15 May 2024 10:56:21 +0100 Subject: [PATCH 6/6] lint fix --- test/integration/bundle/bundle.test.ts | 40 +++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/integration/bundle/bundle.test.ts b/test/integration/bundle/bundle.test.ts index d7f3d0af7eb..c9098f9f466 100644 --- a/test/integration/bundle/bundle.test.ts +++ b/test/integration/bundle/bundle.test.ts @@ -77,16 +77,16 @@ describe('bundle', () => { }); 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(); - }); + .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(); + }); }); describe('bundle spec v3', () => { @@ -103,14 +103,14 @@ describe('bundle spec v3', () => { }); 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(); - }); + .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(); + }); });