-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4835fb
commit 2f9b418
Showing
6 changed files
with
161 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
asyncapi: 3.0.0 | ||
info: | ||
title: Account Service | ||
version: 1.0.0 | ||
description: This service is in charge of processing user signups | ||
channels: | ||
user/signedup: | ||
address: user/signedup | ||
messages: | ||
subscribe.message: | ||
$ref: '#/components/messages/UserSignedUp' | ||
operations: | ||
user/signedup.subscribe: | ||
action: send | ||
channel: | ||
$ref: '#/channels/user~1signedup' | ||
messages: | ||
- $ref: '#/components/messages/UserSignedUp' | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { sanitizeTemplateApiVersion, usesNewAPI, parse } = require('../lib/parser'); | ||
const dummyV2Document = fs.readFileSync(path.resolve(__dirname, './docs/dummy.yml'), 'utf8'); | ||
const dummyV3Document = fs.readFileSync(path.resolve(__dirname, './docs/dummyV3.yml'), 'utf8'); | ||
|
||
describe('Parser', () => { | ||
describe('sanitizeTemplateApiVersion', () => { | ||
it('should return version number when given `v1` syntax', () => { | ||
const rawVersion = 'v1'; | ||
const expectedVersion = '1'; | ||
const sanitizedVersion = sanitizeTemplateApiVersion(rawVersion); | ||
|
||
expect(sanitizedVersion).toStrictEqual(expectedVersion); | ||
}); | ||
it('should return version number when given `1` syntax', () => { | ||
const rawVersion = '1'; | ||
const expectedVersion = '1'; | ||
const sanitizedVersion = sanitizeTemplateApiVersion(rawVersion); | ||
|
||
expect(sanitizedVersion).toStrictEqual(expectedVersion); | ||
}); | ||
}); | ||
describe('usesNewAPI', () => { | ||
it('should use new parser api if v1', () => { | ||
const templateConfig = { | ||
apiVersion: 'v1' | ||
}; | ||
const isUsingNewAPI = usesNewAPI(templateConfig); | ||
|
||
expect(isUsingNewAPI).toStrictEqual(true); | ||
}); | ||
it('should use new parser api if v2', () => { | ||
const templateConfig = { | ||
apiVersion: 'v2' | ||
}; | ||
const isUsingNewAPI = usesNewAPI(templateConfig); | ||
|
||
expect(isUsingNewAPI).toStrictEqual(true); | ||
}); | ||
it('should not use new API if no apiVersion', () => { | ||
const templateConfig = { }; | ||
const isUsingNewAPI = usesNewAPI(templateConfig); | ||
|
||
expect(isUsingNewAPI).toStrictEqual(false); | ||
}); | ||
}); | ||
describe('parse', () => { | ||
it('should be able to parse AsyncAPI v2 document for parser API v1', async () => { | ||
const parsedDocument = await parse(dummyV2Document, {}, {templateConfig: {apiVersion: 'v1'}}); | ||
|
||
expect(parsedDocument).toBeDefined(); | ||
expect(parsedDocument.document.version()).toEqual('2.3.0'); | ||
}); | ||
it('should be able to parse AsyncAPI v2 document for parser API v2', async () => { | ||
const parsedDocument = await parse(dummyV2Document, {}, {templateConfig: {apiVersion: 'v2'}}); | ||
|
||
expect(parsedDocument).toBeDefined(); | ||
expect(parsedDocument.document.version()).toEqual('2.3.0'); | ||
}); | ||
it('should not be able to parse AsyncAPI v3 document for parser API v1', async () => { | ||
const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {apiVersion: 'v1'}}); | ||
|
||
expect(parsedDocument).toBeDefined(); | ||
expect(parsedDocument.document).not.toBeDefined(); | ||
}); | ||
it('should not be able to parse AsyncAPI v3 document for old parser', async () => { | ||
const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {}}); | ||
|
||
expect(parsedDocument).toBeDefined(); | ||
expect(parsedDocument.document).not.toBeDefined(); | ||
}); | ||
it('should be able to parse AsyncAPI v3 document for parser API v2', async () => { | ||
const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {apiVersion: 'v2'}}); | ||
|
||
expect(parsedDocument).toBeDefined(); | ||
expect(parsedDocument.document.version()).toEqual('3.0.0'); | ||
}); | ||
}); | ||
}); |