-
Notifications
You must be signed in to change notification settings - Fork 7
Add optional seedItemIds to trackRecommendationClick #256
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 |
|---|---|---|
|
|
@@ -2785,7 +2785,8 @@ describe('ConstructorIO - Tracker', () => { | |
|
|
||
| expect(tracker.trackSearchResultsLoaded(term, { | ||
| ...requiredParameters, | ||
| ...optionalParameters }, userParameters)).to.equal(true); | ||
| ...optionalParameters, | ||
| }, userParameters)).to.equal(true); | ||
| }); | ||
|
|
||
| it('Should respond with a valid response when term, required parameters and user identifier are provided', (done) => { | ||
|
|
@@ -4398,10 +4399,12 @@ describe('ConstructorIO - Tracker', () => { | |
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
| const fullParameters = { ...requiredParameters, | ||
| const fullParameters = { | ||
| ...requiredParameters, | ||
| type: 'add_to_loves', | ||
| displayName: 'Add To Loves List', | ||
| isCustomType: true }; | ||
| isCustomType: true, | ||
| }; | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
@@ -4457,9 +4460,11 @@ describe('ConstructorIO - Tracker', () => { | |
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
| const fullParameters = { ...requiredParameters, | ||
| const fullParameters = { | ||
| ...requiredParameters, | ||
| display_name: 'Add To Loves List', | ||
| is_custom_type: true }; | ||
| is_custom_type: true, | ||
| }; | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
@@ -4525,9 +4530,11 @@ describe('ConstructorIO - Tracker', () => { | |
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
| const fullParameters = { ...requiredParameters, | ||
| const fullParameters = { | ||
| ...requiredParameters, | ||
| type: 'add_to_loves', | ||
| is_custom_type: true }; | ||
| is_custom_type: true, | ||
| }; | ||
|
|
||
| tracker.on('error', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
@@ -4694,7 +4701,7 @@ describe('ConstructorIO - Tracker', () => { | |
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| try { | ||
| // Request | ||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.have.property('key'); | ||
| expect(requestParams).to.have.property('i'); | ||
|
|
@@ -4729,7 +4736,7 @@ describe('ConstructorIO - Tracker', () => { | |
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| try { | ||
| // Request | ||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.have.property('key'); | ||
| expect(requestParams).to.have.property('i'); | ||
|
|
@@ -5772,6 +5779,98 @@ describe('ConstructorIO - Tracker', () => { | |
|
|
||
| expect(tracker.trackRecommendationView(requiredParameters, { ...userParameters, userId })).to.equal(true); | ||
| }); | ||
|
|
||
| it('Should return valid response and omit seed_item_ids if no seedItemIds provided', (done) => { | ||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.not.have.property('seed_item_ids'); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationView(requiredParameters, userParameters)).to.equal(true); | ||
| }); | ||
| it('Should return valid response with seed_item_ids if seedItemIds is an array', (done) => { | ||
| const seedItemIds = ['123', '456']; | ||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(seedItemIds); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationView({ ...requiredParameters, seedItemIds }, userParameters)).to.equal(true); | ||
| }); | ||
| it('Should return valid response with seed_item_ids if seedItemIds is a string', (done) => { | ||
| const seedItemIds = '123'; | ||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.have.property('seed_item_ids').to.deep.equal([seedItemIds]); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationView({ ...requiredParameters, seedItemIds }, userParameters)).to.equal(true); | ||
| }); | ||
| it('Should return valid response and omit seed_item_ids if seedItemIds is not string or array', (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. Important Issue: Missing test coverage for an edge case: an empty array ( |
||
| const seedItemIds = { seedItemIds: ['123', '456'] }; | ||
|
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: The variable name |
||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.not.have.property('seed_item_ids'); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationView({ ...requiredParameters, seedItemIds }, userParameters)).to.equal(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('trackRecommendationClick', () => { | ||
|
|
@@ -6341,6 +6440,98 @@ describe('ConstructorIO - Tracker', () => { | |
|
|
||
| expect(tracker.trackRecommendationClick(requiredParameters, { ...userParameters, userId })).to.equal(true); | ||
| }); | ||
|
|
||
| it('Should return valid response and omit seed_item_ids if no seedItemIds provided', (done) => { | ||
|
constructor-claude-bedrock[bot] marked this conversation as resolved.
|
||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.not.have.property('seed_item_ids'); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationClick(requiredParameters, userParameters)).to.equal(true); | ||
| }); | ||
| it('Should return valid response with seed_item_ids if seedItemIds is an array', (done) => { | ||
| const seedItemIds = ['123', '456']; | ||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(seedItemIds); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationClick({ ...requiredParameters, seedItemIds }, userParameters)).to.equal(true); | ||
| }); | ||
| it('Should return valid response with seed_item_ids if seedItemIds is a string', (done) => { | ||
| const seedItemIds = '123'; | ||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.have.property('seed_item_ids').to.deep.equal([seedItemIds]); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationClick({ ...requiredParameters, seedItemIds }, userParameters)).to.equal(true); | ||
| }); | ||
| it('Should return valid response and omit seed_item_ids if seedItemIds is not string or array', (done) => { | ||
| const seedItemIds = { seedItemIds: ['123', '456'] }; | ||
| const { tracker } = new ConstructorIO({ | ||
| apiKey: testApiKey, | ||
| fetch: fetchSpy, | ||
| }); | ||
|
|
||
| tracker.on('success', (responseParams) => { | ||
| const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); | ||
|
|
||
| // Request | ||
| expect(fetchSpy).to.have.been.called; | ||
| expect(requestParams).to.not.have.property('seed_item_ids'); | ||
|
|
||
| // Response | ||
| expect(responseParams).to.have.property('method').to.equal('POST'); | ||
| expect(responseParams).to.have.property('message').to.equal('ok'); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| expect(tracker.trackRecommendationClick({ ...requiredParameters, seedItemIds }, userParameters)).to.equal(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('trackBrowseResultsLoaded', () => { | ||
|
|
@@ -8095,7 +8286,7 @@ describe('ConstructorIO - Tracker', () => { | |
| it('Should throw an error when providing no messageType parameter', () => { | ||
| const { tracker } = new ConstructorIO({ apiKey: testApiKey }); | ||
|
|
||
| expect(tracker.on(null, () => {})).to.be.an('error'); | ||
| expect(tracker.on(null, () => { })).to.be.an('error'); | ||
| }); | ||
|
|
||
| it('Should throw an error when providing an invalid callback parameter', () => { | ||
|
|
||
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.
Suggestion: There is no blank line between the previous
it(...)block's closing});and this newit(...)block. All other adjacentit(...)blocks in this file are separated by a blank line for readability. Add a blank line before each newit(...)block to match the surrounding style (this applies to both thetrackRecommendationViewandtrackRecommendationClicktest suites).