-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
563a547
commit 59a2ace
Showing
10 changed files
with
103 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
public | ||
docs | ||
lib | ||
dist | ||
build |
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
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
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
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,60 @@ | ||
import { ConvertService } from '../convert.service'; | ||
import { ProblemException } from '../../exceptions/problem.exception'; | ||
|
||
const validJsonAsyncAPI2_0_0 = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Super test', | ||
version: '1.0.0' | ||
}, | ||
channels: {} | ||
}; | ||
|
||
const validYamlAsyncAPI2_3_0 = ` | ||
asyncapi: 2.3.0 | ||
info: | ||
title: Super test | ||
version: 1.0.0 | ||
channels: {} | ||
`; | ||
|
||
describe('ConvertService', () => { | ||
const convertService = new ConvertService(); | ||
|
||
describe('.convert()', () => { | ||
it('should throw error that the converter cannot convert to a lower version', async () => { | ||
let err: ProblemException; | ||
try { | ||
await convertService.convert(validJsonAsyncAPI2_0_0, '1.2.0'); | ||
} catch (e) { | ||
err = e; | ||
} | ||
|
||
expect(err).toEqual(new ProblemException({ | ||
type: 'internal-converter-error', | ||
title: 'Could not convert document', | ||
status: 422, | ||
detail: 'Cannot downgrade from 2.0.0 to 1.2.0.', | ||
})); | ||
}); | ||
|
||
it('should pass when converting to 2.3.0 version', async () => { | ||
const converted = await convertService.convert(validJsonAsyncAPI2_0_0, '2.3.0'); | ||
|
||
expect(converted).toEqual({ | ||
asyncapi: '2.3.0', | ||
info: { | ||
title: 'Super test', | ||
version: '1.0.0' | ||
}, | ||
channels: {}, | ||
}); | ||
}); | ||
|
||
it('should correctly convert JSON to YAML', async () => { | ||
const converted = await convertService.convert(validJsonAsyncAPI2_0_0, '2.3.0', 'yaml'); | ||
|
||
expect(converted).toEqual(validYamlAsyncAPI2_3_0.trimStart()); | ||
}); | ||
}); | ||
}); |