Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replicate incorrect bundling and missing assertions part of #1323 #1389

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b432838
test: replicate incorrect bundling and missing assertions part of #1323
francocm Apr 24, 2024
03ce3a6
Updated assertion styles as per PR feedback as part of https://github…
francocm Apr 26, 2024
e719f24
Fixed incorrect test and incorrect expected files as part of https://…
francocm Apr 26, 2024
c8564ad
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
francocm May 7, 2024
d1c5c19
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
francocm May 9, 2024
1becec0
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
francocm May 9, 2024
d4296c5
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
francocm May 13, 2024
104affb
As per issue raised in https://github.com/APIDevTools/json-schema-ref…
francocm May 13, 2024
3bcdee9
Moved back to validateGeneratedSpec with explicit expects as per PR c…
francocm May 13, 2024
8efa7cf
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 14, 2024
c06a4d4
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 15, 2024
c761c8c
lint fix
francocm May 15, 2024
1fa8a93
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 15, 2024
523b5f2
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 15, 2024
bb0c1fd
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 15, 2024
041f834
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 16, 2024
3fcec67
Merge branch 'master' into fix/1323/bundleNotBundlingExternalFiles
asyncapi-bot May 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions test/integration/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand Down
36 changes: 36 additions & 0 deletions test/integration/bundle/final-asyncapi-with-xorigin.yaml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francocm could you add the spec files in test/fixtures as can be seen for others.

Original file line number Diff line number Diff line change
@@ -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
52 changes: 23 additions & 29 deletions test/integration/bundle/final-asyncapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 50 additions & 0 deletions test/integration/bundle/final-asyncapiv3-with-xorigin.yaml
Original file line number Diff line number Diff line change
@@ -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'
46 changes: 46 additions & 0 deletions test/integration/bundle/final-asyncapiv3.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion test/integration/bundle/first-asyncapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ channels:
user/signedup:
subscribe:
message:
$ref: "./test/integration/bundle/messages.yaml#/messages/UserSignedUp"
$ref: "./test/integration/bundle/messages.yaml#/messages/UserSignedUp"
user/loggedOut:
subscribe:
message:
$ref: "./test/integration/bundle/messages.yaml#/messages/UserLoggedOut"
28 changes: 28 additions & 0 deletions test/integration/bundle/first-asyncapiv3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading