-
-
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 13 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,89 @@ | ||
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'); | ||
|
||
function createChannelsWithOnly(keysToKeep, originalChannels) { | ||
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. why we need to create a new map here, and still do some mocking basically of 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 are you still working on something? 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. No 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 am done ig 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.
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. ohk I'll fix 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. should I create a second fixture file to fix this problem? 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. let's not decide yet, first answer my question 😄 why new map is needed, why you cannot operate in the helper on the map you get as input 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. The new Map is needed to create a copy so the original channels map isn't mutated, which would affect other tests that need the data. 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. oh, now much better. Remember reviewer did not code and do not see what issues you had during development. Sometimes we just ask question not to play smart, but to really get an answer 😄 thanks for the context - now it makes sense why you've done so, and why later you still do mocking of |
||
const channelsMap = new Map(originalChannels.all()); | ||
for (const key of channelsMap.keys()) { | ||
if (!keysToKeep.includes(key)) { | ||
channelsMap.delete(key); | ||
} | ||
} | ||
return { | ||
isEmpty: () => channelsMap.size === 0, | ||
all: () => channelsMap | ||
}; | ||
} | ||
|
||
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 = createChannelsWithOnly(['marketDataV1NoBinding'], channels); | ||
const params = getQueryParams(filteredChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null for empty channels map', () => { | ||
const emptyChannels = { | ||
isEmpty: () => true, | ||
all: () => new Map() | ||
}; | ||
const params = getQueryParams(emptyChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
|
||
it('should return null for channel with empty binding', () => { | ||
const channels = parsedAsyncAPIDocument.channels(); | ||
const filteredChannels = createChannelsWithOnly(['emptyChannel'], channels); | ||
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 = createChannelsWithOnly(['wsBindingNoQuery'], channels); | ||
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 = createChannelsWithOnly(['wsBindingEmptyQuery'], channels); | ||
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 channelsMap = new Map(); | ||
channelsMap.set('test', { bindings: () => undefined }); | ||
|
||
const testChannels = { | ||
isEmpty: () => channelsMap.size === 0, | ||
all: () => channelsMap | ||
}; | ||
|
||
const params = getQueryParams(testChannels); | ||
expect(params).toBeNull(); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.