-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
7924134
commit 833dbce
Showing
7 changed files
with
139 additions
and
20 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
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,96 @@ | ||
import { AsyncAPIDocumentV2 } from '../../src/models'; | ||
import { Parser } from '../../src/parser'; | ||
import { parse } from '../../src/parse'; | ||
import { xParserOriginalPayload } from '../../src/constants'; | ||
|
||
describe('custom operations - parse schemas', function() { | ||
const parser = new Parser(); | ||
|
||
it('should parse valid schema format', async function() { | ||
const document = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0', | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const { parsed, diagnostics } = await parse(parser, document); | ||
|
||
expect(parsed).toBeInstanceOf(AsyncAPIDocumentV2); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
|
||
expect(parsed?.json()['channels']['channel']['publish']['message']['payload']).toEqual({ type: 'object' }); | ||
expect(parsed?.json()['channels']['channel']['publish']['message'][xParserOriginalPayload]).toEqual({ type: 'object' }); | ||
expect(parsed?.json()['channels']['channel']['publish']['message']['payload']).toEqual(parsed?.json()['channels']['channel']['publish']['message'][xParserOriginalPayload]); | ||
}); | ||
|
||
it('should parse valid default schema format', async function() { | ||
const document = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const { parsed, diagnostics } = await parse(parser, document); | ||
|
||
expect(parsed).toBeInstanceOf(AsyncAPIDocumentV2); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
|
||
expect(parsed?.json()['channels']['channel']['publish']['message']['payload']).toEqual({ type: 'object' }); | ||
expect(parsed?.json()['channels']['channel']['publish']['message'][xParserOriginalPayload]).toEqual({ type: 'object' }); | ||
expect(parsed?.json()['channels']['channel']['publish']['message']['payload']).toEqual(parsed?.json()['channels']['channel']['publish']['message'][xParserOriginalPayload]); | ||
}); | ||
|
||
it('should parse invalid schema format', async function() { | ||
const document = { | ||
asyncapi: '2.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
channel: { | ||
publish: { | ||
operationId: 'operationId', | ||
message: { | ||
schemaFormat: 'not existing', | ||
payload: { | ||
type: 'object', | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
const { parsed, diagnostics } = await parse(parser, document); | ||
|
||
expect(parsed).toBeUndefined(); | ||
expect(diagnostics.length > 0).toEqual(true); | ||
}); | ||
}); |
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