-
Notifications
You must be signed in to change notification settings - Fork 7
[CDX-501] Add support for refined filters as top level URL parameters in browse results #265
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 all commits
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 |
|---|---|---|
|
|
@@ -565,6 +565,59 @@ describe('ConstructorIO - Browse', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('Should send refined filters supplied within the qs param as a top level url parameter', (done) => { | ||
| const qsParam = { refined_filters: { group_id: 'BrandXY' } }; | ||
| const { browse } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| browse.getBrowseResults(filterName, filterValue, { qsParam }).then((res) => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
|
|
||
| expect(res).to.have.property('request').to.be.an('object'); | ||
| expect(requestedUrlParams).to.have.property('refined_filters'); | ||
| expect(requestedUrlParams.refined_filters).to.have.property('group_id').to.equal('BrandXY'); | ||
| expect(requestedUrlParams).to.not.have.property('qs'); | ||
|
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. Suggestion: This assertion verifies that |
||
| expect(res.request.refined_filters).to.deep.equal(qsParam.refined_filters); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should retain the remaining qs param values when sending refined filters as a top level url parameter', (done) => { | ||
| const qsParam = { | ||
| num_results_per_page: '10', | ||
| refined_filters: { group_id: 'BrandXY' }, | ||
| }; | ||
| const { browse } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| browse.getBrowseResults(filterName, filterValue, { qsParam }).then((res) => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
|
|
||
| expect(requestedUrlParams.refined_filters).to.have.property('group_id').to.equal('BrandXY'); | ||
| expect(JSON.parse(requestedUrlParams.qs)).to.deep.equal({ num_results_per_page: '10' }); | ||
| expect(res.request.num_results_per_page).to.equal(10); | ||
| expect(res.request.refined_filters).to.deep.equal(qsParam.refined_filters); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should not mutate the supplied qs param when sending refined filters as a top level url parameter', (done) => { | ||
| const qsParam = { refined_filters: { group_id: 'BrandXY' } }; | ||
| const { browse } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| browse.getBrowseResults(filterName, filterValue, { qsParam }).then(() => { | ||
| expect(qsParam).to.deep.equal({ refined_filters: { group_id: 'BrandXY' } }); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should properly encode path parameters', (done) => { | ||
| const specialCharacters = '+[]&'; | ||
| const filterNameSpecialCharacters = `name ${specialCharacters}`; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important Issue: All three new tests use the callback-style
donepattern without a.catch()handler. If the promise rejects (e.g. network or assertion error),doneis never called and the test silently times out rather than failing with a meaningful error. Add a rejection handler:This matches the pattern already used in the surrounding existing tests in this file.