From a078ef139812413a40876ed2428f8345998fbb5a Mon Sep 17 00:00:00 2001 From: Enes Kutay SEZEN Date: Mon, 24 Mar 2025 23:39:41 +0300 Subject: [PATCH 1/2] Update tests --- spec/src/modules/tracker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index fb07f20b..c58bb31d 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -693,7 +693,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; const optionalParameters = { tr: 'click', - groupId: 'All', + groupId: 'all', displayName: 'display-name', itemId: '12345', }; @@ -756,7 +756,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { original_query: 'original-query', section: 'Search Suggestions', tr: 'click', - group_id: 'All', + group_id: 'all', display_name: 'display-name', variation_id: '12345-A', item_id: '12345', @@ -3550,7 +3550,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // Response expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('conversion type must be one of add_to_wishlist, add_to_cart, like, message, make_offer, read. If you wish to use custom types, please set is_custom_type to true and specify a display_name.'); + expect(responseParams).to.have.property('message').to.equal('Invalid parameters'); done(); }); From 20dc643df4774d2a8b4603bb42a95d2a8b09cad7 Mon Sep 17 00:00:00 2001 From: Enes Kutay SEZEN Date: Tue, 8 Apr 2025 21:51:21 +0300 Subject: [PATCH 2/2] Remove beaconMode tests --- spec/src/modules/tracker.js | 239 ------------------------------------ 1 file changed, 239 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index c58bb31d..86237f84 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -4035,106 +4035,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase()).to.be.an('error'); }); - it('Should respond with a success if beacon=true and a non-existent item_id is provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - }); - - tracker.on('success', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('beacon').to.equal(true); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - expect(tracker.trackPurchase({ - ...requiredParameters, - items: [ - { - itemId: 'bad-item-id-10', - variationId: '456', - }, - { - itemId: 'bad-item-id-11', - }, - ], - })).to.equal(true); - }); - - it('Should respond with an error if beacon=true is not in the request and a non-existent item_id is provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - beaconMode: false, - }); - - tracker.on('error', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('beacon'); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="bad-item-id-10".'); - - done(); - }); - - expect(tracker.trackPurchase({ - ...requiredParameters, - items: [ - { - itemId: 'bad-item-id-10', - }, - ], - })).to.equal(true); - }); - - it('Should respond with an error if beacon=true is not in the request and a non-existent item_id/variation_id is provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - beaconMode: false, - }); - - tracker.on('error', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('beacon'); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.contain('There is no variation item with variation_id="456".'); - - done(); - }); - - expect(tracker.trackPurchase({ - ...requiredParameters, - items: [ - { - itemId: 'bad-item-id-10', - variationId: '456', - }, - ], - })).to.equal(true); - }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5048,75 +4948,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationClick(Object.assign(requiredParameters, optionalParameters))).to.equal(true); }); - it('Should respond with a success if beacon=true and a non-existent item_id is provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - }); - const parameters = { - ...requiredParameters, - ...optionalParameters, - itemId: 'non-existent-item-id', - }; - - tracker.on('success', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage); - expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage); - expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId); - expect(requestParams).to.have.property('section').to.equal(parameters.section); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - expect(tracker.trackRecommendationClick(parameters)).to.equal(true); - }); - - it('Should respond with an error if beacon=true is not in the request and a non-existent item_id is provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - beaconMode: false, - }); - const parameters = { - ...requiredParameters, - ...optionalParameters, - itemId: 'non-existent-item-id', - }; - - tracker.on('error', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage); - expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage); - expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId); - expect(requestParams).to.have.property('section').to.equal(parameters.section); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="non-existent-item-id"'); - - done(); - }); - - expect(tracker.trackRecommendationClick(parameters)).to.equal(true); - }); - it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); @@ -6316,42 +6147,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(parameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - beaconMode: false, - }); - const parameters = { - ...requiredParameters, - ...optionalParameters, - itemId: 'non-existent-item-id', - }; - - tracker.on('error', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(parameters.section); - expect(requestParams).to.have.property('result_count').to.equal(parameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(parameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(parameters.resultId); - expect(requestParams).to.have.property('result_position_on_page').to.equal(parameters.resultPositionOnPage); - expect(requestParams).to.have.property('num_results_per_page').to.equal(parameters.numResultsPerPage); - expect(requestParams).to.have.property('selected_filters').to.deep.equal(parameters.selectedFilters); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.contain('There is no item with item_id="non-existent-item-id"'); - - done(); - }); - - expect(tracker.trackBrowseResultClick(parameters)).to.equal(true); - }); - it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); @@ -6769,40 +6564,6 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackGenericResultClick(parameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKey, - fetch: fetchSpy, - ...requestQueueOptions, - beaconMode: false, - }); - const parameters = { - ...requiredParameters, - ...optionalParameters, - itemId: 'non-existent-item-id', - }; - - tracker.on('error', (responseParams) => { - const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); - - // Request - expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(parameters.section); - expect(requestParams).to.have.property('item_id').to.equal(parameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(parameters.itemName); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams) - .to.have.property('message') - .to.contain('There is no item with item_id="non-existent-item-id"'); - - done(); - }); - - expect(tracker.trackGenericResultClick(parameters)).to.equal(true); - }); - it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey });