Skip to content

Commit

Permalink
feat: removing v3 check for bundle command (#1138)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukasz Gornicki <[email protected]>
  • Loading branch information
Souvikns and derberg authored Mar 19, 2024
1 parent 2971dd0 commit 065a613
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
7 changes: 0 additions & 7 deletions src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ export default class Bundle extends Command {
const outputFormat = path.extname(argv[0]);
const AsyncAPIFiles = await this.loadFiles(argv);

const containsAsyncAPI3 = AsyncAPIFiles.filter((file) => {
return file.isAsyncAPI3();
});
if (containsAsyncAPI3.length > 0) {
this.error('One of the files you tried to bundle is AsyncAPI v3 format, the bundle command does not support it yet, please checkout https://github.com/asyncapi/bundler/issues/133');
}

if (flags.base) {baseFile = (await load(flags.base)).text();}

const fileContents = AsyncAPIFiles.map((file) => file.text());
Expand Down
29 changes: 13 additions & 16 deletions test/integration/bundle/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,13 @@ import path from 'path';
import { fileCleanup } from '../../helpers';

const spec = fs.readFileSync('./test/integration/bundle/final-asyncapi.yaml', {encoding: 'utf-8'});
const asyncapiv3 = './test/fixtures/specification-v3.yml';

function validateGeneratedSpec(filePath: string, spec: string) {
const generatedSPec = fs.readFileSync(path.resolve(filePath), { encoding: 'utf-8' });
return generatedSPec === spec;
}

describe('bundle', () => {
describe('should handle AsyncAPI v3 document correctly', () => {
test
.stderr()
.stdout()
.command([
'bundle',
asyncapiv3,
'--output=./test/integration/bundle/final.yaml'])
.it('give error', (ctx, done) => {
expect(ctx.stderr).to.equal('Error: One of the files you tried to bundle is AsyncAPI v3 format, the bundle command does not support it yet, please checkout https://github.com/asyncapi/bundler/issues/133\n');
expect(ctx.stdout).to.equal('');
done();
});
});

test
.stdout()
.command([
Expand Down Expand Up @@ -100,3 +84,16 @@ describe('bundle', () => {
done();
});
});

describe('bundle spec v3', () => {
test
.stdout()
.command([
'bundle', './test/integration/bundle/first-asyncapiv3.yaml',
'--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');
fileCleanup('./test/integration/bundle/final.yaml');
done();
});
});
34 changes: 34 additions & 0 deletions test/integration/bundle/first-asyncapiv3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
asyncapi: 3.0.0
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signupsA
channels:
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: './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

0 comments on commit 065a613

Please sign in to comment.