-
Notifications
You must be signed in to change notification settings - Fork 14
[CDX-201] Tracking other related parameters #459
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 |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
| "testdata", | ||
| "Bytespider", | ||
| "Timespans", | ||
| "googlequicksearchbox" | ||
| "googlequicksearchbox", | ||
| "cnstrc" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,88 @@ describe(`ConstructorIO - Search${bundledDescriptionSuffix}`, () => { | |
| }); | ||
| }); | ||
|
|
||
| it('Should include window global userId when trackWindowParameters is true and options.userId is absent', (done) => { | ||
| window.cnstrc = { userId: 'window-user-id' }; | ||
| const { search } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| trackWindowParameters: true, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| search.getSearchResults(query, { section }).then(() => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
| expect(requestedUrlParams).to.have.property('ui').to.equal('window-user-id'); | ||
| delete window.cnstrc; | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should include window global testCells when trackWindowParameters is true and options.testCells is absent', (done) => { | ||
| window.cnstrc = { testCells: { experiment: 'variation_a' } }; | ||
| const { search } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| trackWindowParameters: true, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| search.getSearchResults(query, { section }).then(() => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
| expect(requestedUrlParams).to.have.property('ef-experiment').to.equal('variation_a'); | ||
| delete window.cnstrc; | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should include window global userSegments when trackWindowParameters is true and options.segments is absent', (done) => { | ||
| window.cnstrc = { userSegments: ['vip', 'beta'] }; | ||
| const { search } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| trackWindowParameters: true, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| search.getSearchResults(query, { section }).then(() => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
| expect(requestedUrlParams).to.have.property('us').to.deep.equal(['vip', 'beta']); | ||
| delete window.cnstrc; | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should prefer options.userId over window global when trackWindowParameters is true', (done) => { | ||
| window.cnstrc = { userId: 'window-user-id' }; | ||
| const { search } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| userId: 'options-user-id', | ||
| trackWindowParameters: true, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| search.getSearchResults(query, { section }).then(() => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
| expect(requestedUrlParams).to.have.property('ui').to.equal('options-user-id'); | ||
| delete window.cnstrc; | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should not include window globals when trackWindowParameters is false', (done) => { | ||
| window.cnstrc = { userId: 'window-user-id', testCells: { exp: 'var' }, userSegments: ['seg'] }; | ||
|
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: Several test cases set Consider using afterEach(() => { delete window.cnstrc; });This pattern appears in all four module test files ( |
||
| const { search } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| search.getSearchResults(query, { section }).then(() => { | ||
| const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); | ||
| expect(requestedUrlParams).to.not.have.property('ui'); | ||
| expect(requestedUrlParams).to.not.have.property('ef-exp'); | ||
| expect(requestedUrlParams).to.not.have.property('us'); | ||
| delete window.cnstrc; | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('Should return a response with a valid query, section, and offset', (done) => { | ||
| const offset = 1; | ||
| const { search } = new ConstructorIO({ | ||
|
|
||
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.
Several tests set
window.cnstrcand clean it up withdelete window.cnstrcinside the.then()callback. If an assertion throws first (or the promise rejects), the global leaks into subsequent tests. Can we move cleanup toafterEach?