-
-
Notifications
You must be signed in to change notification settings - Fork 303
test: add tests for bindings.js#getQueryParams #1576
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
e2b4f5d
e36c05a
be65fb2
333433d
546a041
3f31e79
f0fbbcc
196311d
024e954
b61121a
ee08acc
e69f4b1
16c0f42
2011e46
6bdaf8f
bda84bc
b89c84d
d1b4adc
5a09394
bb9a194
7d9eb64
73aa16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const path = require('path'); | ||
const { Parser, fromFile } = require('@asyncapi/parser'); | ||
const { getQueryParams } = require('../src/bindings'); | ||
|
||
const parser = new Parser(); | ||
const asyncapi_v3_path = path.resolve(__dirname, './__fixtures__/asyncapi-websocket-query.yml'); | ||
|
||
describe('getQueryParams integration test with AsyncAPI', () => { | ||
let parsedAsyncAPIDocument; | ||
|
||
beforeAll(async () => { | ||
const parseResult = await fromFile(parser, asyncapi_v3_path).parse(); | ||
parsedAsyncAPIDocument = parseResult.document; | ||
}); | ||
|
||
it('should extract query parameters from WebSocket binding with properties', () => { | ||
const channels = parsedAsyncAPIDocument.channels(); | ||
const params = getQueryParams(channels); | ||
|
||
expect(params).not.toBeNull(); | ||
expect(params.get('heartbeat')).toBe('false'); | ||
expect(params.get('top_of_book')).toBe('false'); | ||
expect(params.get('bids')).toBe('true'); | ||
expect(params.get('offers')).toBe(''); | ||
}); | ||
|
||
it('should return null for channel without WebSocket binding', () => { | ||
const channels = parsedAsyncAPIDocument.channels(); | ||
achaljhawar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const filteredChannels = new Map(); | ||
const channelWithoutBinding = channels.get('marketDataV1NoBinding'); | ||
if (channelWithoutBinding) { | ||
filteredChannels.set('marketDataV1NoBinding', channelWithoutBinding); | ||
} | ||
|
||
filteredChannels.isEmpty = function() { return this.size === 0; }; | ||
filteredChannels.all = function() { return this; }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of doing this, and need for mocking how about just using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey, I see you did some updates but you did not answer the question There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, this can be done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome, than please proceed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you check my latest commit I used Map.delete() to implement the fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed the variable names accordingly |
||
|
||
const params = getQueryParams(filteredChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null for empty channels map', () => { | ||
const emptyChannels = new Map(); | ||
emptyChannels.isEmpty = function() { return this.size === 0; }; | ||
emptyChannels.all = function() { return this; }; | ||
|
||
const params = getQueryParams(emptyChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null for channel with empty binding', () => { | ||
const channels = parsedAsyncAPIDocument.channels(); | ||
|
||
const filteredChannels = new Map(); | ||
const emptyChannel = channels.get('emptyChannel'); | ||
if (emptyChannel) { | ||
filteredChannels.set('emptyChannel', emptyChannel); | ||
} | ||
|
||
filteredChannels.isEmpty = function() { return this.size === 0; }; | ||
filteredChannels.all = function() { return this; }; | ||
|
||
const params = getQueryParams(filteredChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null if WebSocket binding exists but has no query parameters', () => { | ||
const channels = parsedAsyncAPIDocument.channels(); | ||
const filteredChannels = new Map(); | ||
const channelWithNoQuery = channels.get('wsBindingNoQuery'); | ||
if (channelWithNoQuery) { | ||
filteredChannels.set('wsBindingNoQuery', channelWithNoQuery); | ||
} | ||
|
||
filteredChannels.isEmpty = function() { return this.size === 0; }; | ||
filteredChannels.all = function() { return this; }; | ||
|
||
const params = getQueryParams(filteredChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null if WebSocket binding query exists but has no properties', () => { | ||
const channels = parsedAsyncAPIDocument.channels(); | ||
const filteredChannels = new Map(); | ||
const channelWithEmptyQuery = channels.get('wsBindingEmptyQuery'); | ||
if (channelWithEmptyQuery) { | ||
filteredChannels.set('wsBindingEmptyQuery', channelWithEmptyQuery); | ||
} | ||
|
||
filteredChannels.isEmpty = function() { return this.size === 0; }; | ||
filteredChannels.all = function() { return this; }; | ||
|
||
const params = getQueryParams(filteredChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null if channel bindings is undefined', () => { | ||
achaljhawar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const filteredChannels = new Map(); | ||
filteredChannels.set('test', { bindings: () => undefined }); | ||
filteredChannels.isEmpty = function() { return this.size === 0; }; | ||
filteredChannels.all = function() { return this; }; | ||
|
||
const params = getQueryParams(filteredChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.