From c3b4817770a174f112ec2fc869c9a0d094451872 Mon Sep 17 00:00:00 2001 From: vishnu Date: Tue, 4 Aug 2026 19:40:29 +0530 Subject: [PATCH 1/3] add thread id to tracking for asa --- spec/src/modules/tracker.js | 12 ++++++++++++ src/modules/tracker.js | 36 ++++++++++++++++++++++++++++++++++++ src/types/tracker.d.ts | 6 ++++++ 3 files changed, 54 insertions(+) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 2986fc51..3ad9ae35 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -9835,6 +9835,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const requiredParameters = { intent: 'Show me cookie recipes' }; const optionalParameters = { section: 'Products', + threadId: 'thread-123', }; it('Should respond with a valid response when intent and required parameters are provided', (done) => { @@ -9983,6 +9984,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // Request expect(fetchSpy).to.have.been.called; expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -10150,6 +10152,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const optionalParameters = { section: 'Products', intentResultId: '123451', + threadId: 'thread-123', }; it('Should respond with a valid response when term and required parameters are provided', (done) => { @@ -10299,6 +10302,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(fetchSpy).to.have.been.called; expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -10467,6 +10471,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const optionalParameters = { section: 'Products', intentResultId: '123451', + threadId: 'thread-123', }; it('Should respond with a valid response when term and required parameters are provided', (done) => { @@ -10617,6 +10622,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(fetchSpy).to.have.been.called; expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -10791,6 +10797,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { section: 'Products', intentResultId: '12312', variationId: '123123', + threadId: 'thread-123', }; it('Should respond with a valid response when required parameters are provided', (done) => { @@ -10944,6 +10951,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -11116,6 +11124,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const optionalParameters = { intentResultId: 'result-id', section: 'Products', + threadId: 'thread-123', items: [ { itemId: '123', @@ -11288,6 +11297,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response expect(responseParams).to.have.property('method').to.equal('POST'); @@ -11455,6 +11465,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const optionalParameters = { section: 'Products', intentResultId: '1234', + threadId: 'thread-123', }; it('Should respond with a valid response when term and required parameters are provided', (done) => { @@ -11606,6 +11617,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(fetchSpy).to.have.been.called; expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response expect(responseParams).to.have.property('method').to.equal('POST'); diff --git a/src/modules/tracker.js b/src/modules/tracker.js index 4b89ebee..07a4e008 100644 --- a/src/modules/tracker.js +++ b/src/modules/tracker.js @@ -2737,6 +2737,7 @@ class Tracker { * @param {object} parameters - Additional parameters to be sent with request * @param {string} parameters.intent - Intent of user request * @param {string} [parameters.section] - The section name for the item Ex. "Products" + * @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} @@ -2756,12 +2757,17 @@ class Tracker { const { section, intent, + threadId, } = parameters; const bodyParams = { intent, section, }; + if (threadId) { + bodyParams.thread_id = threadId; + } + const requestURL = `${baseUrl}${applyParamsAsString({}, this.options)}`; const requestMethod = 'POST'; const requestBody = applyParams(bodyParams, { @@ -2791,6 +2797,7 @@ class Tracker { * @param {string} parameters.intent - Intent of user request * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {string} [parameters.intentResultId] - The intent result id from the ASA response + * @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} @@ -2811,6 +2818,7 @@ class Tracker { section, intentResultId, intent, + threadId, } = parameters; const bodyParams = { intent_result_id: intentResultId, @@ -2818,6 +2826,10 @@ class Tracker { section, }; + if (threadId) { + bodyParams.thread_id = threadId; + } + const requestURL = `${baseUrl}${applyParamsAsString({}, this.options)}`; const requestMethod = 'POST'; const requestBody = applyParams(bodyParams, { @@ -2848,6 +2860,7 @@ class Tracker { * @param {number} parameters.searchResultCount - Number of search results loaded * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {string} [parameters.intentResultId] - The intent result id from the ASA response + * @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} @@ -2870,6 +2883,7 @@ class Tracker { searchResultCount, intentResultId, intent, + threadId, } = parameters; const bodyParams = { intent_result_id: intentResultId, @@ -2878,6 +2892,10 @@ class Tracker { search_result_count: searchResultCount, }; + if (threadId) { + bodyParams.thread_id = threadId; + } + const requestURL = `${baseUrl}${applyParamsAsString({}, this.options)}`; const requestMethod = 'POST'; const requestBody = applyParams(bodyParams, { @@ -2911,6 +2929,7 @@ class Tracker { * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {string} [parameters.variationId] - Product item variation unique identifier * @param {string} [parameters.intentResultId] - Browse result identifier (returned in response from Constructor) + * @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} @@ -2938,6 +2957,7 @@ class Tracker { itemId, itemName, intent, + threadId, } = parameters; const bodyParams = { @@ -2950,6 +2970,10 @@ class Tracker { intent, }; + if (threadId) { + bodyParams.thread_id = threadId; + } + const requestURL = `${requestPath}${applyParamsAsString({}, this.options)}`; const requestMethod = 'POST'; const requestBody = applyParams(bodyParams, { ...this.options, requestMethod }); @@ -2981,6 +3005,7 @@ class Tracker { * @param {object[]} [parameters.items] - List of product item objects viewed * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {string} [parameters.intentResultId] - Browse result identifier (returned in response from Constructor) + * @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} @@ -3007,6 +3032,7 @@ class Tracker { intentResultId, searchResultId, intent, + threadId, } = parameters; const bodyParams = { @@ -3018,6 +3044,10 @@ class Tracker { intent, }; + if (threadId) { + bodyParams.thread_id = threadId; + } + const requestURL = `${requestPath}${applyParamsAsString({}, this.options)}`; const requestMethod = 'POST'; const requestBody = applyParams(bodyParams, { ...this.options, requestMethod }); @@ -3048,6 +3078,7 @@ class Tracker { * @param {string} parameters.searchResultId - resultId of search result the clicked item belongs to * @param {string} [parameters.section] - The section name for the item Ex. "Products" * @param {string} [parameters.intentResultId] - intentResultId from the ASA response + * @param {string} [parameters.threadId] - Thread ID for grouping events within a conversation * @param {object} [networkParameters] - Parameters relevant to the network request * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds) * @returns {(true|Error)} @@ -3073,6 +3104,7 @@ class Tracker { searchTerm, searchResultId, intentResultId, + threadId, } = parameters; const bodyParams = { @@ -3083,6 +3115,10 @@ class Tracker { intent_result_id: intentResultId, }; + if (threadId) { + bodyParams.thread_id = threadId; + } + const requestURL = `${baseUrl}${applyParamsAsString({}, this.options)}`; const requestMethod = 'POST'; const requestBody = applyParams(bodyParams, { diff --git a/src/types/tracker.d.ts b/src/types/tracker.d.ts index 5ee850a9..a9554b47 100644 --- a/src/types/tracker.d.ts +++ b/src/types/tracker.d.ts @@ -283,6 +283,7 @@ declare class Tracker { parameters: { intent: string; section?: string; + threadId?: string; }, networkParameters?: NetworkParameters ): true | Error; @@ -292,6 +293,7 @@ declare class Tracker { intent: string; section?: string; intentResultId?: string; + threadId?: string; }, networkParameters?: NetworkParameters ): true | Error; @@ -302,6 +304,7 @@ declare class Tracker { searchResultCount: number; section?: string; intentResultId?: string; + threadId?: string; }, networkParameters?: NetworkParameters ): true | Error; @@ -315,6 +318,7 @@ declare class Tracker { variationId?: string; section?: string; intentResultId?: string; + threadId?: string; }, networkParameters?: NetworkParameters ): true | Error; @@ -327,6 +331,7 @@ declare class Tracker { items?: ItemTracked[]; intentResultId?: string; section?: string; + threadId?: string; }, networkParameters?: NetworkParameters ): true | Error; @@ -340,6 +345,7 @@ declare class Tracker { groupId?: string; section?: string; intentResultId?: string; + threadId?: string; }, networkParameters?: NetworkParameters ): true | Error; From cc85e2aec4000dec562bb26c52b6dc2caa859907 Mon Sep 17 00:00:00 2001 From: vishnu Date: Tue, 11 Aug 2026 18:06:00 +0530 Subject: [PATCH 2/3] commit to run workflow --- spec/src/modules/tracker.js | 12302 ++++++++++++++++++++-------------- 1 file changed, 7294 insertions(+), 5008 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 3ad9ae35..2578a94e 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -1,16 +1,16 @@ /* eslint-disable no-unused-expressions, import/no-unresolved */ -const dotenv = require('dotenv'); -const chai = require('chai'); -const chaiAsPromised = require('chai-as-promised'); -const sinon = require('sinon'); -const sinonChai = require('sinon-chai'); -const cloneDeep = require('lodash.clonedeep'); -const store = require('../../../test/utils/store'); // eslint-disable-line import/extensions -const helpers = require('../../mocha.helpers'); -const clientHelpers = require('../../../src/utils/helpers'); -const jsdom = require('../utils/jsdom-global'); -const { addOrderIdRecord } = require('../../../src/utils/helpers'); -let ConstructorIO = require('../../../test/constructorio'); // eslint-disable-line import/extensions +const dotenv = require("dotenv"); +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); +const sinon = require("sinon"); +const sinonChai = require("sinon-chai"); +const cloneDeep = require("lodash.clonedeep"); +const store = require("../../../test/utils/store"); // eslint-disable-line import/extensions +const helpers = require("../../mocha.helpers"); +const clientHelpers = require("../../../src/utils/helpers"); +const jsdom = require("../utils/jsdom-global"); +const { addOrderIdRecord } = require("../../../src/utils/helpers"); +let ConstructorIO = require("../../../test/constructorio"); // eslint-disable-line import/extensions chai.use(chaiAsPromised); chai.use(sinonChai); @@ -18,29 +18,39 @@ dotenv.config(); const testApiKey = process.env.TEST_REQUEST_API_KEY; const testApiKeyWithAdPlacements = process.env.TEST_MEDIA_REQUEST_API_KEY; -const clientVersion = 'cio-mocha'; +const clientVersion = "cio-mocha"; const delayBetweenTests = 50; -const bundled = process.env.BUNDLED === 'true'; -const skipNetworkTimeoutTests = process.env.SKIP_NETWORK_TIMEOUT_TESTS === 'true'; -const bundledDescriptionSuffix = bundled ? ' - Bundled' : ''; -const timeoutRejectionMessage = 'AbortError: This operation was aborted'; -const testAnalyticsTag = { param1: 'test', param2: 'test2' }; -const utmParameters = 'utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1'; +const bundled = process.env.BUNDLED === "true"; +const skipNetworkTimeoutTests = + process.env.SKIP_NETWORK_TIMEOUT_TESTS === "true"; +const bundledDescriptionSuffix = bundled ? " - Bundled" : ""; +const timeoutRejectionMessage = "AbortError: This operation was aborted"; +const testAnalyticsTag = { param1: "test", param2: "test2" }; +const utmParameters = + "utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1"; const url = `http://localhost.test/path/name?query=term&category=cat&${utmParameters}`; -const referrer = 'https://www.google.com/'; -const canonicalUrl = 'https://localhost/'; -const testPlacementId = 'home'; +const referrer = "https://www.google.com/"; +const canonicalUrl = "https://localhost/"; +const testPlacementId = "home"; function validateOriginReferrer(requestParams) { - expect(requestParams).to.have.property('origin_referrer').to.contain('localhost.test/path/name'); - expect(requestParams).to.have.property('origin_referrer').to.contain('utm_source=attentive'); - expect(requestParams).to.have.property('origin_referrer').to.contain('utm_medium=sms'); - expect(requestParams).to.have.property('origin_referrer').to.contain('utm_campaign=campaign_1'); + expect(requestParams) + .to.have.property("origin_referrer") + .to.contain("localhost.test/path/name"); + expect(requestParams) + .to.have.property("origin_referrer") + .to.contain("utm_source=attentive"); + expect(requestParams) + .to.have.property("origin_referrer") + .to.contain("utm_medium=sms"); + expect(requestParams) + .to.have.property("origin_referrer") + .to.contain("utm_campaign=campaign_1"); } function createLongUrl(length) { - const baseUrl = 'https://constructor.io/product/KMH876?a='; - return `${baseUrl}${'a'.repeat(length - baseUrl.length)}`; + const baseUrl = "https://constructor.io/product/KMH876?a="; + return `${baseUrl}${"a".repeat(length - baseUrl.length)}`; } describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { @@ -55,7 +65,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { beforeEach(() => { cleanup = jsdom(jsdomOptions); helpers.clearStorage(); - store.session.set('_constructorio_is_human', true); + store.session.set("_constructorio_is_human", true); fetchSpy = sinon.spy(fetch); global.CLIENT_VERSION = clientVersion; @@ -64,7 +74,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { if (bundled) { // store2 doesn't seem to maintain the `window` context for bundled version - set manually window.sessionStorage.clear(); - window.sessionStorage.setItem('_constructorio_is_human', true); + window.sessionStorage.setItem("_constructorio_is_human", true); ConstructorIO = window.ConstructorioClient; } @@ -81,29 +91,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { setTimeout(done, delayBetweenTests); }); - describe('trackSessionStart', () => { - it('V2 Should respond with a valid response', (done) => { + describe("trackSessionStart", () => { + it("V2 Should respond with a valid response", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -111,29 +121,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStartV2()).to.equal(true); }); - it('Should respond with a valid response', (done) => { + it("Should respond with a valid response", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('action').to.equal('session_start'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams) + .to.have.property("action") + .to.equal("session_start"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -141,8 +153,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should respond with a valid response with segments', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response with segments", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -150,16 +162,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -167,8 +179,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should respond with a valid response with userId', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response with userId", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -176,16 +188,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -193,24 +205,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -218,14 +234,14 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is not defined', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is not defined", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -233,8 +249,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -242,7 +258,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -250,7 +266,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -258,8 +274,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -267,7 +283,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -275,16 +291,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -292,8 +308,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should respond with a valid response with testCells', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response with testCells", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -301,16 +317,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -318,11 +336,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should respond with a valid response with multiple testCells', (done) => { + it("Should respond with a valid response with multiple testCells", (done) => { const testCells = { - foo: 'bar', - bar: 'foo', - far: 'boo', + foo: "bar", + bar: "foo", + far: "boo", }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -331,18 +349,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[1]}`).to.equal(Object.values(testCells)[1]); - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[2]}`).to.equal(Object.values(testCells)[2]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[1]}`) + .to.equal(Object.values(testCells)[1]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[2]}`) + .to.equal(Object.values(testCells)[2]); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -350,8 +374,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should only include valid string testCells in request params', (done) => { - const testCells = { valid: 'bar', invalid: null, numVal: 123 }; + it("Should only include valid string testCells in request params", (done) => { + const testCells = { valid: "bar", invalid: null, numVal: 123 }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -359,13 +383,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ef-valid').to.equal('bar'); - expect(requestParams).to.not.have.property('ef-invalid'); - expect(requestParams).to.not.have.property('ef-numVal'); + expect(requestParams).to.have.property("ef-valid").to.equal("bar"); + expect(requestParams).to.not.have.property("ef-invalid"); + expect(requestParams).to.not.have.property("ef-numVal"); done(); }); @@ -374,13 +398,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -388,7 +412,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart({ timeout: 10 })).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -397,7 +421,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -406,8 +430,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -416,16 +440,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -433,10 +457,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const nonBreakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const nonBreakingSpaces = "   "; const userId = `user-id ${nonBreakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -444,16 +468,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -461,8 +485,12 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should include window globals in tracking requests when useWindowParameters is true', (done) => { - window.cnstrc = { userId: 'window-user-id', testCells: { exp: 'var' }, userSegments: ['seg1', 'seg2'] }; + it("Should include window globals in tracking requests when useWindowParameters is true", (done) => { + window.cnstrc = { + userId: "window-user-id", + testCells: { exp: "var" }, + userSegments: ["seg1", "seg2"], + }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, useWindowParameters: true, @@ -470,12 +498,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { try { - const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(requestedUrlParams).to.have.property('ui').to.equal('window-user-id'); - expect(requestedUrlParams).to.have.property('ef-exp').to.equal('var'); - expect(requestedUrlParams).to.have.property('us').to.deep.equal(['seg1', 'seg2']); + const requestedUrlParams = + helpers.extractUrlParamsFromFetch(fetchSpy); + expect(requestedUrlParams) + .to.have.property("ui") + .to.equal("window-user-id"); + expect(requestedUrlParams).to.have.property("ef-exp").to.equal("var"); + expect(requestedUrlParams) + .to.have.property("us") + .to.deep.equal(["seg1", "seg2"]); done(); } catch (e) { done(e); @@ -485,8 +518,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it('Should prefer options.userId over window global in tracking requests when useWindowParameters is true', (done) => { - window.cnstrc = { userId: 'window-user-id' }; + it("Should prefer options.userId over window global in tracking requests when useWindowParameters is true", (done) => { + window.cnstrc = { userId: "window-user-id" }; const instance = new ConstructorIO({ apiKey: testApiKey, useWindowParameters: true, @@ -494,11 +527,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - instance.setClientOptions({ userId: 'explicit-user-id' }); + instance.setClientOptions({ userId: "explicit-user-id" }); - instance.tracker.on('success', () => { + instance.tracker.on("success", () => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(requestedUrlParams).to.have.property('ui').to.equal('explicit-user-id'); + expect(requestedUrlParams) + .to.have.property("ui") + .to.equal("explicit-user-id"); done(); }); @@ -506,67 +541,73 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackInputFocus', () => { - it('V2 Should respond with a valid response', (done) => { + describe("trackInputFocus", () => { + it("V2 Should respond with a valid response", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const userInput = 'Test User Input'; + const userInput = "Test User Input"; const parameters = { analyticsTags: testAnalyticsTag, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('user_input').to.equal(userInput); - expect(bodyParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(bodyParams).to.have.property("user_input").to.equal(userInput); + expect(bodyParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); expect(tracker.trackInputFocusV2(userInput, parameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -574,29 +615,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should respond with a valid response', (done) => { + it("Should respond with a valid response", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('action').to.equal('focus'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("action").to.equal("focus"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -604,8 +645,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should respond with a valid response with segments', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response with segments", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -613,16 +654,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -630,8 +671,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should respond with a valid response with userId', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response with userId", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -639,16 +680,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -656,7 +697,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -664,7 +705,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -672,8 +713,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -681,7 +722,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -689,16 +730,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).not.to.have.property('origin_referrer'); + expect(requestParams).not.to.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -706,8 +747,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should respond with a valid response with testCells', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response with testCells", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -715,16 +756,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -733,13 +776,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -747,7 +790,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus({ timeout: 10 })).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -756,7 +799,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -765,8 +808,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -775,16 +818,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -792,10 +835,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -803,16 +846,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -821,202 +864,256 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAutocompleteSelect', () => { - const term = 'Where The Wild Things Are'; + describe("trackAutocompleteSelect", () => { + const term = "Where The Wild Things Are"; const requiredParameters = { - originalQuery: 'original-query', - section: 'Search Suggestions', + originalQuery: "original-query", + section: "Search Suggestions", }; const optionalParameters = { - tr: 'click', - groupId: 'all', - displayName: 'display-name', - itemId: '12345', - slCampaignOwner: 'Campaign Man', - slCampaignId: 'Campaign 123', + tr: "click", + groupId: "all", + displayName: "display-name", + itemId: "12345", + slCampaignOwner: "Campaign Man", + slCampaignId: "Campaign 123", }; const v2Parameters = { - variationId: '12345-A', + variationId: "12345-A", }; - it('V2 Should respond with a valid response when term and required parameters are provided', (done) => { + it("V2 Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('section').to.equal(requiredParameters.section); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("section") + .to.equal(requiredParameters.section); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('user_input').to.equal(requiredParameters.originalQuery); - expect(bodyParams).to.have.property('tr').to.equal(optionalParameters.tr); - expect(bodyParams).to.have.property('item_id').to.equal(optionalParameters.itemId); - expect(bodyParams).to.have.property('variation_id').to.equal(v2Parameters.variationId); - expect(bodyParams).to.have.property('section').to.deep.equal(requiredParameters.section); - expect(bodyParams).to.have.property('item_name').to.equal(term); - expect(bodyParams).to.have.property('group_id').to.equal(optionalParameters.groupId); - expect(bodyParams).to.have.property('sl_campaign_id').to.equal(optionalParameters.slCampaignId); - expect(bodyParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - tracker.on('error', (error) => { + expect(bodyParams) + .to.have.property("user_input") + .to.equal(requiredParameters.originalQuery); + expect(bodyParams) + .to.have.property("tr") + .to.equal(optionalParameters.tr); + expect(bodyParams) + .to.have.property("item_id") + .to.equal(optionalParameters.itemId); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(v2Parameters.variationId); + expect(bodyParams) + .to.have.property("section") + .to.deep.equal(requiredParameters.section); + expect(bodyParams).to.have.property("item_name").to.equal(term); + expect(bodyParams) + .to.have.property("group_id") + .to.equal(optionalParameters.groupId); + expect(bodyParams) + .to.have.property("sl_campaign_id") + .to.equal(optionalParameters.slCampaignId); + expect(bodyParams) + .to.have.property("sl_campaign_owner") + .to.deep.equal(optionalParameters.slCampaignOwner); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); + + done(); + }); + + tracker.on("error", (error) => { done(error); }); // eslint-disable-next-line max-len - expect(tracker.trackAutocompleteSelectV2(term, { ...requiredParameters, ...optionalParameters, ...v2Parameters })).to.equal(true); + expect( + tracker.trackAutocompleteSelectV2(term, { + ...requiredParameters, + ...optionalParameters, + ...v2Parameters, + }), + ).to.equal(true); }); - it('Backwards Compatibility - V2 Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - V2 Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: 'original-query', - section: 'Search Suggestions', - tr: 'click', - group_id: 'all', - display_name: 'display-name', - variation_id: '12345-A', - item_id: '12345', + original_query: "original-query", + section: "Search Suggestions", + tr: "click", + group_id: "all", + display_name: "display-name", + variation_id: "12345-A", + item_id: "12345", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('section').to.equal(requiredParameters.section); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("section") + .to.equal(requiredParameters.section); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('user_input').to.equal(snakeCaseParameters.original_query); - expect(bodyParams).to.have.property('tr').to.equal(optionalParameters.tr); - expect(bodyParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); - expect(bodyParams).to.have.property('variation_id').to.equal(snakeCaseParameters.variation_id); - expect(bodyParams).to.have.property('section').to.deep.equal(snakeCaseParameters.section); - expect(bodyParams).to.have.property('item_name').to.equal(term); - expect(bodyParams).to.have.property('group_id').to.equal(optionalParameters.groupId); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - tracker.on('error', (error) => { + expect(bodyParams) + .to.have.property("user_input") + .to.equal(snakeCaseParameters.original_query); + expect(bodyParams) + .to.have.property("tr") + .to.equal(optionalParameters.tr); + expect(bodyParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(snakeCaseParameters.variation_id); + expect(bodyParams) + .to.have.property("section") + .to.deep.equal(snakeCaseParameters.section); + expect(bodyParams).to.have.property("item_name").to.equal(term); + expect(bodyParams) + .to.have.property("group_id") + .to.equal(optionalParameters.groupId); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); + + done(); + }); + + tracker.on("error", (error) => { done(error); }); // eslint-disable-next-line max-len - expect(tracker.trackAutocompleteSelectV2(term, snakeCaseParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelectV2(term, snakeCaseParameters), + ).to.equal(true); }); - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: 'original-query', - section: 'Search Suggestions', - tr: 'click', - group_id: 'all', - display_name: 'display-name', - item_id: '12345', + original_query: "original-query", + section: "Search Suggestions", + tr: "click", + group_id: "all", + display_name: "display-name", + item_id: "12345", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('original_query').to.equal(snakeCaseParameters.original_query); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); - expect(requestParams).to.have.property('section').to.equal(snakeCaseParameters.section); - expect(requestParams).to.have.property('group').to.deep.equal({ + expect(requestParams) + .to.have.property("original_query") + .to.equal(snakeCaseParameters.original_query); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("section") + .to.equal(snakeCaseParameters.section); + expect(requestParams).to.have.property("group").to.deep.equal({ display_name: snakeCaseParameters.display_name, group_id: snakeCaseParameters.group_id, }); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, snakeCaseParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, snakeCaseParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('original_query').to.equal(requiredParameters.originalQuery); - expect(requestParams).to.have.property('section').to.equal(requiredParameters.section); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("original_query") + .to.equal(requiredParameters.originalQuery); + expect(requestParams) + .to.have.property("section") + .to.equal(requiredParameters.section); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -1024,25 +1121,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1050,25 +1149,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1076,106 +1177,132 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { + it("Should respond with a valid response when term, required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('tr').to.equal(optionalParameters.tr); - expect(requestParams).to.have.property('item_id').to.equal(optionalParameters.itemId); - expect(requestParams).to.have.property('group').to.deep.equal({ + expect(requestParams) + .to.have.property("tr") + .to.equal(optionalParameters.tr); + expect(requestParams) + .to.have.property("item_id") + .to.equal(optionalParameters.itemId); + expect(requestParams).to.have.property("group").to.deep.equal({ group_id: optionalParameters.groupId, display_name: optionalParameters.displayName, }); - expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); - expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams) + .to.have.property("sl_campaign_owner") + .to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams) + .to.have.property("sl_campaign_id") + .to.deep.equal(optionalParameters.slCampaignId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, { ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, { + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should throw an error when invalid term is provided', () => { + it("Should throw an error when invalid term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect([], requiredParameters)).to.be.an('error'); + expect(tracker.trackAutocompleteSelect([], requiredParameters)).to.be.an( + "error", + ); }); - it('Should throw an error when no term is provided', () => { + it("Should throw an error when no term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect(null, requiredParameters)).to.be.an('error'); + expect( + tracker.trackAutocompleteSelect(null, requiredParameters), + ).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect(term, [])).to.be.an('error'); + expect(tracker.trackAutocompleteSelect(term, [])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect(term)).to.be.an('error'); + expect(tracker.trackAutocompleteSelect(term)).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1183,7 +1310,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -1191,16 +1318,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1208,39 +1337,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -1249,17 +1384,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); } - it('Should properly encode path parameter', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode path parameter", (done) => { + const specialCharacters = "+[]&"; const termSpecialCharacters = `apple ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -1267,25 +1404,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request expect(fetchSpy).to.have.been.called; - expect(requestUrl).to.include(encodeURIComponent(termSpecialCharacters)); + expect(requestUrl).to.include( + encodeURIComponent(termSpecialCharacters), + ); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(termSpecialCharacters, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect( + termSpecialCharacters, + requiredParameters, + ), + ).to.equal(true); }); - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -1294,27 +1438,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1322,66 +1468,74 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); + expect( + tracker.trackAutocompleteSelect(term, requiredParameters), + ).to.equal(true); }); }); - describe('trackItemDetailLoad', () => { + describe("trackItemDetailLoad", () => { const requiredParameters = { - itemId: 'test1', - itemName: 'test name', - url: 'http://constructor.io', + itemId: "test1", + itemName: "test name", + url: "http://constructor.io", }; const optionalParameters = { - variationId: 'test1-small', + variationId: "test1-small", analyticsTags: testAnalyticsTag, }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: 'test1', - item_name: 'test name', - url: 'http://constructor.io', - variation_id: 'test1-small', + item_id: "test1", + item_name: "test name", + url: "http://constructor.io", + variation_id: "test1-small", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); - expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); - expect(requestParams).to.have.property('variation_id').to.equal(snakeCaseParameters.variation_id); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("item_name") + .to.equal(snakeCaseParameters.item_name); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(snakeCaseParameters.variation_id); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1389,30 +1543,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(snakeCaseParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1420,8 +1578,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -1429,16 +1587,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1446,8 +1604,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1455,16 +1613,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1472,8 +1630,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1481,16 +1639,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1498,71 +1658,87 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackItemDetailLoad({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackItemDetailLoad({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('variation_id').to.deep.equal(optionalParameters.variationId); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("variation_id") + .to.deep.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackItemDetailLoad({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackItemDetailLoad({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackItemDetailLoad([])).to.be.an('error'); + expect(tracker.trackItemDetailLoad([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackItemDetailLoad()).to.be.an('error'); + expect(tracker.trackItemDetailLoad()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1570,7 +1746,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -1578,8 +1754,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1587,7 +1763,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1595,16 +1771,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -1613,21 +1789,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackItemDetailLoad(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackItemDetailLoad(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -1636,7 +1814,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -1645,7 +1823,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should truncate url param to 2048 characters max', (done) => { + it("Should truncate url param to 2048 characters max", (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -1655,7 +1833,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -1674,165 +1852,188 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackSearchSubmit', () => { - const term = 'Where The Wild Things Are'; - const requiredParameters = { originalQuery: 'original-query' }; + describe("trackSearchSubmit", () => { + const term = "Where The Wild Things Are"; + const requiredParameters = { originalQuery: "original-query" }; const optionalParameters = { - groupId: 'group-id', - displayName: 'display-name', + groupId: "group-id", + displayName: "display-name", analyticsTags: testAnalyticsTag, }; - it('Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided', (done) => { + it("Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: 'original-query', - group_id: 'group-id', - display_name: 'display-name', + original_query: "original-query", + group_id: "group-id", + display_name: "display-name", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('user_input').to.equal(snakeCaseParameters.original_query); - expect(bodyParams).to.have.property('search_term').to.equal(term); - expect(bodyParams.filters).to.have.property('group_id').to.equal(snakeCaseParameters.group_id); + expect(bodyParams) + .to.have.property("user_input") + .to.equal(snakeCaseParameters.original_query); + expect(bodyParams).to.have.property("search_term").to.equal(term); + expect(bodyParams.filters) + .to.have.property("group_id") + .to.equal(snakeCaseParameters.group_id); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackSearchSubmitV2(term, snakeCaseParameters)).to.equal(true); + expect(tracker.trackSearchSubmitV2(term, snakeCaseParameters)).to.equal( + true, + ); }); - it('V2 Should respond with a valid response when term and required parameters are provided', (done) => { + it("V2 Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('user_input').to.equal(requiredParameters.originalQuery); - expect(bodyParams).to.have.property('search_term').to.equal(term); - expect(bodyParams.filters).to.have.property('group_id').to.equal(optionalParameters.groupId); + expect(bodyParams) + .to.have.property("user_input") + .to.equal(requiredParameters.originalQuery); + expect(bodyParams).to.have.property("search_term").to.equal(term); + expect(bodyParams.filters) + .to.have.property("group_id") + .to.equal(optionalParameters.groupId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackSearchSubmitV2(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackSearchSubmitV2(term, { + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: 'original-query', - group_id: 'group-id', - display_name: 'display-name', + original_query: "original-query", + group_id: "group-id", + display_name: "display-name", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('original_query').to.equal(snakeCaseParameters.original_query); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("original_query") + .to.equal(snakeCaseParameters.original_query); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, snakeCaseParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('original_query').to.equal(requiredParameters.originalQuery); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("original_query") + .to.equal(requiredParameters.originalQuery); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -1840,25 +2041,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1866,25 +2069,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1892,101 +2097,125 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackSearchSubmit(term, { + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { + it("Should respond with a valid response when term, required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('group').to.deep.equal({ + expect(requestParams).to.have.property("group").to.deep.equal({ group_id: optionalParameters.groupId, display_name: optionalParameters.displayName, }); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackSearchSubmit(term, { + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid term is provided', () => { + it("Should throw an error when invalid term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit([], requiredParameters)).to.be.an('error'); + expect(tracker.trackSearchSubmit([], requiredParameters)).to.be.an( + "error", + ); }); - it('Should throw an error when no term is provided', () => { + it("Should throw an error when no term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit(null, requiredParameters)).to.be.an('error'); + expect(tracker.trackSearchSubmit(null, requiredParameters)).to.be.an( + "error", + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit(term, [])).to.be.an('error'); + expect(tracker.trackSearchSubmit(term, [])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit(term)).to.be.an('error'); + expect(tracker.trackSearchSubmit(term)).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1994,7 +2223,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -2002,16 +2231,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2019,39 +2250,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackSearchSubmit(term, requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -2060,17 +2295,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); } - it('Should properly encode path parameter', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode path parameter", (done) => { + const specialCharacters = "+[]&"; const termSpecialCharacters = `apple ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2078,25 +2315,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request expect(fetchSpy).to.have.been.called; - expect(requestUrl).to.include(encodeURIComponent(termSpecialCharacters)); + expect(requestUrl).to.include( + encodeURIComponent(termSpecialCharacters), + ); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(termSpecialCharacters, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchSubmit(termSpecialCharacters, requiredParameters), + ).to.equal(true); }); - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2105,27 +2346,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -2133,33 +2376,35 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( + true, + ); }); - it('Should properly obfuscate PII in a path parameter', (done) => { - const termWithPII = ' test-email@gmail.com'; - const replaceWith = ''; + it("Should properly obfuscate PII in a path parameter", (done) => { + const termWithPII = " test-email@gmail.com"; + const replaceWith = ""; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request @@ -2168,45 +2413,53 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(requestUrl).to.not.include(termWithPII); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII })).to.equal(true); + expect( + tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII }), + ).to.equal(true); }); - it('Should properly obfuscate PII in a query parameter', (done) => { - const termWithPII = ' test-email@gmail.com'; - const replaceWith = ''; + it("Should properly obfuscate PII in a query parameter", (done) => { + const termWithPII = " test-email@gmail.com"; + const replaceWith = ""; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('original_query').to.equal(replaceWith); - expect(requestParams).to.have.property('original_query').to.not.include(termWithPII); + expect(requestParams) + .to.have.property("original_query") + .to.equal(replaceWith); + expect(requestParams) + .to.have.property("original_query") + .to.not.include(termWithPII); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII })).to.equal(true); + expect( + tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII }), + ).to.equal(true); }); }); - describe('trackSearchResultsLoaded', () => { - const term = 'Cat in the Hat'; + describe("trackSearchResultsLoaded", () => { + const term = "Cat in the Hat"; const requiredParameters = { numResults: 1337 }; const optionalParameters = { itemIds: [1, 2, 3] }; const legacyParameters = { @@ -2214,20 +2467,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { customerIds: [1, 2, 3], }; const v2Parameters = { - url: 'test', + url: "test", resultPage: 3, - resultId: 'test', - sortOrder: 'descending', - sortBy: 'test', - selectedFilters: { test: ['test'] }, - section: 'Products', + resultId: "test", + sortOrder: "descending", + sortBy: "test", + selectedFilters: { test: ["test"] }, + section: "Products", analyticsTags: testAnalyticsTag, - items: [{ itemId: '1', slCampaignId: 'Campaign 123', slCampaignOwner: 'Campaign Man' }, { item_id: '2' }], + items: [ + { + itemId: "1", + slCampaignId: "Campaign 123", + slCampaignOwner: "Campaign Man", + }, + { item_id: "2" }, + ], }; - const transformedItems = [{ item_id: '1' }, { item_id: '2' }, { item_id: '3' }]; + const transformedItems = [ + { item_id: "1" }, + { item_id: "2" }, + { item_id: "3" }, + ]; - it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2236,145 +2500,200 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const snakeCaseParameters = { num_results: 1337, item_ids: [1, 2, 3], - url: 'test', + url: "test", result_page: 3, - result_id: 'test', - sort_order: 'descending', - sort_by: 'test', - selected_filters: { test: ['test'] }, - section: 'Products', + result_id: "test", + sort_order: "descending", + sort_by: "test", + selected_filters: { test: ["test"] }, + section: "Products", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('result_count').to.equal(snakeCaseParameters.num_results); - expect(bodyParams).to.have.property('url').to.equal(snakeCaseParameters.url); - expect(bodyParams).to.have.property('result_page').to.equal(snakeCaseParameters.result_page); - expect(bodyParams).to.have.property('result_id').to.equal(snakeCaseParameters.result_id); - expect(bodyParams).to.have.property('sort_order').to.equal(snakeCaseParameters.sort_order); - expect(bodyParams).to.have.property('sort_by').to.equal(snakeCaseParameters.sort_by); - expect(bodyParams).to.have.property('selected_filters').to.deep.equal(snakeCaseParameters.selected_filters); - expect(bodyParams).to.have.property('section').to.deep.equal(snakeCaseParameters.section); - expect(bodyParams).to.have.property('items').to.deep.equal(transformedItems); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - tracker.on('error', (error) => { + expect(bodyParams) + .to.have.property("result_count") + .to.equal(snakeCaseParameters.num_results); + expect(bodyParams) + .to.have.property("url") + .to.equal(snakeCaseParameters.url); + expect(bodyParams) + .to.have.property("result_page") + .to.equal(snakeCaseParameters.result_page); + expect(bodyParams) + .to.have.property("result_id") + .to.equal(snakeCaseParameters.result_id); + expect(bodyParams) + .to.have.property("sort_order") + .to.equal(snakeCaseParameters.sort_order); + expect(bodyParams) + .to.have.property("sort_by") + .to.equal(snakeCaseParameters.sort_by); + expect(bodyParams) + .to.have.property("selected_filters") + .to.deep.equal(snakeCaseParameters.selected_filters); + expect(bodyParams) + .to.have.property("section") + .to.deep.equal(snakeCaseParameters.section); + expect(bodyParams) + .to.have.property("items") + .to.deep.equal(transformedItems); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); + + done(); + }); + + tracker.on("error", (error) => { done(error); }); // eslint-disable-next-line max-len - expect(tracker.trackSearchResultsLoaded(term, snakeCaseParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, snakeCaseParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term and parameters are provided', (done) => { + it("Should respond with a valid response when term and parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('result_count').to.equal(requiredParameters.numResults); - expect(bodyParams).to.have.property('url').to.equal(v2Parameters.url); - expect(bodyParams).to.have.property('result_page').to.equal(v2Parameters.resultPage); - expect(bodyParams).to.have.property('result_id').to.equal(v2Parameters.resultId); - expect(bodyParams).to.have.property('sort_order').to.equal(v2Parameters.sortOrder); - expect(bodyParams).to.have.property('sort_by').to.equal(v2Parameters.sortBy); - expect(bodyParams).to.have.property('selected_filters').to.deep.equal(v2Parameters.selectedFilters); - expect(bodyParams).to.have.property('section').to.deep.equal(v2Parameters.section); - expect(bodyParams).to.have.property('analytics_tags').to.deep.equal(v2Parameters.analyticsTags); - expect(bodyParams).to.have.property('items').to.deep.equal(v2Parameters.items.map((item) => clientHelpers.toSnakeCaseKeys(item, false))); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - tracker.on('error', (error) => { + expect(bodyParams) + .to.have.property("result_count") + .to.equal(requiredParameters.numResults); + expect(bodyParams).to.have.property("url").to.equal(v2Parameters.url); + expect(bodyParams) + .to.have.property("result_page") + .to.equal(v2Parameters.resultPage); + expect(bodyParams) + .to.have.property("result_id") + .to.equal(v2Parameters.resultId); + expect(bodyParams) + .to.have.property("sort_order") + .to.equal(v2Parameters.sortOrder); + expect(bodyParams) + .to.have.property("sort_by") + .to.equal(v2Parameters.sortBy); + expect(bodyParams) + .to.have.property("selected_filters") + .to.deep.equal(v2Parameters.selectedFilters); + expect(bodyParams) + .to.have.property("section") + .to.deep.equal(v2Parameters.section); + expect(bodyParams) + .to.have.property("analytics_tags") + .to.deep.equal(v2Parameters.analyticsTags); + expect(bodyParams) + .to.have.property("items") + .to.deep.equal( + v2Parameters.items.map((item) => + clientHelpers.toSnakeCaseKeys(item, false), + ), + ); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); + + done(); + }); + + tracker.on("error", (error) => { done(error); }); // eslint-disable-next-line max-len - expect(tracker.trackSearchResultsLoaded(term, { ...requiredParameters, ...v2Parameters })).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + ...v2Parameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('result_count').to.equal(requiredParameters.numResults); - expect(bodyParams).to.have.property('url').to.equal(window?.location?.href); - expect(bodyParams).to.have.property('search_term').to.equal(term); - expect(bodyParams).to.have.property('url').to.equal(window?.location?.href); - expect(bodyParams).to.have.property('key'); - expect(bodyParams).to.have.property('i'); - expect(bodyParams).to.have.property('s'); - expect(bodyParams).to.have.property('c').to.equal(clientVersion); - expect(bodyParams).to.have.property('_dt'); + expect(bodyParams) + .to.have.property("result_count") + .to.equal(requiredParameters.numResults); + expect(bodyParams) + .to.have.property("url") + .to.equal(window?.location?.href); + expect(bodyParams).to.have.property("search_term").to.equal(term); + expect(bodyParams) + .to.have.property("url") + .to.equal(window?.location?.href); + expect(bodyParams).to.have.property("key"); + expect(bodyParams).to.have.property("i"); + expect(bodyParams).to.have.property("s"); + expect(bodyParams).to.have.property("c").to.equal(clientVersion); + expect(bodyParams).to.have.property("_dt"); validateOriginReferrer(bodyParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { - const segments = ['foo', 'bar']; + it("Should send along document_referrer and canonical_url query param", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -2382,31 +2701,41 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Body - expect(bodyParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(bodyParams).to.have.property('document_referrer').to.equal(referrer); + expect(bodyParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(bodyParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -2414,29 +2743,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Body - expect(bodyParams).to.have.property('us').to.deep.equal(segments); + expect(bodyParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -2444,29 +2775,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Body - expect(bodyParams).to.have.property('ui').to.equal(userId); + expect(bodyParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2474,105 +2807,123 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Body - expect(bodyParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(bodyParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { + it("Should respond with a valid response when term, required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; // Body - expect(bodyParams).to.have.property('items').to.deep.equal(transformedItems); + expect(bodyParams) + .to.have.property("items") + .to.deep.equal(transformedItems); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, { ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when term and legacy parameters are provided', (done) => { + it("Should respond with a valid response when term and legacy parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; // Body - expect(bodyParams).to.have.property('items').to.deep.equal(transformedItems); + expect(bodyParams) + .to.have.property("items") + .to.deep.equal(transformedItems); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, legacyParameters)).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, legacyParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, and zero value num_results parameter are provided', (done) => { + it("Should respond with a valid response when term, and zero value num_results parameter are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property('result_count').to.equal(0); + expect(bodyParams).to.have.property("result_count").to.equal(0); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, { num_results: 0 })).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, { num_results: 0 }), + ).to.equal(true); }); - it('Should trim term parameter if extra spaces are provided', (done) => { + it("Should trim term parameter if extra spaces are provided", (done) => { const spaceTerm = ` ${term} `; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2580,44 +2931,50 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property('search_term').to.equal(term); + expect(bodyParams).to.have.property("search_term").to.equal(term); done(); }); - expect(tracker.trackSearchResultsLoaded(spaceTerm, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(spaceTerm, requiredParameters), + ).to.equal(true); }); - it('Should throw an error when invalid term is provided', () => { + it("Should throw an error when invalid term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded([], requiredParameters)).to.be.an('error'); + expect(tracker.trackSearchResultsLoaded([], requiredParameters)).to.be.an( + "error", + ); }); - it('Should throw an error when no term is provided', () => { + it("Should throw an error when no term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded(null, requiredParameters)).to.be.an('error'); + expect( + tracker.trackSearchResultsLoaded(null, requiredParameters), + ).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded(term, [])).to.be.an('error'); + expect(tracker.trackSearchResultsLoaded(term, [])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded(term)).to.be.an('error'); + expect(tracker.trackSearchResultsLoaded(term)).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2625,7 +2982,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); @@ -2637,16 +2994,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(bodyParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2654,43 +3013,49 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Body - expect(bodyParams).to.not.have.property('origin_referrer'); + expect(bodyParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -2699,16 +3064,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); } - it('Should send all items when more than 100 items are provided', (done) => { + it("Should send all items when more than 100 items are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2721,17 +3088,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { item_ids: itemIDs, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property('items').to.deep.equal(formattedItems); + expect(bodyParams) + .to.have.property("items") + .to.deep.equal(formattedItems); expect(bodyParams.items).to.have.lengthOf(150); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -2739,8 +3108,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchResultsLoaded(term, parameters)).to.equal(true); }); - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2749,31 +3118,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Body - expect(bodyParams).to.have.property('ui').to.equal(userId); + expect(bodyParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -2781,28 +3152,30 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Body - expect(bodyParams).to.have.property('ui').to.equal(userIdExpected); + expect(bodyParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, requiredParameters), + ).to.equal(true); }); - it('Should truncate url param to 2048 characters max', (done) => { + it("Should truncate url param to 2048 characters max", (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -2812,7 +3185,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -2830,105 +3203,113 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchResultsLoaded(term, parameters)).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackSearchResultClick', () => { - const term = 'Where The Wild Things Are'; + describe("trackSearchResultClick", () => { + const term = "Where The Wild Things Are"; const requiredParameters = { - itemName: 'name', - itemId: 'customer-id', + itemName: "name", + itemId: "customer-id", }; const legacyParameters = { - name: 'name', - customerId: 'customer-id', + name: "name", + customerId: "customer-id", }; const optionalParameters = { - variationId: 'foobar', - resultId: 'result-id', - section: 'Products', + variationId: "foobar", + resultId: "result-id", + section: "Products", analyticsTags: testAnalyticsTag, - slCampaignOwner: 'Campaign Man', - slCampaignId: 'Campaign 123', + slCampaignOwner: "Campaign Man", + slCampaignId: "Campaign 123", }; const v2Parameters = { resultCount: 1337, @@ -2936,267 +3317,335 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { resultPositionOnPage: 3, numResultsPerPage: 20, selectedFilters: { - test: ['test'], + test: ["test"], }, analyticsTags: testAnalyticsTag, }; - it('Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided', (done) => { + it("Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_name: 'name', - item_id: 'customer-id', - variation_id: 'foobar', - result_id: 'result-id', + item_name: "name", + item_id: "customer-id", + variation_id: "foobar", + result_id: "result-id", result_count: 1337, result_page: 3, result_position_on_page: 3, num_results_per_page: 20, selected_filters: { - test: ['test'], + test: ["test"], }, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); - expect(bodyParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); - expect(bodyParams).to.have.property('variation_id').to.equal(snakeCaseParameters.variation_id); - expect(bodyParams).to.have.property('result_page').to.equal(snakeCaseParameters.result_page); - expect(bodyParams).to.have.property('result_position_on_page').to.equal(snakeCaseParameters.result_position_on_page); - expect(bodyParams).to.have.property('result_count').to.equal(snakeCaseParameters.result_count); - expect(bodyParams).to.have.property('num_results_per_page').to.equal(snakeCaseParameters.num_results_per_page); - expect(bodyParams).to.have.property('selected_filters').to.deep.equal(snakeCaseParameters.selected_filters); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); - - done(); - }); - - tracker.on('error', (error) => { - done(error); - }); + expect(bodyParams) + .to.have.property("item_name") + .to.equal(snakeCaseParameters.item_name); + expect(bodyParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(snakeCaseParameters.variation_id); + expect(bodyParams) + .to.have.property("result_page") + .to.equal(snakeCaseParameters.result_page); + expect(bodyParams) + .to.have.property("result_position_on_page") + .to.equal(snakeCaseParameters.result_position_on_page); + expect(bodyParams) + .to.have.property("result_count") + .to.equal(snakeCaseParameters.result_count); + expect(bodyParams) + .to.have.property("num_results_per_page") + .to.equal(snakeCaseParameters.num_results_per_page); + expect(bodyParams) + .to.have.property("selected_filters") + .to.deep.equal(snakeCaseParameters.selected_filters); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); + + done(); + }); + + tracker.on("error", (error) => { + done(error); + }); // eslint-disable-next-line max-len - expect(tracker.trackSearchResultClickV2(term, snakeCaseParameters)).to.equal(true); + expect( + tracker.trackSearchResultClickV2(term, snakeCaseParameters), + ).to.equal(true); }); - it('V2 Should respond with a valid response when term and required parameters are provided', (done) => { + it("V2 Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(bodyParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('section').to.deep.equal(optionalParameters.section); - expect(bodyParams).to.have.property('sl_campaign_id').to.equal(optionalParameters.slCampaignId); - expect(bodyParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); - expect(bodyParams).to.have.property('result_page').to.equal(v2Parameters.resultPage); - expect(bodyParams).to.have.property('result_position_on_page').to.equal(v2Parameters.resultPositionOnPage); - expect(bodyParams).to.have.property('result_count').to.equal(v2Parameters.resultCount); - expect(bodyParams).to.have.property('num_results_per_page').to.equal(v2Parameters.numResultsPerPage); - expect(bodyParams).to.have.property('selected_filters').to.deep.equal(v2Parameters.selectedFilters); - expect(bodyParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(bodyParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(bodyParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("section") + .to.deep.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("sl_campaign_id") + .to.equal(optionalParameters.slCampaignId); + expect(bodyParams) + .to.have.property("sl_campaign_owner") + .to.deep.equal(optionalParameters.slCampaignOwner); + expect(bodyParams) + .to.have.property("result_page") + .to.equal(v2Parameters.resultPage); + expect(bodyParams) + .to.have.property("result_position_on_page") + .to.equal(v2Parameters.resultPositionOnPage); + expect(bodyParams) + .to.have.property("result_count") + .to.equal(v2Parameters.resultCount); + expect(bodyParams) + .to.have.property("num_results_per_page") + .to.equal(v2Parameters.numResultsPerPage); + expect(bodyParams) + .to.have.property("selected_filters") + .to.deep.equal(v2Parameters.selectedFilters); + expect(bodyParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); // eslint-disable-next-line max-len - expect(tracker.trackSearchResultClickV2(term, { ...requiredParameters, ...optionalParameters, ...v2Parameters })).to.equal(true); + expect( + tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + ...optionalParameters, + ...v2Parameters, + }), + ).to.equal(true); }); - it('V2 Should return valid response when resultOffset is passed as an integer', (done) => { + it("V2 Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('V2 Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("V2 Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + }), + ).to.equal(true); }); - it('V2 Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("V2 Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_name: 'name', - item_id: 'customer-id', - variation_id: 'foobar', - result_id: 'result-id', + item_name: "name", + item_id: "customer-id", + variation_id: "foobar", + result_id: "result-id", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('name').to.equal(snakeCaseParameters.item_name); - expect(requestParams).to.have.property('customer_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("name") + .to.equal(snakeCaseParameters.item_name); + expect(requestParams) + .to.have.property("customer_id") + .to.equal(snakeCaseParameters.item_id); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, snakeCaseParameters)).to.equal(true); + expect( + tracker.trackSearchResultClick(term, snakeCaseParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('customer_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("customer_id") + .to.equal(requiredParameters.itemId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -3204,50 +3653,58 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -3255,25 +3712,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3281,166 +3740,204 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and variation id is provided', (done) => { + it("Should respond with a valid response when term, required parameters and variation id is provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('variation_id').to.equal('variation-id'); + expect(requestParams) + .to.have.property("variation_id") + .to.equal("variation-id"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, { - ...requiredParameters, - variation_id: 'variation-id', - })).to.equal(true); + expect( + tracker.trackSearchResultClick(term, { + ...requiredParameters, + variation_id: "variation-id", + }), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and optional parameters are provided', (done) => { + it("Should respond with a valid response when term, required parameters and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); - expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); - expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("sl_campaign_owner") + .to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams) + .to.have.property("sl_campaign_id") + .to.deep.equal(optionalParameters.slCampaignId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, Object.assign( - requiredParameters, - optionalParameters, - ))).to.equal(true); + expect( + tracker.trackSearchResultClick( + term, + Object.assign(requiredParameters, optionalParameters), + ), + ).to.equal(true); }); - it('Should respond with a valid response when term and legacy parameters are provided', (done) => { + it("Should respond with a valid response when term and legacy parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('customer_id').to.equal(legacyParameters.customerId); - expect(requestParams).to.have.property('name').to.equal(legacyParameters.name); + expect(requestParams) + .to.have.property("customer_id") + .to.equal(legacyParameters.customerId); + expect(requestParams) + .to.have.property("name") + .to.equal(legacyParameters.name); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, legacyParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, legacyParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term and item_is_convertible are provided', (done) => { + it("Should respond with a valid response when term and item_is_convertible are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('customer_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("customer_id") + .to.equal(requiredParameters.itemId); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('item_is_convertible').to.equal('false'); + expect(requestParams) + .to.have.property("item_is_convertible") + .to.equal("false"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, { - ...requiredParameters, - item_is_convertible: false, - })).to.equal(true); + expect( + tracker.trackSearchResultClick(term, { + ...requiredParameters, + item_is_convertible: false, + }), + ).to.equal(true); }); - it('Should throw an error when invalid term is provided', () => { + it("Should throw an error when invalid term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick([], requiredParameters)).to.be.an('error'); + expect(tracker.trackSearchResultClick([], requiredParameters)).to.be.an( + "error", + ); }); - it('Should throw an error when no term is provided', () => { + it("Should throw an error when no term is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(null, requiredParameters)).to.be.an('error'); + expect(tracker.trackSearchResultClick(null, requiredParameters)).to.be.an( + "error", + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term, [])).to.be.an('error'); + expect(tracker.trackSearchResultClick(term, [])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term)).to.be.an('error'); + expect(tracker.trackSearchResultClick(term)).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3448,7 +3945,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -3456,16 +3953,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3473,39 +3972,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackSearchResultClick(term, requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -3514,17 +4019,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultClick(term, requiredParameters), + ).to.equal(true); }); } - it('Should properly encode path parameter', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode path parameter", (done) => { + const specialCharacters = "+[]&"; const termSpecialCharacters = `apple ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -3532,25 +4039,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request expect(fetchSpy).to.have.been.called; - expect(requestUrl).to.include(encodeURIComponent(termSpecialCharacters)); + expect(requestUrl).to.include( + encodeURIComponent(termSpecialCharacters), + ); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(termSpecialCharacters, requiredParameters)).to.equal(true); + expect( + tracker.trackSearchResultClick( + termSpecialCharacters, + requiredParameters, + ), + ).to.equal(true); }); - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -3559,27 +4073,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -3587,87 +4103,98 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('GET'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("GET"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( + true, + ); }); - it('Should be rejected when an invalid section is used', (done) => { + it("Should be rejected when an invalid section is used", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { - expect(message).to.equal('Unknown section: non-existent'); + tracker.on("error", ({ message }) => { + expect(message).to.equal("Unknown section: non-existent"); done(); }); - expect(tracker.trackSearchResultClick(term, { ...requiredParameters, section: 'non-existent' })).to.equal(true); + expect( + tracker.trackSearchResultClick(term, { + ...requiredParameters, + section: "non-existent", + }), + ).to.equal(true); }); }); - describe('trackConversion', () => { - const term = 'Where The Wild Things Are'; + describe("trackConversion", () => { + const term = "Where The Wild Things Are"; const requiredParameters = { - itemId: 'customer-id', + itemId: "customer-id", revenue: 123, }; const optionalParameters = { - itemName: 'item_name', - variationId: 'variation-id', - section: 'Products', + itemName: "item_name", + variationId: "variation-id", + section: "Products", }; const legacyParameters = { - customerId: 'customer-id', + customerId: "customer-id", revenue: 123, - name: 'item_name', + name: "item_name", }; - it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: 'item_name', + item_id: "item_name", revenue: 123, - item_name: 'item_name', - variation_id: 'variation-id', + item_name: "item_name", + variation_id: "variation-id", is_custom_type: true, - display_name: 'Add To Wishlist', + display_name: "Add To Wishlist", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); - expect(requestParams).to.have.property('revenue').to.equal(snakeCaseParameters.revenue.toString()); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("revenue") + .to.equal(snakeCaseParameters.revenue.toString()); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3675,30 +4202,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, snakeCaseParameters)).to.equal(true); }); - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('revenue').to.equal(requiredParameters.revenue.toString()); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("revenue") + .to.equal(requiredParameters.revenue.toString()); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3706,43 +4237,60 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters, and optional parameters are provided', (done) => { + it("Should respond with a valid response when term, required parameters, and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const queryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(queryParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('revenue').to.equal(requiredParameters.revenue.toString()); - expect(requestParams).to.have.property('item_name').to.equal(optionalParameters.itemName); - expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(queryParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("revenue") + .to.equal(requiredParameters.revenue.toString()); + expect(requestParams) + .to.have.property("item_name") + .to.equal(optionalParameters.itemName); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackConversion(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackConversion(term, { + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response and section should be defaulted when term and required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when term and required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -3750,16 +4298,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3769,24 +4317,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, clonedParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3794,8 +4346,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -3803,16 +4355,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3820,8 +4372,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -3829,16 +4381,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3846,7 +4398,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should ensure userId is passed as a string', (done) => { + it("Should ensure userId is passed as a string", (done) => { const userId = 123; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -3855,16 +4407,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(String(userId)); + expect(requestParams).to.have.property("ui").to.equal(String(userId)); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3872,8 +4424,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3881,16 +4433,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3898,24 +4452,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and conversion type are provided', (done) => { + it("Should respond with a valid response when term, required parameters and conversion type are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const fullParameters = { ...requiredParameters, type: 'add_to_wishlist' }; + const fullParameters = { ...requiredParameters, type: "add_to_wishlist" }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('type').to.equal(fullParameters.type); + expect(requestParams) + .to.have.property("type") + .to.equal(fullParameters.type); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3923,7 +4479,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and custom conversion type are provided', (done) => { + it("Should respond with a valid response when term, required parameters and custom conversion type are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3931,23 +4487,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const fullParameters = { ...requiredParameters, - type: 'add_to_loves', - displayName: 'Add To Loves List', + type: "add_to_loves", + displayName: "Add To Loves List", isCustomType: true, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('type').to.equal(fullParameters.type); - expect(requestParams).to.have.property('is_custom_type').to.equal(fullParameters.isCustomType); - expect(requestParams).to.have.property('display_name').to.equal(fullParameters.displayName); + expect(requestParams) + .to.have.property("type") + .to.equal(fullParameters.type); + expect(requestParams) + .to.have.property("is_custom_type") + .to.equal(fullParameters.isCustomType); + expect(requestParams) + .to.have.property("display_name") + .to.equal(fullParameters.displayName); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3955,24 +4517,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it('Should respond with a valid response when term and legacy parameters are provided', (done) => { + it("Should respond with a valid response when term and legacy parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('item_id').to.equal(legacyParameters.customerId); - expect(requestParams).to.have.property('item_name').to.equal(legacyParameters.name); + expect(requestParams) + .to.have.property("item_id") + .to.equal(legacyParameters.customerId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(legacyParameters.name); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -3980,13 +4546,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, legacyParameters)).to.equal(true); }); - it('Should respond with a valid response when no term is provided, but parameters are', () => { + it("Should respond with a valid response when no term is provided, but parameters are", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); expect(tracker.trackConversion(null, requiredParameters)).to.equal(true); }); - it('should respond with a valid response if isCustomType is true, displayName is provided, and no type is specified', (done) => { + it("should respond with a valid response if isCustomType is true, displayName is provided, and no type is specified", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3994,22 +4560,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const fullParameters = { ...requiredParameters, - displayName: 'Add To Loves List', + displayName: "Add To Loves List", isCustomType: true, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('display_name').to.equal(fullParameters.displayName); - expect(requestParams).to.have.property('is_custom_type').to.equal(fullParameters.isCustomType); - expect(requestParams).to.not.have.property('type'); + expect(requestParams) + .to.have.property("display_name") + .to.equal(fullParameters.displayName); + expect(requestParams) + .to.have.property("is_custom_type") + .to.equal(fullParameters.isCustomType); + expect(requestParams).to.not.have.property("type"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4017,7 +4587,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it('should respond with an error if isCustomType is true, type is provided, and no displayName is specified', (done) => { + it("should respond with an error if isCustomType is true, type is provided, and no displayName is specified", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4025,22 +4595,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const fullParameters = { ...requiredParameters, - type: 'add_to_loves', + type: "add_to_loves", isCustomType: true, }; - tracker.on('error', (responseParams) => { + tracker.on("error", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('type').to.equal(fullParameters.type); - expect(requestParams).to.have.property('is_custom_type').to.equal(fullParameters.isCustomType); - expect(requestParams).to.not.have.property('display_name'); + expect(requestParams) + .to.have.property("type") + .to.equal(fullParameters.type); + expect(requestParams) + .to.have.property("is_custom_type") + .to.equal(fullParameters.isCustomType); + expect(requestParams).to.not.have.property("display_name"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('Invalid parameters'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); @@ -4048,7 +4624,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it('should support v1 endpoint arguments', (done) => { + it("should support v1 endpoint arguments", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4056,33 +4632,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parameters = { - customerId: 'customer-id', - name: 'name', - section: 'Products', + customerId: "customer-id", + name: "name", + section: "Products", revenue: 123, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const queryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(queryParams).to.have.property('section').to.equal(parameters.section); - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(parameters.customerId); - expect(requestParams).to.have.property('item_name').to.equal(parameters.name); - expect(requestParams).to.have.property('revenue').to.equal(parameters.revenue.toString()); - expect(requestParams).to.have.property('section').to.equal(parameters.section); + expect(queryParams) + .to.have.property("section") + .to.equal(parameters.section); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(parameters.customerId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(parameters.name); + expect(requestParams) + .to.have.property("revenue") + .to.equal(parameters.revenue.toString()); + expect(requestParams) + .to.have.property("section") + .to.equal(parameters.section); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4090,7 +4676,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, parameters)).to.equal(true); }); - it('Should trim term parameter if extra spaces are provided', (done) => { + it("Should trim term parameter if extra spaces are provided", (done) => { const spaceTerm = ` ${term} `; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4098,30 +4684,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); - expect(bodyParams).to.have.property('search_term').to.equal(term); + expect(bodyParams).to.have.property("search_term").to.equal(term); done(); }); - expect(tracker.trackConversion(spaceTerm, requiredParameters)).to.equal(true); + expect(tracker.trackConversion(spaceTerm, requiredParameters)).to.equal( + true, + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term, [])).to.be.an('error'); + expect(tracker.trackSearchResultClick(term, [])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term)).to.be.an('error'); + expect(tracker.trackSearchResultClick(term)).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4129,7 +4717,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -4137,8 +4725,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4146,7 +4734,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4154,16 +4742,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4172,21 +4760,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackConversion(term, requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackConversion(term, requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -4195,17 +4785,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); + expect(tracker.trackConversion(term, requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4214,16 +4806,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4231,10 +4823,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -4242,16 +4834,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4259,7 +4851,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when analyticsTags are provided', (done) => { + it("Should respond with a valid response when analyticsTags are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4270,83 +4862,91 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { analyticsTags: testAnalyticsTag, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackConversion(term, parametersWithAnalyticsTags)).to.equal(true); + expect( + tracker.trackConversion(term, parametersWithAnalyticsTags), + ).to.equal(true); }); }); - describe('trackPurchase', () => { + describe("trackPurchase", () => { const requiredParameters = { items: [ { // cspell:disable-next-line - itemId: 'productc60366c42b5d4194ad39962fd88d7266', - variationId: '456', + itemId: "productc60366c42b5d4194ad39962fd88d7266", + variationId: "456", }, { - itemId: 'product55f1b3577fa84947a93ea01b91d52f45', + itemId: "product55f1b3577fa84947a93ea01b91d52f45", }, ], revenue: 123.45, }; const optionalParameters = { - orderId: '123938123', - section: 'Products', + orderId: "123938123", + section: "Products", analyticsTags: testAnalyticsTag, }; const snakeCaseItems = [ { // cspell:disable-next-line - item_id: 'productc60366c42b5d4194ad39962fd88d7266', - variation_id: '456', + item_id: "productc60366c42b5d4194ad39962fd88d7266", + variation_id: "456", }, { - item_id: 'product55f1b3577fa84947a93ea01b91d52f45', + item_id: "product55f1b3577fa84947a93ea01b91d52f45", }, ]; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - order_id: '123938123', + order_id: "123938123", revenue: 123.45, items: snakeCaseItems, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseParameters.items); - expect(requestParams).to.have.property('revenue').to.equal(snakeCaseParameters.revenue); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseParameters.items); + expect(requestParams) + .to.have.property("revenue") + .to.equal(snakeCaseParameters.revenue); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4354,30 +4954,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(snakeCaseParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); - expect(requestParams).to.have.property('revenue').to.equal(requiredParameters.revenue); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("revenue") + .to.equal(requiredParameters.revenue); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4385,65 +4989,83 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestQueryParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestQueryParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestQueryParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestQueryParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Body - expect(requestBodyParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestBodyParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestBodyParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestBodyParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackPurchase({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackPurchase({ ...requiredParameters, ...optionalParameters }), + ).to.equal(true); }); - it('Should respond with a valid response when optional parameters are provided', (done) => { + it("Should respond with a valid response when optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestQueryParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestBodyParams).to.have.property('order_id').to.equal(optionalParameters.orderId); - expect(requestBodyParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestQueryParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestBodyParams) + .to.have.property("order_id") + .to.equal(optionalParameters.orderId); + expect(requestBodyParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackPurchase({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackPurchase({ ...requiredParameters, ...optionalParameters }), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -4451,16 +5073,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4468,23 +5090,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4492,8 +5114,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -4501,16 +5123,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4518,8 +5140,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4527,16 +5149,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4544,46 +5168,48 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response and limit items to no more than 100', (done) => { + it("Should respond with a valid response and limit items to no more than 100", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestBodyParams).to.have.property('items').length.to.be(100); + expect(requestBodyParams).to.have.property("items").length.to.be(100); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackPurchase({ - ...requiredParameters, - items: Array(200).fill({ item_id: 'product55f1b3a93ea01b91d52f45' }), - })).to.equal(true); + expect( + tracker.trackPurchase({ + ...requiredParameters, + items: Array(200).fill({ item_id: "product55f1b3a93ea01b91d52f45" }), + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase([])).to.be.an('error'); + expect(tracker.trackPurchase([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase()).to.be.an('error'); + expect(tracker.trackPurchase()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4591,7 +5217,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -4599,8 +5225,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4608,7 +5234,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4616,16 +5242,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4635,22 +5261,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // store2 doesn't seem to maintain the `window` context for bundled version if (!bundled) { - it('Should not send a purchase event if the order has been tracked already', (done) => { + it("Should not send a purchase event if the order has been tracked already", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const orderId = '848291039'; + const orderId = "848291039"; const apiKey = testApiKey; addOrderIdRecord({ orderId, apiKey }); - expect(tracker.trackPurchase({ - ...requiredParameters, - ...optionalParameters, - orderId, - })).to.equal(false); + expect( + tracker.trackPurchase({ + ...requiredParameters, + ...optionalParameters, + orderId, + }), + ).to.equal(false); setTimeout(() => { // Request @@ -4661,67 +5289,75 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should send a purchase event if the order has not been tracked yet', (done) => { + it("Should send a purchase event if the order has not been tracked yet", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestQueryParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestBodyParams).to.have.property('order_id').to.equal('328192019'); + expect(requestQueryParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestBodyParams) + .to.have.property("order_id") + .to.equal("328192019"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - addOrderIdRecord({ orderId: '239402919', apiKey: testApiKey }); - addOrderIdRecord({ orderId: '482039192', apiKey: testApiKey }); + addOrderIdRecord({ orderId: "239402919", apiKey: testApiKey }); + addOrderIdRecord({ orderId: "482039192", apiKey: testApiKey }); - expect(tracker.trackPurchase({ - ...requiredParameters, - ...optionalParameters, - orderId: '328192019', - })).to.equal(true); + expect( + tracker.trackPurchase({ + ...requiredParameters, + ...optionalParameters, + orderId: "328192019", + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase([])).to.be.an('error'); + expect(tracker.trackPurchase([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase()).to.be.an('error'); + expect(tracker.trackPurchase()).to.be.an("error"); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackPurchase(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackPurchase(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -4730,7 +5366,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -4739,8 +5375,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4749,16 +5385,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4766,10 +5402,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -4777,16 +5413,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -4795,94 +5431,110 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackRecommendationView', () => { + describe("trackRecommendationView", () => { const requiredParameters = { - podId: 'test_pod_id', + podId: "test_pod_id", numResultsViewed: 5, - url: 'https://constructor.io', + url: "https://constructor.io", }; const optionalParameters = { resultCount: 5, resultPage: 1, - resultId: 'result-id', - section: 'Products', + resultId: "result-id", + section: "Products", analyticsTags: testAnalyticsTag, }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - pod_id: 'test_pod_id', + pod_id: "test_pod_id", num_results_viewed: 5, - url: 'https://constructor.io', + url: "https://constructor.io", result_count: 5, result_page: 1, - result_id: 'result_id', - section: 'Products', + result_id: "result_id", + section: "Products", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('url').to.equal(snakeCaseParameters.url); - expect(requestParams).to.have.property('pod_id').to.equal(snakeCaseParameters.pod_id); - expect(requestParams).to.have.property('num_results_viewed').to.equal(snakeCaseParameters.num_results_viewed); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("url") + .to.equal(snakeCaseParameters.url); + expect(requestParams) + .to.have.property("pod_id") + .to.equal(snakeCaseParameters.pod_id); + expect(requestParams) + .to.have.property("num_results_viewed") + .to.equal(snakeCaseParameters.num_results_viewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(snakeCaseParameters)).to.equal(true); + expect(tracker.trackRecommendationView(snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); - expect(requestParams).to.have.property('pod_id').to.equal(requiredParameters.podId); - expect(requestParams).to.have.property('num_results_viewed').to.equal(requiredParameters.numResultsViewed); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("url") + .to.equal(requiredParameters.url); + expect(requestParams) + .to.have.property("pod_id") + .to.equal(requiredParameters.podId); + expect(requestParams) + .to.have.property("num_results_viewed") + .to.equal(requiredParameters.numResultsViewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4890,17 +5542,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4910,7 +5566,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(clonedParameters)).to.equal(true); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4918,16 +5574,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -4937,14 +5593,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(clonedParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and items are provided', (done) => { - const items = [ - { itemId: '123', variationId: '234' }, - { itemId: 'abc' }, - ]; + it("Should respond with a valid response when required parameters and items are provided", (done) => { + const items = [{ itemId: "123", variationId: "234" }, { itemId: "abc" }]; const snakeCaseItems = [ - { item_id: '123', variation_id: '234' }, - { item_id: 'abc' }, + { item_id: "123", variation_id: "234" }, + { item_id: "abc" }, ]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4952,24 +5605,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView({ items, ...requiredParameters })).to.equal(true); + expect( + tracker.trackRecommendationView({ items, ...requiredParameters }), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -4977,25 +5634,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5003,25 +5662,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5029,64 +5692,81 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("result_count") + .to.equal(optionalParameters.resultCount); + expect(requestParams) + .to.have.property("result_page") + .to.equal(optionalParameters.resultPage); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackRecommendationView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationView([])).to.be.an('error'); + expect(tracker.trackRecommendationView([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationView()).to.be.an('error'); + expect(tracker.trackRecommendationView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5094,7 +5774,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -5102,16 +5782,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5119,39 +5801,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackRecommendationView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackRecommendationView(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -5160,17 +5846,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5179,27 +5867,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5207,25 +5897,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when seedItemIds is an array', (done) => { - const seedItemIds = ['123']; + it("Should respond with a valid response when seedItemIds is an array", (done) => { + const seedItemIds = ["123"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5236,24 +5928,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on('success', (responseParams) => { + 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(['123']); + expect(requestParams) + .to.have.property("seed_item_ids") + .to.deep.equal(["123"]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationView(requiredParamsWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and convert seedItemIds to an array if it\'s is a number', (done) => { + it("Should respond with a valid response and convert seedItemIds to an array if it's is a number", (done) => { const seedItemIds = 123; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5265,25 +5961,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on('success', (responseParams) => { + 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(['123']); + expect(requestParams) + .to.have.property("seed_item_ids") + .to.deep.equal(["123"]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationView(requiredParamsWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and convert seedItemIds to an array if it\'s a string', (done) => { - const seedItemIds = '123'; + it("Should respond with a valid response and convert seedItemIds to an array if it's a string", (done) => { + const seedItemIds = "123"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5294,24 +5994,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on('success', (responseParams) => { + 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(['123']); + expect(requestParams) + .to.have.property("seed_item_ids") + .to.deep.equal(["123"]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationView(requiredParamsWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and omit seed_item_ids if seedItemIds is null', (done) => { + it("Should respond with a valid response and omit seed_item_ids if seedItemIds is null", (done) => { const seedItemIds = null; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5323,25 +6027,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on('success', (responseParams) => { + 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'); + 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'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationView(requiredParamsWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and omit seed_item_ids if seedItemIds is an object', (done) => { - const seedItemIds = { seedItemIds: '123' }; + it("Should respond with a valid response and omit seed_item_ids if seedItemIds is an object", (done) => { + const seedItemIds = { seedItemIds: "123" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5352,24 +6058,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on('success', (responseParams) => { + 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'); + 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'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationView(requiredParamsWithSeedItemIds), + ).to.equal(true); }); - it('Should truncate url param to 2048 characters max', (done) => { + it("Should truncate url param to 2048 characters max", (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -5379,7 +6087,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -5397,257 +6105,297 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(parameters)).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackRecommendationView({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationView({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackRecommendationView({ + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackRecommendationView({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackRecommendationView({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackRecommendationClick', () => { + describe("trackRecommendationClick", () => { // Note: `variation_id` parameter not being passed as none are defined for this item_id in catalog const requiredParameters = { - podId: 'test_pod_id', - strategyId: 'strategy-id', - itemId: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', + podId: "test_pod_id", + strategyId: "strategy-id", + itemId: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", }; const optionalParameters = { resultPositionOnPage: 10, numResultsPerPage: 5, resultCount: 5, resultPage: 1, - resultId: 'result-id', - section: 'Products', + resultId: "result-id", + section: "Products", analyticsTags: testAnalyticsTag, - slCampaignOwner: 'Campaign Man', - slCampaignId: 'Campaign 123', + slCampaignOwner: "Campaign Man", + slCampaignId: "Campaign 123", }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - pod_id: 'test_pod_id', - strategy_id: 'strategy-id', - item_id: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', + pod_id: "test_pod_id", + strategy_id: "strategy-id", + item_id: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", result_position_on_page: 10, num_results_per_page: 5, result_count: 5, result_page: 1, - result_id: 'result-id', - section: 'Products', + result_id: "result-id", + section: "Products", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('pod_id').to.equal(snakeCaseParameters.pod_id); - expect(requestParams).to.have.property('strategy_id').to.equal(snakeCaseParameters.strategy_id); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("pod_id") + .to.equal(snakeCaseParameters.pod_id); + expect(requestParams) + .to.have.property("strategy_id") + .to.equal(snakeCaseParameters.strategy_id); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(snakeCaseParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('pod_id').to.equal(requiredParameters.podId); - expect(requestParams).to.have.property('strategy_id').to.equal(requiredParameters.strategyId); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("pod_id") + .to.equal(requiredParameters.podId); + expect(requestParams) + .to.have.property("strategy_id") + .to.equal(requiredParameters.strategyId); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); - }); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); + }); - it('Backwards Compatibility - Should respond with a valid response when only item_name is provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when only item_name is provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const parametersWithItemName = { - pod_id: 'test_pod_id', - strategy_id: 'strategy-id', - item_name: 'product', + pod_id: "test_pod_id", + strategy_id: "strategy-id", + item_name: "product", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('pod_id').to.equal(parametersWithItemName.pod_id); - expect(requestParams).to.have.property('strategy_id').to.equal(parametersWithItemName.strategy_id); - expect(requestParams).to.have.property('item_name').to.equal(parametersWithItemName.item_name); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("pod_id") + .to.equal(parametersWithItemName.pod_id); + expect(requestParams) + .to.have.property("strategy_id") + .to.equal(parametersWithItemName.strategy_id); + expect(requestParams) + .to.have.property("item_name") + .to.equal(parametersWithItemName.item_name); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal( + true, + ); }); - it('Should respond with a valid response when only item_name is provided', (done) => { + it("Should respond with a valid response when only item_name is provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const parametersWithItemName = { - podId: 'test_pod_id', - strategyId: 'strategy-id', - itemName: 'product', + podId: "test_pod_id", + strategyId: "strategy-id", + itemName: "product", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('pod_id').to.equal(parametersWithItemName.podId); - expect(requestParams).to.have.property('strategy_id').to.equal(parametersWithItemName.strategyId); - expect(requestParams).to.have.property('item_name').to.equal(parametersWithItemName.itemName); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("pod_id") + .to.equal(parametersWithItemName.podId); + expect(requestParams) + .to.have.property("strategy_id") + .to.equal(parametersWithItemName.strategyId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(parametersWithItemName.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal( + true, + ); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5655,16 +6403,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -5674,33 +6422,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationClick(clonedParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -5708,25 +6462,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5734,25 +6490,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5760,68 +6518,95 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + 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(optionalParameters.resultPositionOnPage); - expect(requestParams).to.have.property('num_results_per_page').to.equal(optionalParameters.numResultsPerPage); - expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); - expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); - expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams) + .to.have.property("result_position_on_page") + .to.equal(optionalParameters.resultPositionOnPage); + expect(requestParams) + .to.have.property("num_results_per_page") + .to.equal(optionalParameters.numResultsPerPage); + expect(requestParams) + .to.have.property("result_count") + .to.equal(optionalParameters.resultCount); + expect(requestParams) + .to.have.property("result_page") + .to.equal(optionalParameters.resultPage); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("sl_campaign_id") + .to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams) + .to.have.property("sl_campaign_owner") + .to.deep.equal(optionalParameters.slCampaignOwner); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackRecommendationClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationClick([])).to.be.an('error'); + expect(tracker.trackRecommendationClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationClick()).to.be.an('error'); + expect(tracker.trackRecommendationClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5829,7 +6614,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -5837,16 +6622,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5854,39 +6641,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackRecommendationClick(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -5895,17 +6686,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5914,27 +6707,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5942,24 +6737,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when seedItemIds is provided as an array of strings', (done) => { + it("Should respond with a valid response when seedItemIds is provided as an array of strings", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5967,22 +6764,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parametersWithSeedItemIds = { ...requiredParameters, - seedItemIds: ['item-123', 'item-456', 'item-789'], + seedItemIds: ["item-123", "item-456", "item-789"], }; - tracker.on('success', (responseParams) => { + 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(['item-123', 'item-456', 'item-789']); + expect(requestParams) + .to.have.property("seed_item_ids") + .to.deep.equal(["item-123", "item-456", "item-789"]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationClick(parametersWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and convert seedItemIds to array when provided as string', (done) => { + it("Should respond with a valid response and convert seedItemIds to array when provided as string", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5990,22 +6791,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parametersWithSeedItemIds = { ...requiredParameters, - seedItemIds: 'item-123', + seedItemIds: "item-123", }; - tracker.on('success', (responseParams) => { + 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(['item-123']); + expect(requestParams) + .to.have.property("seed_item_ids") + .to.deep.equal(["item-123"]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationClick(parametersWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and convert seedItemIds to array when provided as number', (done) => { + it("Should respond with a valid response and convert seedItemIds to array when provided as number", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6015,20 +6820,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, seedItemIds: 123, }; - tracker.on('success', (responseParams) => { + 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(['123']); + expect(requestParams) + .to.have.property("seed_item_ids") + .to.deep.equal(["123"]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationClick(parametersWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and omit seed_item_ids when seedItemIds is empty string', (done) => { + it("Should respond with a valid response and omit seed_item_ids when seedItemIds is empty string", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6036,22 +6845,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parametersWithSeedItemIds = { ...requiredParameters, - seedItemIds: '', + seedItemIds: "", }; - tracker.on('success', (responseParams) => { + 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'); + 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'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationClick(parametersWithSeedItemIds), + ).to.equal(true); }); - it('Should respond with a valid response and omit seed_item_ids when seedItemIds is empty array', (done) => { + it("Should respond with a valid response and omit seed_item_ids when seedItemIds is empty array", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6061,221 +6872,255 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, seedItemIds: [], }; - tracker.on('success', (responseParams) => { + 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'); + 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'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); + expect( + tracker.trackRecommendationClick(parametersWithSeedItemIds), + ).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackRecommendationClick({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackRecommendationClick({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackRecommendationClick({ + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackRecommendationClick({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackRecommendationClick({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackBrowseResultsLoaded', () => { + describe("trackBrowseResultsLoaded", () => { const requiredParameters = { - sortBy: 'price', - sortOrder: 'ascending', - filterName: 'group_id', - filterValue: 'Clothing', - url: 'http://constructor.io', + sortBy: "price", + sortOrder: "ascending", + filterName: "group_id", + filterValue: "Clothing", + url: "http://constructor.io", }; const optionalParameters = { - section: 'Products', + section: "Products", resultCount: 5, resultPage: 1, - resultId: 'result-id', - selectedFilters: { foo: ['bar'] }, + resultId: "result-id", + selectedFilters: { foo: ["bar"] }, items: [ { - itemId: '123', - variationId: '456', - slCampaignId: 'Campaign 123', - slCampaignOwner: 'Campaign Man', + itemId: "123", + variationId: "456", + slCampaignId: "Campaign 123", + slCampaignOwner: "Campaign Man", }, { - itemId: '789', + itemId: "789", }, ], analyticsTags: testAnalyticsTag, }; const snakeCaseItems = [ { - item_id: '123', - variation_id: '456', - sl_campaign_id: 'Campaign 123', - sl_campaign_owner: 'Campaign Man', + item_id: "123", + variation_id: "456", + sl_campaign_id: "Campaign 123", + sl_campaign_owner: "Campaign Man", }, { - item_id: '789', + item_id: "789", }, ]; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - sort_by: 'price', - sort_order: 'ascending', - filter_name: 'group_id', - filter_value: 'Clothing', - url: 'http://constructor.io', + sort_by: "price", + sort_order: "ascending", + filter_name: "group_id", + filter_value: "Clothing", + url: "http://constructor.io", result_count: 5, result_page: 1, - result_id: 'result-id', - selected_filters: { foo: ['bar'] }, + result_id: "result-id", + selected_filters: { foo: ["bar"] }, items: snakeCaseItems, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('sort_by').to.equal(snakeCaseParameters.sort_by); - expect(requestParams).to.have.property('sort_order').to.equal(snakeCaseParameters.sort_order); - expect(requestParams).to.have.property('filter_name').to.equal(snakeCaseParameters.filter_name); - expect(requestParams).to.have.property('filter_value').to.equal(snakeCaseParameters.filter_value); - expect(requestParams).to.have.property('url').to.equal(snakeCaseParameters.url); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("sort_by") + .to.equal(snakeCaseParameters.sort_by); + expect(requestParams) + .to.have.property("sort_order") + .to.equal(snakeCaseParameters.sort_order); + expect(requestParams) + .to.have.property("filter_name") + .to.equal(snakeCaseParameters.filter_name); + expect(requestParams) + .to.have.property("filter_value") + .to.equal(snakeCaseParameters.filter_value); + expect(requestParams) + .to.have.property("url") + .to.equal(snakeCaseParameters.url); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded(snakeCaseParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('sort_by').to.equal(requiredParameters.sortBy); - expect(requestParams).to.have.property('sort_order').to.equal(requiredParameters.sortOrder); - expect(requestParams).to.have.property('filter_name').to.equal(requiredParameters.filterName); - expect(requestParams).to.have.property('filter_value').to.equal(requiredParameters.filterValue); - expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("sort_by") + .to.equal(requiredParameters.sortBy); + expect(requestParams) + .to.have.property("sort_order") + .to.equal(requiredParameters.sortOrder); + expect(requestParams) + .to.have.property("filter_name") + .to.equal(requiredParameters.filterName); + expect(requestParams) + .to.have.property("filter_value") + .to.equal(requiredParameters.filterValue); + expect(requestParams) + .to.have.property("url") + .to.equal(requiredParameters.url); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -6283,16 +7128,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6302,33 +7147,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(clonedParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -6336,25 +7187,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -6362,25 +7215,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6388,76 +7243,101 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('selected_filters').to.deep.equal(optionalParameters.selectedFilters); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("result_count") + .to.equal(optionalParameters.resultCount); + expect(requestParams) + .to.have.property("result_page") + .to.equal(optionalParameters.resultPage); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("selected_filters") + .to.deep.equal(optionalParameters.selectedFilters); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should send all items when more than 100 items are provided', (done) => { + it("Should send all items when more than 100 items are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const items = [...Array(150).keys()].map((i) => ({ item_id: i.toString() })); + const items = [...Array(150).keys()].map((i) => ({ + item_id: i.toString(), + })); const parameters = { ...requiredParameters, items, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('items').to.deep.equal(items); + expect(requestParams).to.have.property("items").to.deep.equal(items); expect(requestParams.items).to.have.lengthOf(150); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6465,19 +7345,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(parameters)).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultsLoaded([])).to.be.an('error'); + expect(tracker.trackBrowseResultsLoaded([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultsLoaded()).to.be.an('error'); + expect(tracker.trackBrowseResultsLoaded()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6485,7 +7365,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -6493,16 +7373,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6510,39 +7392,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackBrowseResultsLoaded(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -6551,17 +7437,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -6570,27 +7458,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -6598,24 +7488,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( + true, + ); }); - it('Should truncate url param to 2048 characters max', (done) => { + it("Should truncate url param to 2048 characters max", (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -6625,7 +7517,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -6643,128 +7535,142 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(parameters)).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - ...optionalParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + ...optionalParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackBrowseRedirect', () => { + describe("trackBrowseRedirect", () => { const requiredParameters = { - filterName: 'group_id', - filterValue: 'Clothing', - searchTerm: 'books', + filterName: "group_id", + filterValue: "Clothing", + searchTerm: "books", }; const optionalParameters = { - section: 'Products', - selectedFilters: { foo: ['bar'] }, + section: "Products", + selectedFilters: { foo: ["bar"] }, analyticsTags: testAnalyticsTag, - redirectToUrl: 'https://demo.constructor.io/books', - userInput: 'book', + redirectToUrl: "https://demo.constructor.io/books", + userInput: "book", }; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('filter_name').to.equal(requiredParameters.filterName); - expect(requestParams).to.have.property('filter_value').to.equal(requiredParameters.filterValue); - expect(requestParams).to.have.property('search_term').to.equal(requiredParameters.searchTerm); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("filter_name") + .to.equal(requiredParameters.filterName); + expect(requestParams) + .to.have.property("filter_value") + .to.equal(requiredParameters.filterValue); + expect(requestParams) + .to.have.property("search_term") + .to.equal(requiredParameters.searchTerm); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6772,7 +7678,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -6780,16 +7686,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6799,24 +7705,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(clonedParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6824,8 +7734,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -6833,16 +7743,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6850,8 +7760,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -6859,16 +7769,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6876,8 +7786,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6885,16 +7795,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -6902,47 +7814,62 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('redirect_to_url').to.equal(optionalParameters.redirectToUrl); - expect(requestParams).to.have.property('user_input').to.equal(optionalParameters.userInput); - expect(requestParams).to.have.property('selected_filters').to.deep.equal(optionalParameters.selectedFilters); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("redirect_to_url") + .to.equal(optionalParameters.redirectToUrl); + expect(requestParams) + .to.have.property("user_input") + .to.equal(optionalParameters.userInput); + expect(requestParams) + .to.have.property("selected_filters") + .to.deep.equal(optionalParameters.selectedFilters); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseRedirect({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackBrowseRedirect({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseRedirect([])).to.be.an('error'); + expect(tracker.trackBrowseRedirect([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseRedirect()).to.be.an('error'); + expect(tracker.trackBrowseRedirect()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6950,7 +7877,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -6958,8 +7885,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -6967,7 +7894,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6975,16 +7902,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -6993,21 +7920,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseRedirect(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackBrowseRedirect(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -7016,7 +7945,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -7025,8 +7954,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7035,16 +7964,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7052,10 +7981,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7063,16 +7992,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7081,105 +8010,123 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackBrowseResultClick', () => { + describe("trackBrowseResultClick", () => { // Note: `variation_id` parameter not being passed as none are defined for this item_id in catalog const requiredParameters = { - itemId: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', - filterName: 'group_id', - filterValue: 'BrandXY', - itemName: 'Pencil', + itemId: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", + filterName: "group_id", + filterValue: "BrandXY", + itemName: "Pencil", }; const legacyParameters = { - filterName: 'group_id', - filterValue: 'BrandXY', - name: 'Pencil', - customerId: 'customer-id', + filterName: "group_id", + filterValue: "BrandXY", + name: "Pencil", + customerId: "customer-id", }; const optionalParameters = { - section: 'Products', + section: "Products", resultCount: 5, resultPage: 1, - resultId: 'result-id', + resultId: "result-id", resultPositionOnPage: 10, numResultsPerPage: 5, - selectedFilters: { foo: ['bar'] }, + selectedFilters: { foo: ["bar"] }, analyticsTags: testAnalyticsTag, - slCampaignOwner: 'Campaign Man', - slCampaignId: 'Campaign 123', + slCampaignOwner: "Campaign Man", + slCampaignId: "Campaign 123", }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', - item_name: 'Pencil', - variation_id: 'product-variation', - filter_name: 'group_id', - filter_value: 'Clothing', + item_id: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", + item_name: "Pencil", + variation_id: "product-variation", + filter_name: "group_id", + filter_value: "Clothing", result_count: 5, result_page: 1, - result_id: 'result-id', + result_id: "result-id", result_position_on_page: 10, num_results_per_page: 5, - selected_filters: { foo: ['bar'] }, + selected_filters: { foo: ["bar"] }, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); - expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); - expect(requestParams).to.have.property('filter_name').to.equal(snakeCaseParameters.filter_name); - expect(requestParams).to.have.property('filter_value').to.equal(snakeCaseParameters.filter_value); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("item_name") + .to.equal(snakeCaseParameters.item_name); + expect(requestParams) + .to.have.property("filter_name") + .to.equal(snakeCaseParameters.filter_name); + expect(requestParams) + .to.have.property("filter_value") + .to.equal(snakeCaseParameters.filter_value); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultClick(snakeCaseParameters)).to.equal(true); + expect(tracker.trackBrowseResultClick(snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('filter_name').to.equal(requiredParameters.filterName); - expect(requestParams).to.have.property('filter_value').to.equal(requiredParameters.filterValue); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("filter_name") + .to.equal(requiredParameters.filterName); + expect(requestParams) + .to.have.property("filter_value") + .to.equal(requiredParameters.filterValue); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7187,7 +8134,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7195,16 +8142,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7214,24 +8161,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(clonedParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7239,8 +8190,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -7248,16 +8199,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7265,8 +8216,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7274,16 +8225,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7291,8 +8242,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7300,16 +8251,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7317,40 +8270,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); - expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('result_position_on_page').to.equal(optionalParameters.resultPositionOnPage); - expect(requestParams).to.have.property('num_results_per_page').to.equal(optionalParameters.numResultsPerPage); - expect(requestParams).to.have.property('selected_filters').to.deep.equal(optionalParameters.selectedFilters); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); - expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); - expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("result_count") + .to.equal(optionalParameters.resultCount); + expect(requestParams) + .to.have.property("result_page") + .to.equal(optionalParameters.resultPage); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("result_position_on_page") + .to.equal(optionalParameters.resultPositionOnPage); + expect(requestParams) + .to.have.property("num_results_per_page") + .to.equal(optionalParameters.numResultsPerPage); + expect(requestParams) + .to.have.property("selected_filters") + .to.deep.equal(optionalParameters.selectedFilters); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("sl_campaign_id") + .to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams) + .to.have.property("sl_campaign_owner") + .to.deep.equal(optionalParameters.slCampaignOwner); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultClick({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackBrowseResultClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => { + 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, @@ -7359,25 +8337,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const parameters = { ...requiredParameters, ...optionalParameters, - itemId: 'non-existent-item-id', + itemId: "non-existent-item-id", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (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); + 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.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7385,19 +8377,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(parameters)).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultClick([])).to.be.an('error'); + expect(tracker.trackBrowseResultClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultClick()).to.be.an('error'); + expect(tracker.trackBrowseResultClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7405,7 +8397,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -7413,8 +8405,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7422,7 +8414,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7430,16 +8422,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7448,21 +8440,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseResultClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackBrowseResultClick(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -7471,17 +8465,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7490,16 +8486,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7507,10 +8503,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7518,16 +8514,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7535,24 +8531,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when legacy parameters are provided', (done) => { + it("Should respond with a valid response when legacy parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('item_id').to.equal(legacyParameters.customerId); - expect(requestParams).to.have.property('item_name').to.equal(legacyParameters.name); + expect(requestParams) + .to.have.property("item_id") + .to.equal(legacyParameters.customerId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(legacyParameters.name); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7560,165 +8560,181 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(legacyParameters)).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultClick({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackBrowseResultClick({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackBrowseResultClick({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackBrowseResultClick({ + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackBrowseResultClick({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackBrowseResultClick({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackGenericResultClick', () => { + describe("trackGenericResultClick", () => { // Note: `variation_id` parameter not being passed as none are defined for this item_id in catalog const requiredParameters = { - itemId: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', + itemId: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", }; const optionalParameters = { - itemName: 'Example Product Name', - section: 'Products', + itemName: "Example Product Name", + section: "Products", analyticsTags: testAnalyticsTag, }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', - item_name: 'Example Product Name', - variation_id: 'product-variation', + item_id: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", + item_name: "Example Product Name", + variation_id: "product-variation", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick(snakeCaseParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { + it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7726,16 +8742,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -7745,33 +8761,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackGenericResultClick(clonedParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -7779,25 +8801,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7805,25 +8829,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7831,7 +8857,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -7841,43 +8867,58 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(optionalParameters.itemName); - expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(optionalParameters.itemName); + expect(requestParams) + .to.have.property("analytics_tags") + .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackGenericResultClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and non-existent item id are provided', (done) => { + 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, @@ -7886,21 +8927,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const parameters = { ...requiredParameters, ...optionalParameters, - itemId: 'non-existent-item-id', + itemId: "non-existent-item-id", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (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.deep.equal(parameters.itemName); + 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.deep.equal(parameters.itemName); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -7908,19 +8955,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackGenericResultClick(parameters)).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackGenericResultClick([])).to.be.an('error'); + expect(tracker.trackGenericResultClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackGenericResultClick()).to.be.an('error'); + expect(tracker.trackGenericResultClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7928,7 +8975,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -7936,16 +8983,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7953,39 +9002,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackGenericResultClick(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -7994,17 +9047,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -8013,27 +9068,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8041,235 +9098,281 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackGenericResultClick({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackGenericResultClick({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackGenericResultClick({ + ...requiredParameters, + }), + ).to.equal(true); }); }); - describe('trackQuizResultsLoaded', () => { + describe("trackQuizResultsLoaded", () => { const requiredParameters = { - quizId: 'coffee-quiz', - quizVersionId: '1231243', - quizSessionId: '13443', - url: 'www.example.com', + quizId: "coffee-quiz", + quizVersionId: "1231243", + quizSessionId: "13443", + url: "www.example.com", }; const optionalParameters = { - section: 'Products', + section: "Products", resultCount: 1, - resultId: '12312', + resultId: "12312", resultPage: 1, items: [ { - itemId: '123', - variationId: '456', + itemId: "123", + variationId: "456", }, { - itemName: 'product test', - itemId: '789', + itemName: "product test", + itemId: "789", }, ], }; const snakeCaseItems = [ { // cspell:disable-next-line - item_id: '123', - variation_id: '456', + item_id: "123", + variation_id: "456", }, { - item_name: 'product test', - item_id: '789', + item_name: "product test", + item_id: "789", }, ]; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - quiz_id: 'coffee-quiz', - quiz_version_id: '1231243', - quiz_session_id: '13443', - url: 'www.example.com', + quiz_id: "coffee-quiz", + quiz_version_id: "1231243", + quiz_session_id: "13443", + url: "www.example.com", items: snakeCaseItems, }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(snakeCaseParameters.quiz_id); - expect(requestParams).to.have.property('quiz_version_id').to.equal(snakeCaseParameters.quiz_version_id); - expect(requestParams).to.have.property('url').to.equal(snakeCaseParameters.url); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(snakeCaseParameters.quiz_id); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(snakeCaseParameters.quiz_version_id); + expect(requestParams) + .to.have.property("url") + .to.equal(snakeCaseParameters.url); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackQuizResultsLoaded(snakeCaseParameters)).to.equal(true); + expect(tracker.trackQuizResultsLoaded(snakeCaseParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); - expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); - expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(requiredParameters.quizId); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(requiredParameters.quizVersionId); + expect(requestParams) + .to.have.property("url") + .to.equal(requiredParameters.url); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when result_count is zero', (done) => { + it("Should respond with a valid response when result_count is zero", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); - expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); - expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); - expect(requestParams).to.have.property('result_count').to.equal(0); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(requiredParameters.quizId); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(requiredParameters.quizVersionId); + expect(requestParams) + .to.have.property("url") + .to.equal(requiredParameters.url); + expect(requestParams).to.have.property("result_count").to.equal(0); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, result_count: 0 })).to.equal(true); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + result_count: 0, + }), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8277,8 +9380,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -8286,16 +9389,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8303,8 +9406,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8312,16 +9415,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8329,8 +9432,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8338,16 +9441,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8355,120 +9460,162 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("result_count") + .to.equal(optionalParameters.resultCount); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("result_page") + .to.equal(optionalParameters.resultPage); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid quizId is provided', () => { + it("Should throw an error when invalid quizId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, quizId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ ...requiredParameters, quizId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid quizVersionId is provided', () => { + it("Should throw an error when invalid quizVersionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, quizVersionId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + quizVersionId: 1, + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid quizSessionId is provided', () => { + it("Should throw an error when invalid quizSessionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, quizSessionId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + quizSessionId: 1, + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid url is provided', () => { + it("Should throw an error when invalid url is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, url: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ ...requiredParameters, url: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid section is provided', () => { + it("Should throw an error when invalid section is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultCount is provided', () => { + it("Should throw an error when invalid resultCount is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, resultCount: '1' })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultCount: "1", + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultPage is provided', () => { + it("Should throw an error when invalid resultPage is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, resultPage: '1' })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultPage: "1", + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultId is provided', () => { + it("Should throw an error when invalid resultId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, resultId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ ...requiredParameters, resultId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when no quiz_id is provided', () => { + it("Should throw an error when no quiz_id is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); }); - it('Should throw an error when no quiz_version_id is provided', () => { + it("Should throw an error when no quiz_version_id is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizVersionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); }); - it('Should throw an error when no quiz_session_id is provided', () => { + it("Should throw an error when no quiz_session_id is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizSessionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); }); - it('Should throw an error when no url is provided', () => { + it("Should throw an error when no url is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { url: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded([])).to.be.an('error'); + expect(tracker.trackQuizResultsLoaded([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded()).to.be.an('error'); + expect(tracker.trackQuizResultsLoaded()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8476,7 +9623,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -8484,8 +9631,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8493,7 +9640,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8501,16 +9648,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8519,21 +9666,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackQuizResultsLoaded(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackQuizResultsLoaded(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -8542,17 +9691,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); + expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal( + true, + ); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -8561,16 +9712,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8578,10 +9729,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8589,16 +9740,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8606,7 +9757,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it('Should truncate url param to 2048 characters max', (done) => { + it("Should truncate url param to 2048 characters max", (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -8616,7 +9767,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', () => { + tracker.on("success", () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -8634,152 +9785,170 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(parameters)).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackQuizResultsLoaded({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should return an error when resultOffset is not a number', () => { + it("Should return an error when resultOffset is not a number", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - expect(tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultOffset: 'not-a-number', - })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultOffset: "not-a-number", + }), + ).to.be.an("error"); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackQuizResultClick', () => { + describe("trackQuizResultClick", () => { const requiredParameters = { - quizId: 'coffee-quiz', - quizVersionId: '1231243', - quizSessionId: '13443', - itemName: 'espresso', - itemId: '1123', + quizId: "coffee-quiz", + quizVersionId: "1231243", + quizSessionId: "13443", + itemName: "espresso", + itemId: "1123", }; const optionalParameters = { - section: 'Products', + section: "Products", resultCount: 1, - resultId: '12312', + resultId: "12312", resultPage: 1, numResultsPerPage: 100, resultPositionOnPage: 1, - variationId: '123123', + variationId: "123123", }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - quiz_id: 'coffee-quiz', - quiz_version_id: '1231243', - quiz_session_id: '13443', - item_name: 'espresso', - item_id: '1123', + quiz_id: "coffee-quiz", + quiz_version_id: "1231243", + quiz_session_id: "13443", + item_name: "espresso", + item_id: "1123", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(snakeCaseParameters.quiz_id); - expect(requestParams).to.have.property('quiz_version_id').to.equal(snakeCaseParameters.quiz_version_id); - expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(snakeCaseParameters.quiz_id); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(snakeCaseParameters.quiz_version_id); + expect(requestParams) + .to.have.property("item_name") + .to.equal(snakeCaseParameters.item_name); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8787,32 +9956,40 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(snakeCaseParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); - expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(requiredParameters.quizId); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(requiredParameters.quizVersionId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8820,8 +9997,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -8829,16 +10006,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8846,24 +10023,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8871,8 +10052,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8880,16 +10061,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8897,8 +10078,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8906,16 +10087,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -8923,139 +10106,195 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); - expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); - expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); - expect(requestParams).to.have.property('num_results_per_page').to.equal(optionalParameters.numResultsPerPage); - expect(requestParams).to.have.property('result_position_on_page').to.equal(optionalParameters.resultPositionOnPage); - expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("result_count") + .to.equal(optionalParameters.resultCount); + expect(requestParams) + .to.have.property("result_id") + .to.equal(optionalParameters.resultId); + expect(requestParams) + .to.have.property("result_page") + .to.equal(optionalParameters.resultPage); + expect(requestParams) + .to.have.property("num_results_per_page") + .to.equal(optionalParameters.numResultsPerPage); + expect(requestParams) + .to.have.property("result_position_on_page") + .to.equal(optionalParameters.resultPositionOnPage); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid quizId is provided', () => { + it("Should throw an error when invalid quizId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, quizId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ ...requiredParameters, quizId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid quizVersionId is provided', () => { + it("Should throw an error when invalid quizVersionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, quizVersionId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + quizVersionId: 1, + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid quizSessionId is provided', () => { + it("Should throw an error when invalid quizSessionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, quizSessionId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + quizSessionId: 1, + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid itemId is provided', () => { + it("Should throw an error when invalid itemId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, itemId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ ...requiredParameters, itemId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid itemName is provided', () => { + it("Should throw an error when invalid itemName is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, itemName: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ ...requiredParameters, itemName: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid section is provided', () => { + it("Should throw an error when invalid section is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultCount is provided', () => { + it("Should throw an error when invalid resultCount is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, resultCount: '1' })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + resultCount: "1", + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultPage is provided', () => { + it("Should throw an error when invalid resultPage is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, resultPage: '1' })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + resultPage: "1", + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultId is provided', () => { + it("Should throw an error when invalid resultId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, resultId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ ...requiredParameters, resultId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid numResultsPerPage is provided', () => { + it("Should throw an error when invalid numResultsPerPage is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, numResultsPerPage: '1' })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + numResultsPerPage: "1", + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid resultPositionOnPage is provided', () => { + it("Should throw an error when invalid resultPositionOnPage is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick({ ...requiredParameters, resultPositionOnPage: '1' })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + resultPositionOnPage: "1", + }), + ).to.be.an("error"); }); - it('Should throw an error when no quizId is provided', () => { + it("Should throw an error when no quizId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); + expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); }); - it('Should throw an error when no quizVersionId is provided', () => { + it("Should throw an error when no quizVersionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizVersionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); + expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); }); - it('Should throw an error when no quizSessionId is provided', () => { + it("Should throw an error when no quizSessionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizSessionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); + expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); }); - it('Should throw an error when no itemId nor item_name is provided', () => { + it("Should throw an error when no itemId nor item_name is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { itemName: _, itemId: __, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); + expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick([])).to.be.an('error'); + expect(tracker.trackQuizResultClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick()).to.be.an('error'); + expect(tracker.trackQuizResultClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9063,7 +10302,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -9071,8 +10310,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9080,7 +10319,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9088,16 +10327,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9106,21 +10345,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackQuizResultClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackQuizResultClick(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -9129,7 +10370,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -9138,8 +10379,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -9148,16 +10389,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9165,10 +10406,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9176,16 +10417,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9193,151 +10434,169 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it('Should return valid response when resultOffset is passed as an integer', (done) => { + it("Should return valid response when resultOffset is passed as an integer", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_offset').to.equal(1); + expect(requestParams).to.have.property("result_offset").to.equal(1); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackQuizResultClick({ - ...requiredParameters, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + resultOffset: 1, + }), + ).to.equal(true); }); - it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { + it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('result_offset'); + expect(requestParams).to.not.have.property("result_offset"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackQuizResultClick({ - ...requiredParameters, - })).to.equal(true); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + }), + ).to.equal(true); }); - it('Should return an error when resultOffset is not a number', () => { + it("Should return an error when resultOffset is not a number", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - expect(tracker.trackQuizResultClick({ - ...requiredParameters, - resultOffset: 'not-a-number', - })).to.be.an('error'); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + resultOffset: "not-a-number", + }), + ).to.be.an("error"); }); - it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { + it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('result_page'); - expect(requestParams).to.have.property('result_offset'); + expect(requestParams).to.have.property("result_page"); + expect(requestParams).to.have.property("result_offset"); // Response - expect(error).to.have.property('message').to.equal('Invalid parameters'); + expect(error) + .to.have.property("message") + .to.equal("Invalid parameters"); done(); }); - expect(tracker.trackQuizResultClick({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - })).to.equal(true); + expect( + tracker.trackQuizResultClick({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + }), + ).to.equal(true); }); }); - describe('trackQuizConversion', () => { + describe("trackQuizConversion", () => { const requiredParameters = { - quizId: 'coffee-quiz', - quizVersionId: '1231243', - quizSessionId: '13443', - itemName: 'espresso', - itemId: '1123', + quizId: "coffee-quiz", + quizVersionId: "1231243", + quizSessionId: "13443", + itemName: "espresso", + itemId: "1123", }; const optionalParameters = { - variationId: '123', - section: 'Products', - type: 'add_to_cart', - revenue: '1.0', + variationId: "123", + section: "Products", + type: "add_to_cart", + revenue: "1.0", isCustomType: false, - displayName: 'name', + displayName: "name", }; - it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { + it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - quiz_id: 'coffee-quiz', - quiz_version_id: '1231243', - quiz_session_id: '13443', - item_name: 'espresso', - item_id: '1123', + quiz_id: "coffee-quiz", + quiz_version_id: "1231243", + quiz_session_id: "13443", + item_name: "espresso", + item_id: "1123", }; - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(snakeCaseParameters.quiz_id); - expect(requestParams).to.have.property('quiz_version_id').to.equal(snakeCaseParameters.quiz_version_id); - expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); - expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(snakeCaseParameters.quiz_id); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(snakeCaseParameters.quiz_version_id); + expect(requestParams) + .to.have.property("item_name") + .to.equal(snakeCaseParameters.item_name); + expect(requestParams) + .to.have.property("item_id") + .to.equal(snakeCaseParameters.item_id); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9345,32 +10604,40 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(snakeCaseParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); - expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("quiz_id") + .to.equal(requiredParameters.quizId); + expect(requestParams) + .to.have.property("quiz_version_id") + .to.equal(requiredParameters.quizVersionId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9378,24 +10645,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9403,8 +10674,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -9412,16 +10683,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9429,8 +10700,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9438,16 +10709,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9455,8 +10726,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9464,16 +10735,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9481,139 +10754,186 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('type').to.equal(optionalParameters.type); - expect(requestParams).to.have.property('revenue').to.equal(optionalParameters.revenue); - expect(requestParams).to.have.property('is_custom_type').to.equal(optionalParameters.isCustomType); - expect(requestParams).to.have.property('display_name').to.equal(optionalParameters.displayName); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("type") + .to.equal(optionalParameters.type); + expect(requestParams) + .to.have.property("revenue") + .to.equal(optionalParameters.revenue); + expect(requestParams) + .to.have.property("is_custom_type") + .to.equal(optionalParameters.isCustomType); + expect(requestParams) + .to.have.property("display_name") + .to.equal(optionalParameters.displayName); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackQuizConversion({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackQuizConversion({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid quizId is provided', () => { + it("Should throw an error when invalid quizId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, quizId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, quizId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid quizVersionId is provided', () => { + it("Should throw an error when invalid quizVersionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, quizVersionId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ + ...requiredParameters, + quizVersionId: 1, + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid quizSessionId is provided', () => { + it("Should throw an error when invalid quizSessionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, quizSessionId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ + ...requiredParameters, + quizSessionId: 1, + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid itemId is provided', () => { + it("Should throw an error when invalid itemId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, itemId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, itemId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid itemName is provided', () => { + it("Should throw an error when invalid itemName is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, itemName: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, itemName: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid section is provided', () => { + it("Should throw an error when invalid section is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, section: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, section: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid variationId is provided', () => { + it("Should throw an error when invalid variationId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, variationId: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, variationId: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid type is provided', () => { + it("Should throw an error when invalid type is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, type: 0 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, type: 0 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid revenue is provided', () => { + it("Should throw an error when invalid revenue is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, revenue: 1 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, revenue: 1 }), + ).to.be.an("error"); }); - it('Should throw an error when invalid isCustomType is provided', () => { + it("Should throw an error when invalid isCustomType is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, isCustomType: 'true' })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ + ...requiredParameters, + isCustomType: "true", + }), + ).to.be.an("error"); }); - it('Should throw an error when invalid displayName is provided', () => { + it("Should throw an error when invalid displayName is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion({ ...requiredParameters, displayName: 0 })).to.be.an('error'); + expect( + tracker.trackQuizConversion({ ...requiredParameters, displayName: 0 }), + ).to.be.an("error"); }); - it('Should throw an error when no quizId is provided', () => { + it("Should throw an error when no quizId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an('error'); + expect(tracker.trackQuizConversion(rest)).to.be.an("error"); }); - it('Should throw an error when no quizVersionId is provided', () => { + it("Should throw an error when no quizVersionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizVersionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an('error'); + expect(tracker.trackQuizConversion(rest)).to.be.an("error"); }); - it('Should throw an error when no quizSessionId is provided', () => { + it("Should throw an error when no quizSessionId is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizSessionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an('error'); + expect(tracker.trackQuizConversion(rest)).to.be.an("error"); }); - it('Should throw an error when no itemId nor itemName is provided', () => { + it("Should throw an error when no itemId nor itemName is provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { itemName: _, itemId: __, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an('error'); + expect(tracker.trackQuizConversion(rest)).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion([])).to.be.an('error'); + expect(tracker.trackQuizConversion([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion()).to.be.an('error'); + expect(tracker.trackQuizConversion()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9621,7 +10941,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -9629,8 +10949,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9638,7 +10958,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9646,16 +10966,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9664,21 +10984,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackQuizConversion(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackQuizConversion(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -9687,7 +11009,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -9696,8 +11018,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -9706,16 +11028,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9723,10 +11045,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9734,16 +11056,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9752,32 +11074,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('on', () => { - it('Should throw an error when providing an invalid messageType parameter', () => { + describe("on", () => { + it("Should throw an error when providing an invalid messageType parameter", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.on('invalid')).to.be.an('error'); + expect(tracker.on("invalid")).to.be.an("error"); }); - it('Should throw an error when providing no messageType parameter', () => { + 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', () => { + it("Should throw an error when providing an invalid callback parameter", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.on('success', {})).to.be.an('error'); + expect(tracker.on("success", {})).to.be.an("error"); }); - it('Should throw an error when providing no callback parameter', () => { + it("Should throw an error when providing no callback parameter", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.on('success', null)).to.be.an('error'); + expect(tracker.on("success", null)).to.be.an("error"); }); - it('Should receive a success message when making a request to a valid endpoint', (done) => { + it("Should receive a success message when making a request to a valid endpoint", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9786,81 +11108,83 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { tracker.trackSessionStart(); - tracker.on('success', (response) => { - expect(response).to.have.property('url'); - expect(response).to.have.property('method'); - expect(response).to.have.property('message').to.equal('ok'); + tracker.on("success", (response) => { + expect(response).to.have.property("url"); + expect(response).to.have.property("method"); + expect(response).to.have.property("message").to.equal("ok"); done(); }); }); - it('Should receive an error message when making a request to an endpoint that does not return valid JSON', (done) => { + it("Should receive an error message when making a request to an endpoint that does not return valid JSON", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, - serviceUrl: 'http://constructor.io', + serviceUrl: "http://constructor.io", ...requestQueueOptions, }); tracker.trackSessionStart(); - tracker.on('error', (response) => { - expect(response).to.have.property('url'); - expect(response).to.have.property('method'); - expect(response).to.have.property('message'); + tracker.on("error", (response) => { + expect(response).to.have.property("url"); + expect(response).to.have.property("method"); + expect(response).to.have.property("message"); done(); }); }); - it('Should receive an error message when making a request to an invalid endpoint', (done) => { + it("Should receive an error message when making a request to an invalid endpoint", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, - serviceUrl: 'invalid', + serviceUrl: "invalid", ...requestQueueOptions, }); tracker.trackSessionStart(); - tracker.on('error', (response) => { - expect(response).to.have.property('url'); - expect(response).to.have.property('method'); - expect(response).to.have.property('message'); + tracker.on("error", (response) => { + expect(response).to.have.property("url"); + expect(response).to.have.property("method"); + expect(response).to.have.property("message"); done(); }); }); }); - describe('trackAgentSubmit', () => { - const requiredParameters = { intent: 'Show me cookie recipes' }; + describe("trackAgentSubmit", () => { + const requiredParameters = { intent: "Show me cookie recipes" }; const optionalParameters = { - section: 'Products', - threadId: 'thread-123', + section: "Products", + threadId: "thread-1234", }; - it('Should respond with a valid response when intent and required parameters are provided', (done) => { + it("Should respond with a valid response when intent and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9868,24 +11192,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9893,8 +11221,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -9902,16 +11230,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9919,8 +11247,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9928,16 +11256,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9945,8 +11273,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9954,16 +11282,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -9971,44 +11301,51 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); - expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAgentSubmit({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSubmit()).to.be.an('error'); + expect(tracker.trackAgentSubmit()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSubmit()).to.be.an('error'); + expect(tracker.trackAgentSubmit()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10016,7 +11353,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -10024,8 +11361,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10033,7 +11370,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10041,16 +11378,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10059,21 +11396,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAgentSubmit(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -10082,7 +11421,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -10091,8 +11430,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -10101,16 +11440,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10118,10 +11457,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10129,16 +11468,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10147,71 +11486,81 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAgentResultLoadStarted', () => { - const requiredParameters = { intent: 'Show me cookie recipes' }; + describe("trackAgentResultLoadStarted", () => { + const requiredParameters = { intent: "Show me cookie recipes" }; const optionalParameters = { - section: 'Products', - intentResultId: '123451', - threadId: 'thread-123', + section: "Products", + intentResultId: "123451", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -10219,25 +11568,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10245,25 +11596,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10271,63 +11624,78 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); // eslint-disable-next-line max-len - expect(tracker.trackAgentResultLoadStarted({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAgentResultLoadStarted({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadStarted()).to.be.an('error'); + expect(tracker.trackAgentResultLoadStarted()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadStarted()).to.be.an('error'); + expect(tracker.trackAgentResultLoadStarted()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10335,7 +11703,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -10343,16 +11711,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10360,39 +11730,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters, { timeout: 10 })).to.equal(true); - }); + expect( + tracker.trackAgentResultLoadStarted(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); + }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -10401,17 +11777,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAgentResultLoadStarted(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -10420,27 +11798,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10448,90 +11828,107 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( + true, + ); }); }); - describe('trackAgentResultLoadFinished', () => { - const requiredParameters = { intent: 'Show me cookie recipes', searchResultCount: 15 }; + describe("trackAgentResultLoadFinished", () => { + const requiredParameters = { + intent: "Show me cookie recipes", + searchResultCount: 15, + }; const optionalParameters = { - section: 'Products', - intentResultId: '123451', - threadId: 'thread-123', + section: "Products", + intentResultId: "123451", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_result_count').to.equal(requiredParameters.searchResultCount); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_result_count") + .to.equal(requiredParameters.searchResultCount); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -10539,25 +11936,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10565,25 +11964,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10591,63 +11992,78 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); // eslint-disable-next-line max-len - expect(tracker.trackAgentResultLoadFinished({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAgentResultLoadFinished({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadFinished()).to.be.an('error'); + expect(tracker.trackAgentResultLoadFinished()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadFinished()).to.be.an('error'); + expect(tracker.trackAgentResultLoadFinished()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10655,7 +12071,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -10663,16 +12079,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10680,39 +12098,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAgentResultLoadFinished(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -10721,17 +12145,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAgentResultLoadFinished(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -10740,27 +12166,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10768,64 +12196,74 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( + true, + ); }); }); - describe('trackAgentResultClick', () => { + describe("trackAgentResultClick", () => { const requiredParameters = { - intent: 'Show me cookie recipes', - searchResultId: '12341cd', - itemName: 'espresso', - itemId: '1123', + intent: "Show me cookie recipes", + searchResultId: "12341cd", + itemName: "espresso", + itemId: "1123", }; const optionalParameters = { - section: 'Products', - intentResultId: '12312', - variationId: '123123', - threadId: 'thread-123', + section: "Products", + intentResultId: "12312", + variationId: "123123", + threadId: "thread-123", }; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_result_id") + .to.equal(requiredParameters.searchResultId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10833,24 +12271,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10858,8 +12300,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -10867,16 +12309,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10884,8 +12326,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10893,16 +12335,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10910,8 +12352,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10919,16 +12361,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -10936,47 +12380,59 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentResultClick({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackAgentResultClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultClick([])).to.be.an('error'); + expect(tracker.trackAgentResultClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultClick()).to.be.an('error'); + expect(tracker.trackAgentResultClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10984,7 +12440,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -10992,8 +12448,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11001,7 +12457,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11009,16 +12465,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11027,21 +12483,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAgentResultClick(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -11050,17 +12508,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAgentResultClick(requiredParameters)).to.equal( + true, + ); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -11069,16 +12529,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11086,10 +12546,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11097,16 +12557,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11115,63 +12575,69 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAgentResultView', () => { + describe("trackAgentResultView", () => { const requiredParameters = { - intent: 'Show me cookie recipes', + intent: "Show me cookie recipes", numResultsViewed: 5, - searchResultId: '123123123', + searchResultId: "123123123", }; const optionalParameters = { - intentResultId: 'result-id', - section: 'Products', - threadId: 'thread-123', + intentResultId: "result-id", + section: "Products", + threadId: "thread-123", items: [ { - itemId: '123', - variationId: '456', + itemId: "123", + variationId: "456", }, { - itemName: 'product test', - itemId: '789', + itemName: "product test", + itemId: "789", }, ], }; const snakeCaseItems = [ { - item_id: '123', - variation_id: '456', + item_id: "123", + variation_id: "456", }, { - item_name: 'product test', - item_id: '789', + item_name: "product test", + item_id: "789", }, ]; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); - expect(requestParams).to.have.property('num_results_viewed').to.equal(requiredParameters.numResultsViewed); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_result_id") + .to.equal(requiredParameters.searchResultId); + expect(requestParams) + .to.have.property("num_results_viewed") + .to.equal(requiredParameters.numResultsViewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -11179,24 +12645,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -11204,8 +12674,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -11213,16 +12683,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -11230,8 +12700,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11239,16 +12709,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -11256,8 +12728,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11265,16 +12737,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); @@ -11282,46 +12754,59 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAgentResultView({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAgentResultView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultView([])).to.be.an('error'); + expect(tracker.trackAgentResultView([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultView()).to.be.an('error'); + expect(tracker.trackAgentResultView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11329,7 +12814,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -11337,8 +12822,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11346,7 +12831,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11354,16 +12839,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11372,21 +12857,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAgentResultView(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -11395,7 +12882,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -11404,8 +12891,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -11414,16 +12901,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11431,10 +12918,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11442,16 +12929,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11460,39 +12947,49 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAgentSearchSubmit', () => { - const requiredParameters = { intent: 'Show me cookie recipes', searchTerm: 'Flour', searchResultId: '123' }; + describe("trackAgentSearchSubmit", () => { + const requiredParameters = { + intent: "Show me cookie recipes", + searchTerm: "Flour", + searchResultId: "123", + }; const optionalParameters = { - section: 'Products', - intentResultId: '1234', - threadId: 'thread-123', + section: "Products", + intentResultId: "1234", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_term').to.equal(requiredParameters.searchTerm); - expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_term") + .to.equal(requiredParameters.searchTerm); + expect(requestParams) + .to.have.property("search_result_id") + .to.equal(requiredParameters.searchResultId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11500,24 +12997,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11525,8 +13026,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -11534,16 +13035,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11551,8 +13052,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11560,16 +13061,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11577,8 +13078,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11586,16 +13087,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11603,45 +13106,56 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAgentSearchSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAgentSearchSubmit({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSearchSubmit()).to.be.an('error'); + expect(tracker.trackAgentSearchSubmit()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSearchSubmit()).to.be.an('error'); + expect(tracker.trackAgentSearchSubmit()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11649,7 +13163,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -11657,8 +13171,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11666,7 +13180,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11674,16 +13188,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11692,21 +13206,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentSearchSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAgentSearchSubmit(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -11715,17 +13231,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal( + true, + ); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -11734,16 +13252,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11751,10 +13269,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11762,16 +13280,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11780,35 +13298,37 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAssistantSubmit', () => { - const requiredParameters = { intent: 'Show me cookie recipes' }; + describe("trackAssistantSubmit", () => { + const requiredParameters = { intent: "Show me cookie recipes" }; const optionalParameters = { - section: 'Products', + section: "Products", }; - it('Should respond with a valid response when intent and required parameters are provided', (done) => { + it("Should respond with a valid response when intent and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11816,24 +13336,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11841,8 +13365,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -11850,16 +13374,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11867,8 +13391,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11876,16 +13400,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11893,8 +13417,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11902,16 +13426,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11919,43 +13445,48 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property("section").to.equal("Products"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAssistantSubmit({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSubmit()).to.be.an('error'); + expect(tracker.trackAssistantSubmit()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSubmit()).to.be.an('error'); + expect(tracker.trackAssistantSubmit()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11963,7 +13494,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -11971,8 +13502,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -11980,7 +13511,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11988,16 +13519,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -12006,21 +13537,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAssistantSubmit(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12029,7 +13562,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -12038,8 +13571,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -12048,16 +13581,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -12065,10 +13598,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12076,16 +13609,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -12094,70 +13627,80 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe('trackAssistantResultLoadStarted', () => { - const requiredParameters = { intent: 'Show me cookie recipes' }; + describe("trackAssistantResultLoadStarted", () => { + const requiredParameters = { intent: "Show me cookie recipes" }; const optionalParameters = { - section: 'Products', - intentResultId: '123451', + section: "Products", + intentResultId: "123451", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -12165,25 +13708,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12191,25 +13736,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12217,62 +13764,75 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); // eslint-disable-next-line max-len - expect(tracker.trackAssistantResultLoadStarted({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadStarted()).to.be.an('error'); + expect(tracker.trackAssistantResultLoadStarted()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadStarted()).to.be.an('error'); + expect(tracker.trackAssistantResultLoadStarted()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12280,7 +13840,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -12288,16 +13848,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12305,39 +13867,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12346,17 +13914,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -12365,27 +13935,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12393,89 +13965,106 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadStarted(requiredParameters), + ).to.equal(true); }); }); - describe('trackAssistantResultLoadFinished', () => { - const requiredParameters = { intent: 'Show me cookie recipes', searchResultCount: 15 }; + describe("trackAssistantResultLoadFinished", () => { + const requiredParameters = { + intent: "Show me cookie recipes", + searchResultCount: 15, + }; const optionalParameters = { - section: 'Products', - intentResultId: '123451', + section: "Products", + intentResultId: "123451", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_result_count').to.equal(requiredParameters.searchResultCount); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_result_count") + .to.equal(requiredParameters.searchResultCount); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -12483,25 +14072,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12509,25 +14100,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12535,62 +14128,75 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); // eslint-disable-next-line max-len - expect(tracker.trackAssistantResultLoadFinished({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadFinished()).to.be.an('error'); + expect(tracker.trackAssistantResultLoadFinished()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadFinished()).to.be.an('error'); + expect(tracker.trackAssistantResultLoadFinished()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12598,7 +14204,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -12606,16 +14212,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12623,39 +14231,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12664,17 +14278,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -12683,27 +14299,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12711,97 +14329,115 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); + expect( + tracker.trackAssistantResultLoadFinished(requiredParameters), + ).to.equal(true); }); }); - describe('trackAssistantResultClick', () => { + describe("trackAssistantResultClick", () => { const requiredParameters = { - intent: 'Show me cookie recipes', - searchResultId: '12341cd', - itemName: 'espresso', - itemId: '1123', + intent: "Show me cookie recipes", + searchResultId: "12341cd", + itemName: "espresso", + itemId: "1123", }; const optionalParameters = { - section: 'Products', - intentResultId: '12312', - variationId: '123123', + section: "Products", + intentResultId: "12312", + variationId: "123123", }; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_result_id") + .to.equal(requiredParameters.searchResultId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -12809,25 +14445,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12835,25 +14473,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12861,63 +14501,77 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick({ ...requiredParameters, ...optionalParameters })) - .to.equal(true); + expect( + tracker.trackAssistantResultClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultClick([])).to.be.an('error'); + expect(tracker.trackAssistantResultClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultClick()).to.be.an('error'); + expect(tracker.trackAssistantResultClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12925,7 +14579,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -12933,16 +14587,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12950,39 +14606,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAssistantResultClick(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12991,17 +14653,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -13010,27 +14674,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13038,114 +14704,130 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( + true, + ); }); }); - describe('trackAssistantResultView', () => { + describe("trackAssistantResultView", () => { const requiredParameters = { - intent: 'Show me cookie recipes', + intent: "Show me cookie recipes", numResultsViewed: 5, - searchResultId: '123123123', + searchResultId: "123123123", }; const optionalParameters = { - intentResultId: 'result-id', - section: 'Products', + intentResultId: "result-id", + section: "Products", items: [ { - itemId: '123', - variationId: '456', + itemId: "123", + variationId: "456", }, { - itemName: 'product test', - itemId: '789', + itemName: "product test", + itemId: "789", }, ], }; const snakeCaseItems = [ { - item_id: '123', - variation_id: '456', + item_id: "123", + variation_id: "456", }, { - item_name: 'product test', - item_id: '789', + item_name: "product test", + item_id: "789", }, ]; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); - expect(requestParams).to.have.property('num_results_viewed').to.equal(requiredParameters.numResultsViewed); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_result_id") + .to.equal(requiredParameters.searchResultId); + expect(requestParams) + .to.have.property("num_results_viewed") + .to.equal(requiredParameters.numResultsViewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -13153,25 +14835,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13179,25 +14863,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13205,62 +14893,75 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); - expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message'); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("items") + .to.deep.equal(snakeCaseItems); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message"); done(); }); - expect(tracker.trackAssistantResultView({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAssistantResultView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultView([])).to.be.an('error'); + expect(tracker.trackAssistantResultView([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultView()).to.be.an('error'); + expect(tracker.trackAssistantResultView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13268,7 +14969,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -13276,16 +14977,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13293,39 +14996,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAssistantResultView(requiredParameters, { timeout: 10 }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -13334,17 +15041,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); } - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -13353,27 +15062,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13381,90 +15092,110 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( + true, + ); }); }); - describe('trackAssistantSearchSubmit', () => { - const requiredParameters = { intent: 'Show me cookie recipes', searchTerm: 'Flour', searchResultId: '123' }; + describe("trackAssistantSearchSubmit", () => { + const requiredParameters = { + intent: "Show me cookie recipes", + searchTerm: "Flour", + searchResultId: "123", + }; const optionalParameters = { - section: 'Products', - intentResultId: '1234', + section: "Products", + intentResultId: "1234", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); - expect(requestParams).to.have.property('search_term').to.equal(requiredParameters.searchTerm); - expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("intent") + .to.equal(requiredParameters.intent); + expect(requestParams) + .to.have.property("search_term") + .to.equal(requiredParameters.searchTerm); + expect(requestParams) + .to.have.property("search_result_id") + .to.equal(requiredParameters.searchResultId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -13472,25 +15203,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13498,25 +15231,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13524,61 +15259,74 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(requestParams) + .to.have.property("intent_result_id") + .to.equal(optionalParameters.intentResultId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackAssistantSearchSubmit({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSearchSubmit()).to.be.an('error'); + expect(tracker.trackAssistantSearchSubmit()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSearchSubmit()).to.be.an('error'); + expect(tracker.trackAssistantSearchSubmit()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13586,7 +15334,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -13594,16 +15342,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13611,39 +15361,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackAssistantSearchSubmit(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -13652,17 +15408,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -13671,27 +15429,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13699,110 +15459,128 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( + true, + ); }); }); - describe('trackProductInsightsAgentViews', () => { + describe("trackProductInsightsAgentViews", () => { const requiredParameters = { - itemId: '1', - itemName: 'item1', + itemId: "1", + itemName: "item1", questions: [ - { question: 'Why choose this?' }, - { question: 'How is this product made?' }, - { question: 'What are the dimensions of this product?' }, + { question: "Why choose this?" }, + { question: "How is this product made?" }, + { question: "What are the dimensions of this product?" }, ], viewTimespans: [ { - start: '2025-05-19T14:30:00+02:00', - end: '2025-05-19T14:30:05+02:00', + start: "2025-05-19T14:30:00+02:00", + end: "2025-05-19T14:30:05+02:00", }, { - start: '2025-05-19T14:30:10+02:00', - end: '2025-05-19T14:30:15+02:00', + start: "2025-05-19T14:30:10+02:00", + end: "2025-05-19T14:30:15+02:00", }, ], }; const optionalParameters = { - section: 'Products', - variationId: '2', - threadId: 'thread-123', + section: "Products", + variationId: "2", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('questions').to.deep.equal(requiredParameters.questions); - expect(requestParams).to.have.property('view_timespans').to.deep.equal(requiredParameters.viewTimespans); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("questions") + .to.deep.equal(requiredParameters.questions); + expect(requestParams) + .to.have.property("view_timespans") + .to.deep.equal(requiredParameters.viewTimespans); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -13810,25 +15588,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13836,25 +15616,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13862,65 +15644,78 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentViews()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentViews()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentViews()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentViews()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13928,7 +15723,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -13936,16 +15731,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13953,39 +15750,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -13994,17 +15797,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -14013,27 +15818,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14041,99 +15848,115 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentViews(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentView', () => { + describe("trackProductInsightsAgentView", () => { const requiredParameters = { - itemId: '1', - itemName: 'item1', + itemId: "1", + itemName: "item1", questions: [ - { question: 'Why choose this?' }, - { question: 'How is this product made?' }, - { question: 'What are the dimensions of this product?' }, + { question: "Why choose this?" }, + { question: "How is this product made?" }, + { question: "What are the dimensions of this product?" }, ], }; const optionalParameters = { - section: 'Products', - variationId: '2', - threadId: 'thread-123', + section: "Products", + variationId: "2", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('questions').to.deep.equal(requiredParameters.questions); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("questions") + .to.deep.equal(requiredParameters.questions); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14141,25 +15964,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14167,25 +15992,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14193,65 +16020,78 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentView()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14259,7 +16099,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -14267,16 +16107,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14284,39 +16126,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -14325,17 +16173,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -14344,27 +16194,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14372,65 +16224,73 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentView(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentOutOfView', () => { - const requiredParameters = { itemId: '1', itemName: 'item1' }; + describe("trackProductInsightsAgentOutOfView", () => { + const requiredParameters = { itemId: "1", itemName: "item1" }; const optionalParameters = { - section: 'Products', - variationId: '2', - threadId: 'thread-123', + section: "Products", + variationId: "2", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { - const segments = ['foo', 'bar']; + it("Should send along document_referrer and canonical_url query param", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14438,26 +16298,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14465,25 +16331,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14491,25 +16359,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14517,65 +16387,78 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14583,7 +16466,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -14591,16 +16474,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14608,39 +16493,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -14649,17 +16540,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -14668,27 +16561,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14696,90 +16591,104 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentOutOfView(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentFocus', () => { - const requiredParameters = { itemId: '1', itemName: 'item1' }; + describe("trackProductInsightsAgentFocus", () => { + const requiredParameters = { itemId: "1", itemName: "item1" }; const optionalParameters = { - section: 'Products', - variationId: '2', - threadId: 'thread-123', + section: "Products", + variationId: "2", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14787,25 +16696,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14813,25 +16724,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14839,65 +16752,78 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentFocus()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentFocus()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentFocus()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentFocus()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14905,7 +16831,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -14913,16 +16839,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14930,39 +16858,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -14971,17 +16905,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -14990,27 +16926,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15018,92 +16956,112 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentFocus(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentQuestionClick', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; + describe("trackProductInsightsAgentQuestionClick", () => { + const requiredParameters = { + itemId: "1", + itemName: "item1", + question: "Why choose this?", + }; const optionalParameters = { - section: 'Products', - variationId: '2', - threadId: 'thread-123', - questionTopic: 'pricing', + section: "Products", + variationId: "2", + threadId: "thread-123", + questionTopic: "pricing", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("question") + .to.equal(requiredParameters.question); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -15111,25 +17069,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15137,25 +17097,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15163,66 +17125,85 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); - expect(bodyParams).to.have.property('question_topic').to.equal(optionalParameters.questionTopic); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); + expect(bodyParams) + .to.have.property("question_topic") + .to.equal(optionalParameters.questionTopic); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an( + "error", + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an( + "error", + ); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15230,7 +17211,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -15238,16 +17219,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15255,39 +17238,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -15296,17 +17285,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -15315,27 +17306,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15343,92 +17336,112 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionClick(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentQuestionSubmit', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; + describe("trackProductInsightsAgentQuestionSubmit", () => { + const requiredParameters = { + itemId: "1", + itemName: "item1", + question: "Why choose this?", + }; const optionalParameters = { - section: 'Products', - variationId: '2', - threadId: 'thread-123', - questionTopic: 'pricing', + section: "Products", + variationId: "2", + threadId: "thread-123", + questionTopic: "pricing", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("question") + .to.equal(requiredParameters.question); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -15436,25 +17449,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15462,25 +17477,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15488,66 +17505,85 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); - expect(bodyParams).to.have.property('question_topic').to.equal(optionalParameters.questionTopic); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); + expect(bodyParams) + .to.have.property("question_topic") + .to.equal(optionalParameters.questionTopic); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an( + "error", + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an( + "error", + ); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15555,7 +17591,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -15563,16 +17599,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15580,39 +17618,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -15621,17 +17665,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -15640,27 +17686,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15668,95 +17716,124 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentAnswerView', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!' }; + describe("trackProductInsightsAgentAnswerView", () => { + const requiredParameters = { + itemId: "1", + itemName: "item1", + question: "Why choose this?", + answerText: "This product is awesome!", + }; const optionalParameters = { - section: 'Products', - variationId: '2', - qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', - threadId: 'thread-123', - items: [{ itemId: 'rec1', itemName: 'Rec Product 1' }, { itemId: 'rec2', itemName: 'Rec Product 2' }], - followUpQuestions: [{ value: 'What about size?' }, { value: 'Is it machine washable?' }], + section: "Products", + variationId: "2", + qnaResultId: "0daf0015-fc29-4727-9140-8d5313a1902c", + threadId: "thread-123", + items: [ + { itemId: "rec1", itemName: "Rec Product 1" }, + { itemId: "rec2", itemName: "Rec Product 2" }, + ], + followUpQuestions: [ + { value: "What about size?" }, + { value: "Is it machine washable?" }, + ], }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); - expect(requestParams).to.have.property('answer_text').to.equal(requiredParameters.answerText); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("question") + .to.equal(requiredParameters.question); + expect(requestParams) + .to.have.property("answer_text") + .to.equal(requiredParameters.answerText); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -15764,25 +17841,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15790,25 +17869,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15816,71 +17897,98 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); - expect(bodyParams).to.have.property('items').to.be.an('array').with.lengthOf(2); - expect(bodyParams.items[0]).to.have.property('item_id').to.equal('rec1'); - expect(bodyParams.items[0]).to.have.property('item_name').to.equal('Rec Product 1'); - expect(bodyParams).to.have.property('follow_up_questions').to.be.an('array').with.lengthOf(2); - expect(bodyParams.follow_up_questions[0]).to.have.property('value').to.equal('What about size?'); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("qna_result_id") + .to.equal(optionalParameters.qnaResultId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); + expect(bodyParams) + .to.have.property("items") + .to.be.an("array") + .with.lengthOf(2); + expect(bodyParams.items[0]) + .to.have.property("item_id") + .to.equal("rec1"); + expect(bodyParams.items[0]) + .to.have.property("item_name") + .to.equal("Rec Product 1"); + expect(bodyParams) + .to.have.property("follow_up_questions") + .to.be.an("array") + .with.lengthOf(2); + expect(bodyParams.follow_up_questions[0]) + .to.have.property("value") + .to.equal("What about size?"); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15888,7 +17996,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -15896,16 +18004,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15913,39 +18023,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -15954,17 +18070,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -15973,27 +18091,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16001,92 +18121,112 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerView(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentAnswerFeedback', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up' }; + describe("trackProductInsightsAgentAnswerFeedback", () => { + const requiredParameters = { + itemId: "1", + itemName: "item1", + feedbackLabel: "thumbs_up", + }; const optionalParameters = { - section: 'Products', - variationId: '2', - qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', - threadId: 'thread-123', + section: "Products", + variationId: "2", + qnaResultId: "0daf0015-fc29-4727-9140-8d5313a1902c", + threadId: "thread-123", }; - it('Should respond with a valid response when term and required parameters are provided', (done) => { + it("Should respond with a valid response when term and required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('feedback_label').to.equal(requiredParameters.feedbackLabel); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("feedback_label") + .to.equal(requiredParameters.feedbackLabel); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should send along document_referrer and canonical_url query param', (done) => { + it("Should send along document_referrer and canonical_url query param", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -16094,25 +18234,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16120,25 +18262,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16146,65 +18290,84 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("qna_result_id") + .to.equal(optionalParameters.qnaResultId); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an( + "error", + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an( + "error", + ); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16212,7 +18375,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -16220,16 +18383,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16237,39 +18402,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -16278,17 +18449,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); } - it('Should properly encode query parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should properly encode query parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -16297,27 +18470,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16325,115 +18500,151 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), + ).to.equal(true); }); }); - describe('trackProductInsightsAgentResultClick', () => { - const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', seedItemId: 'seed-1' }; + describe("trackProductInsightsAgentResultClick", () => { + const requiredParameters = { + itemId: "1", + itemName: "item1", + question: "Why choose this?", + seedItemId: "seed-1", + }; const optionalParameters = { - section: 'Products', - variationId: '2', + section: "Products", + variationId: "2", position: 1, - seedItemName: 'Seed Product', - seedVariationId: 'seed-var-1', - threadId: 'thread-123', - qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', + seedItemName: "Seed Product", + seedVariationId: "seed-var-1", + threadId: "thread-123", + qnaResultId: "0daf0015-fc29-4727-9140-8d5313a1902c", }; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); - expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); - expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); - expect(requestParams).to.have.property('seed_item_id').to.equal(requiredParameters.seedItemId); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("item_id") + .to.equal(requiredParameters.itemId); + expect(requestParams) + .to.have.property("item_name") + .to.equal(requiredParameters.itemName); + expect(requestParams) + .to.have.property("question") + .to.equal(requiredParameters.question); + expect(requestParams) + .to.have.property("seed_item_id") + .to.equal(requiredParameters.seedItemId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentResultClick(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); - expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); - expect(bodyParams).to.have.property('position').to.equal(optionalParameters.position); - expect(bodyParams).to.have.property('seed_item_name').to.equal(optionalParameters.seedItemName); - expect(bodyParams).to.have.property('seed_variation_id').to.equal(optionalParameters.seedVariationId); - expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); - expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); - - // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(requestParams) + .to.have.property("section") + .to.equal(optionalParameters.section); + expect(bodyParams) + .to.have.property("variation_id") + .to.equal(optionalParameters.variationId); + expect(bodyParams) + .to.have.property("position") + .to.equal(optionalParameters.position); + expect(bodyParams) + .to.have.property("seed_item_name") + .to.equal(optionalParameters.seedItemName); + expect(bodyParams) + .to.have.property("seed_variation_id") + .to.equal(optionalParameters.seedVariationId); + expect(bodyParams) + .to.have.property("thread_id") + .to.equal(optionalParameters.threadId); + expect(bodyParams) + .to.have.property("qna_result_id") + .to.equal(optionalParameters.qnaResultId); + + // Response + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentResultClick( - { ...requiredParameters, ...optionalParameters }, - )).to.equal(true); + expect( + tracker.trackProductInsightsAgentResultClick({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentResultClick()).to.be.an('error'); + expect(tracker.trackProductInsightsAgentResultClick()).to.be.an("error"); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentResultClick('invalid')).to.be.an('error'); + expect(tracker.trackProductInsightsAgentResultClick("invalid")).to.be.an( + "error", + ); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -16441,25 +18652,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('us').to.deep.equal(segments); + expect(requestParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentResultClick(requiredParameters), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16467,39 +18680,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentResultClick(requiredParameters), + ).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentResultClick(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackProductInsightsAgentResultClick(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -16508,126 +18727,143 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); + expect( + tracker.trackProductInsightsAgentResultClick(requiredParameters), + ).to.equal(true); }); } }); - describe('trackResultsImpressionView', () => { + describe("trackResultsImpressionView", () => { const requiredParameters = { items: [ { - itemId: '1', - itemName: 'Item 1', - variationId: 'VAR-1', - slCampaignId: 'campaign-123', - slCampaignOwner: 'owner-abc', + itemId: "1", + itemName: "Item 1", + variationId: "VAR-1", + slCampaignId: "campaign-123", + slCampaignOwner: "owner-abc", }, { - itemId: '2', - itemName: 'Item 2', - variationId: 'VAR-2', - slCampaignId: 'campaign-456', - slCampaignOwner: 'owner-def', + itemId: "2", + itemName: "Item 2", + variationId: "VAR-2", + slCampaignId: "campaign-456", + slCampaignOwner: "owner-def", }, ], }; const optionalParameters = { - filterName: 'category', - filterValue: 'shoes', - searchTerm: 'red shoes', + filterName: "category", + filterValue: "shoes", + searchTerm: "red shoes", }; - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property('items').to.deep.equal([ - { - item_id: '1', - item_name: 'Item 1', - variation_id: 'VAR-1', - sl_campaign_id: 'campaign-123', - sl_campaign_owner: 'owner-abc', - }, - { - item_id: '2', - item_name: 'Item 2', - variation_id: 'VAR-2', - sl_campaign_id: 'campaign-456', - sl_campaign_owner: 'owner-def', - }, - ]); + expect(bodyParams) + .to.have.property("items") + .to.deep.equal([ + { + item_id: "1", + item_name: "Item 1", + variation_id: "VAR-1", + sl_campaign_id: "campaign-123", + sl_campaign_owner: "owner-abc", + }, + { + item_id: "2", + item_name: "Item 2", + variation_id: "VAR-2", + sl_campaign_id: "campaign-456", + sl_campaign_owner: "owner-def", + }, + ]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property('items'); - expect(bodyParams).to.have.property('filter_name').to.equal(optionalParameters.filterName); - expect(bodyParams).to.have.property('filter_value').to.equal(optionalParameters.filterValue); - expect(bodyParams).to.have.property('search_term').to.equal(optionalParameters.searchTerm); + expect(bodyParams).to.have.property("items"); + expect(bodyParams) + .to.have.property("filter_name") + .to.equal(optionalParameters.filterName); + expect(bodyParams) + .to.have.property("filter_value") + .to.equal(optionalParameters.filterValue); + expect(bodyParams) + .to.have.property("search_term") + .to.equal(optionalParameters.searchTerm); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView({ ...requiredParameters, ...optionalParameters })).to.equal(true); + expect( + tracker.trackResultsImpressionView({ + ...requiredParameters, + ...optionalParameters, + }), + ).to.equal(true); }); - it('Should respond with a valid response when required parameters and segments are provided', (done) => { - const segments = ['foo', 'bar']; + it("Should respond with a valid response when required parameters and segments are provided", (done) => { + const segments = ["foo", "bar"]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -16635,29 +18871,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property('us').to.deep.equal(segments); + expect(bodyParams).to.have.property("us").to.deep.equal(segments); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and userId are provided', (done) => { - const userId = 'user-id'; + it("Should respond with a valid response when required parameters and userId are provided", (done) => { + const userId = "user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16665,29 +18903,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property('ui').to.equal(userId); + expect(bodyParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); - it('Should respond with a valid response when required parameters and testCells are provided', (done) => { - const testCells = { foo: 'bar' }; + it("Should respond with a valid response when required parameters and testCells are provided", (done) => { + const testCells = { foo: "bar" }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16695,28 +18935,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(bodyParams) + .to.have.property(`ef-${Object.keys(testCells)[0]}`) + .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16724,7 +18968,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body @@ -16732,20 +18976,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(bodyParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16753,85 +18999,99 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.not.have.property('origin_referrer'); + expect(bodyParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); - tracker.on('error', (error) => { + tracker.on("error", (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); - it('Should throw an error when invalid parameters are provided', () => { + it("Should throw an error when invalid parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView([])).to.be.an('error'); + expect(tracker.trackResultsImpressionView([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { + it("Should throw an error when no parameters are provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView()).to.be.an('error'); + expect(tracker.trackResultsImpressionView()).to.be.an("error"); }); - it('Should throw an error when items is not provided', () => { + it("Should throw an error when items is not provided", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({})).to.be.an('error'); + expect(tracker.trackResultsImpressionView({})).to.be.an("error"); }); - it('Should throw an error when items is an empty array', () => { + it("Should throw an error when items is an empty array", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({ items: [] })).to.be.an('error'); + expect(tracker.trackResultsImpressionView({ items: [] })).to.be.an( + "error", + ); }); - it('Should throw an error when an item is missing itemId', () => { + it("Should throw an error when an item is missing itemId", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({ items: [{ itemName: 'Shoe' }] })).to.be.an('error'); + expect( + tracker.trackResultsImpressionView({ items: [{ itemName: "Shoe" }] }), + ).to.be.an("error"); }); - it('Should throw an error when an item is missing itemName', () => { + it("Should throw an error when an item is missing itemName", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({ items: [{ itemId: '1' }] })).to.be.an('error'); + expect( + tracker.trackResultsImpressionView({ items: [{ itemId: "1" }] }), + ).to.be.an("error"); }); - it('Should throw an error when items contains non-object entries', () => { + it("Should throw an error when items contains non-object entries", () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({ items: ['string'] })).to.be.an('error'); + expect( + tracker.trackResultsImpressionView({ items: ["string"] }), + ).to.be.an("error"); }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackResultsImpressionView(requiredParameters, { timeout: 10 })).to.equal(true); + expect( + tracker.trackResultsImpressionView(requiredParameters, { + timeout: 10, + }), + ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -16840,17 +19100,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( + true, + ); }); } }); - describe('trackMediaImpressionView', () => { + describe("trackMediaImpressionView", () => { let requiredParameters; const optionalParameters = { @@ -16858,7 +19120,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; before(async () => { - const response = await fetch(`https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`); + const response = await fetch( + `https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`, + ); const data = await response.json(); const ad = data.display_ads[testPlacementId]; requiredParameters = { @@ -16867,36 +19131,40 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); + expect(requestParams) + .to.have.property("document_referrer") + .to.equal(referrer); expect(requestParams) - .to.have.property('banner_ad_id') + .to.have.property("banner_ad_id") .to.equal(requiredParameters.bannerAdId); expect(requestParams) - .to.have.property('placement_id') + .to.have.property("placement_id") .to.equal(requiredParameters.placementId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -16906,59 +19174,64 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; expect(requestParams) - .to.have.property('analytics_tags') + .to.have.property("analytics_tags") .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); expect( - tracker.trackMediaImpressionView( - { ...requiredParameters, ...optionalParameters }, - ), + tracker.trackMediaImpressionView({ + ...requiredParameters, + ...optionalParameters, + }), ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { - const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); + it("Should throw an error when invalid parameters are provided", () => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKeyWithAdPlacements, + }); - expect(tracker.trackMediaImpressionView([])).to.be.an('error'); + expect(tracker.trackMediaImpressionView([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { - const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); + it("Should throw an error when no parameters are provided", () => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKeyWithAdPlacements, + }); - expect(tracker.trackMediaImpressionView()).to.be.an('error'); + expect(tracker.trackMediaImpressionView()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: true, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -16966,8 +19239,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -16977,25 +19250,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: false, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -17005,27 +19278,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, userId, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -17036,14 +19309,14 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -17053,17 +19326,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", networkParameters: { timeout: 20, }, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -17075,7 +19348,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { } }); - describe('trackMediaImpressionClick', () => { + describe("trackMediaImpressionClick", () => { let requiredParameters; const optionalParameters = { @@ -17083,7 +19356,9 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; before(async () => { - const response = await fetch(`https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`); + const response = await fetch( + `https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`, + ); const data = await response.json(); const ad = data.display_ads[testPlacementId]; @@ -17093,36 +19368,40 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; }); - it('Should respond with a valid response when required parameters are provided', (done) => { + it("Should respond with a valid response when required parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('key'); - expect(requestParams).to.have.property('i'); - expect(requestParams).to.have.property('s'); - expect(requestParams).to.have.property('c').to.equal(clientVersion); - expect(requestParams).to.have.property('_dt'); - expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); - expect(requestParams).to.have.property('document_referrer').to.equal(referrer); + expect(requestParams).to.have.property("key"); + expect(requestParams).to.have.property("i"); + expect(requestParams).to.have.property("s"); + expect(requestParams).to.have.property("c").to.equal(clientVersion); + expect(requestParams).to.have.property("_dt"); + expect(requestParams) + .to.have.property("canonical_url") + .to.equal(canonicalUrl); expect(requestParams) - .to.have.property('banner_ad_id') + .to.have.property("document_referrer") + .to.equal(referrer); + expect(requestParams) + .to.have.property("banner_ad_id") .to.equal(requiredParameters.bannerAdId); expect(requestParams) - .to.have.property('placement_id') + .to.have.property("placement_id") .to.equal(requiredParameters.placementId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -17132,59 +19411,64 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it('Should respond with a valid response when required and optional parameters are provided', (done) => { + it("Should respond with a valid response when required and optional parameters are provided", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; expect(requestParams) - .to.have.property('analytics_tags') + .to.have.property("analytics_tags") .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); expect( - tracker.trackMediaImpressionClick( - { ...requiredParameters, ...optionalParameters }, - ), + tracker.trackMediaImpressionClick({ + ...requiredParameters, + ...optionalParameters, + }), ).to.equal(true); }); - it('Should throw an error when invalid parameters are provided', () => { - const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); + it("Should throw an error when invalid parameters are provided", () => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKeyWithAdPlacements, + }); - expect(tracker.trackMediaImpressionClick([])).to.be.an('error'); + expect(tracker.trackMediaImpressionClick([])).to.be.an("error"); }); - it('Should throw an error when no parameters are provided', () => { - const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); + it("Should throw an error when no parameters are provided", () => { + const { tracker } = new ConstructorIO({ + apiKey: testApiKeyWithAdPlacements, + }); - expect(tracker.trackMediaImpressionClick()).to.be.an('error'); + expect(tracker.trackMediaImpressionClick()).to.be.an("error"); }); - it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { + it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: true, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -17192,8 +19476,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -17203,25 +19487,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { + it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: false, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property('origin_referrer'); + expect(requestParams).to.not.have.property("origin_referrer"); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -17231,27 +19515,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it('Should not encode body parameters', (done) => { - const specialCharacters = '+[]&'; + it("Should not encode body parameters", (done) => { + const specialCharacters = "+[]&"; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, userId, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userId); + expect(requestParams).to.have.property("ui").to.equal(userId); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); @@ -17262,34 +19546,36 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it('Should be rejected when network request timeout is provided and reached', (done) => { + it("Should be rejected when network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); expect( - tracker.trackMediaImpressionClick(requiredParameters, { timeout: 10 }), + tracker.trackMediaImpressionClick(requiredParameters, { + timeout: 10, + }), ).to.equal(true); }); - it('Should be rejected when global network request timeout is provided and reached', (done) => { + it("Should be rejected when global network request timeout is provided and reached", (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", networkParameters: { timeout: 20, }, ...requestQueueOptions, }); - tracker.on('error', ({ message }) => { + tracker.on("error", ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -17300,28 +19586,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it('Should properly transform non-breaking spaces in parameters', (done) => { - const breakingSpaces = '   '; + it("Should properly transform non-breaking spaces in parameters", (done) => { + const breakingSpaces = "   "; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = 'user-id user-id'; + const userIdExpected = "user-id user-id"; const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, userId, - mediaServiceUrl: 'https://media-cnstrc.com', + mediaServiceUrl: "https://media-cnstrc.com", fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on('success', (responseParams) => { + tracker.on("success", (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property('ui').to.equal(userIdExpected); + expect(requestParams).to.have.property("ui").to.equal(userIdExpected); // Response - expect(responseParams).to.have.property('method').to.equal('POST'); - expect(responseParams).to.have.property('message').to.equal('ok'); + expect(responseParams).to.have.property("method").to.equal("POST"); + expect(responseParams).to.have.property("message").to.equal("ok"); done(); }); From adfa31916551de2ad939286a502f15c215c62311 Mon Sep 17 00:00:00 2001 From: vishnu Date: Tue, 11 Aug 2026 18:06:27 +0530 Subject: [PATCH 3/3] revert format on save --- spec/src/modules/tracker.js | 12296 ++++++++++++++-------------------- 1 file changed, 5005 insertions(+), 7291 deletions(-) diff --git a/spec/src/modules/tracker.js b/spec/src/modules/tracker.js index 2578a94e..54491386 100644 --- a/spec/src/modules/tracker.js +++ b/spec/src/modules/tracker.js @@ -1,16 +1,16 @@ /* eslint-disable no-unused-expressions, import/no-unresolved */ -const dotenv = require("dotenv"); -const chai = require("chai"); -const chaiAsPromised = require("chai-as-promised"); -const sinon = require("sinon"); -const sinonChai = require("sinon-chai"); -const cloneDeep = require("lodash.clonedeep"); -const store = require("../../../test/utils/store"); // eslint-disable-line import/extensions -const helpers = require("../../mocha.helpers"); -const clientHelpers = require("../../../src/utils/helpers"); -const jsdom = require("../utils/jsdom-global"); -const { addOrderIdRecord } = require("../../../src/utils/helpers"); -let ConstructorIO = require("../../../test/constructorio"); // eslint-disable-line import/extensions +const dotenv = require('dotenv'); +const chai = require('chai'); +const chaiAsPromised = require('chai-as-promised'); +const sinon = require('sinon'); +const sinonChai = require('sinon-chai'); +const cloneDeep = require('lodash.clonedeep'); +const store = require('../../../test/utils/store'); // eslint-disable-line import/extensions +const helpers = require('../../mocha.helpers'); +const clientHelpers = require('../../../src/utils/helpers'); +const jsdom = require('../utils/jsdom-global'); +const { addOrderIdRecord } = require('../../../src/utils/helpers'); +let ConstructorIO = require('../../../test/constructorio'); // eslint-disable-line import/extensions chai.use(chaiAsPromised); chai.use(sinonChai); @@ -18,39 +18,29 @@ dotenv.config(); const testApiKey = process.env.TEST_REQUEST_API_KEY; const testApiKeyWithAdPlacements = process.env.TEST_MEDIA_REQUEST_API_KEY; -const clientVersion = "cio-mocha"; +const clientVersion = 'cio-mocha'; const delayBetweenTests = 50; -const bundled = process.env.BUNDLED === "true"; -const skipNetworkTimeoutTests = - process.env.SKIP_NETWORK_TIMEOUT_TESTS === "true"; -const bundledDescriptionSuffix = bundled ? " - Bundled" : ""; -const timeoutRejectionMessage = "AbortError: This operation was aborted"; -const testAnalyticsTag = { param1: "test", param2: "test2" }; -const utmParameters = - "utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1"; +const bundled = process.env.BUNDLED === 'true'; +const skipNetworkTimeoutTests = process.env.SKIP_NETWORK_TIMEOUT_TESTS === 'true'; +const bundledDescriptionSuffix = bundled ? ' - Bundled' : ''; +const timeoutRejectionMessage = 'AbortError: This operation was aborted'; +const testAnalyticsTag = { param1: 'test', param2: 'test2' }; +const utmParameters = 'utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1'; const url = `http://localhost.test/path/name?query=term&category=cat&${utmParameters}`; -const referrer = "https://www.google.com/"; -const canonicalUrl = "https://localhost/"; -const testPlacementId = "home"; +const referrer = 'https://www.google.com/'; +const canonicalUrl = 'https://localhost/'; +const testPlacementId = 'home'; function validateOriginReferrer(requestParams) { - expect(requestParams) - .to.have.property("origin_referrer") - .to.contain("localhost.test/path/name"); - expect(requestParams) - .to.have.property("origin_referrer") - .to.contain("utm_source=attentive"); - expect(requestParams) - .to.have.property("origin_referrer") - .to.contain("utm_medium=sms"); - expect(requestParams) - .to.have.property("origin_referrer") - .to.contain("utm_campaign=campaign_1"); + expect(requestParams).to.have.property('origin_referrer').to.contain('localhost.test/path/name'); + expect(requestParams).to.have.property('origin_referrer').to.contain('utm_source=attentive'); + expect(requestParams).to.have.property('origin_referrer').to.contain('utm_medium=sms'); + expect(requestParams).to.have.property('origin_referrer').to.contain('utm_campaign=campaign_1'); } function createLongUrl(length) { - const baseUrl = "https://constructor.io/product/KMH876?a="; - return `${baseUrl}${"a".repeat(length - baseUrl.length)}`; + const baseUrl = 'https://constructor.io/product/KMH876?a='; + return `${baseUrl}${'a'.repeat(length - baseUrl.length)}`; } describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { @@ -65,7 +55,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { beforeEach(() => { cleanup = jsdom(jsdomOptions); helpers.clearStorage(); - store.session.set("_constructorio_is_human", true); + store.session.set('_constructorio_is_human', true); fetchSpy = sinon.spy(fetch); global.CLIENT_VERSION = clientVersion; @@ -74,7 +64,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { if (bundled) { // store2 doesn't seem to maintain the `window` context for bundled version - set manually window.sessionStorage.clear(); - window.sessionStorage.setItem("_constructorio_is_human", true); + window.sessionStorage.setItem('_constructorio_is_human', true); ConstructorIO = window.ConstructorioClient; } @@ -91,29 +81,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { setTimeout(done, delayBetweenTests); }); - describe("trackSessionStart", () => { - it("V2 Should respond with a valid response", (done) => { + describe('trackSessionStart', () => { + it('V2 Should respond with a valid response', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -121,31 +111,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStartV2()).to.equal(true); }); - it("Should respond with a valid response", (done) => { + it('Should respond with a valid response', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams) - .to.have.property("action") - .to.equal("session_start"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('action').to.equal('session_start'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -153,8 +141,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should respond with a valid response with segments", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response with segments', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -162,16 +150,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -179,8 +167,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should respond with a valid response with userId", (done) => { - const userId = "user-id"; + it('Should respond with a valid response with userId', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -188,16 +176,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -205,28 +193,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -234,14 +218,14 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is not defined", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is not defined', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -249,8 +233,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -258,7 +242,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -266,7 +250,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -274,8 +258,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -283,7 +267,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -291,16 +275,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -308,8 +292,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should respond with a valid response with testCells", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response with testCells', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -317,18 +301,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -336,11 +318,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should respond with a valid response with multiple testCells", (done) => { + it('Should respond with a valid response with multiple testCells', (done) => { const testCells = { - foo: "bar", - bar: "foo", - far: "boo", + foo: 'bar', + bar: 'foo', + far: 'boo', }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -349,24 +331,18 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[1]}`) - .to.equal(Object.values(testCells)[1]); - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[2]}`) - .to.equal(Object.values(testCells)[2]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[1]}`).to.equal(Object.values(testCells)[1]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[2]}`).to.equal(Object.values(testCells)[2]); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -374,8 +350,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should only include valid string testCells in request params", (done) => { - const testCells = { valid: "bar", invalid: null, numVal: 123 }; + it('Should only include valid string testCells in request params', (done) => { + const testCells = { valid: 'bar', invalid: null, numVal: 123 }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -383,13 +359,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ef-valid").to.equal("bar"); - expect(requestParams).to.not.have.property("ef-invalid"); - expect(requestParams).to.not.have.property("ef-numVal"); + expect(requestParams).to.have.property('ef-valid').to.equal('bar'); + expect(requestParams).to.not.have.property('ef-invalid'); + expect(requestParams).to.not.have.property('ef-numVal'); done(); }); @@ -398,13 +374,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -412,7 +388,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart({ timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -421,7 +397,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -430,8 +406,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -440,16 +416,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -457,10 +433,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const nonBreakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const nonBreakingSpaces = '   '; const userId = `user-id ${nonBreakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -468,16 +444,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -485,12 +461,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should include window globals in tracking requests when useWindowParameters is true", (done) => { - window.cnstrc = { - userId: "window-user-id", - testCells: { exp: "var" }, - userSegments: ["seg1", "seg2"], - }; + it('Should include window globals in tracking requests when useWindowParameters is true', (done) => { + window.cnstrc = { userId: 'window-user-id', testCells: { exp: 'var' }, userSegments: ['seg1', 'seg2'] }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, useWindowParameters: true, @@ -498,17 +470,12 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { try { - const requestedUrlParams = - helpers.extractUrlParamsFromFetch(fetchSpy); - expect(requestedUrlParams) - .to.have.property("ui") - .to.equal("window-user-id"); - expect(requestedUrlParams).to.have.property("ef-exp").to.equal("var"); - expect(requestedUrlParams) - .to.have.property("us") - .to.deep.equal(["seg1", "seg2"]); + const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); + expect(requestedUrlParams).to.have.property('ui').to.equal('window-user-id'); + expect(requestedUrlParams).to.have.property('ef-exp').to.equal('var'); + expect(requestedUrlParams).to.have.property('us').to.deep.equal(['seg1', 'seg2']); done(); } catch (e) { done(e); @@ -518,8 +485,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSessionStart()).to.equal(true); }); - it("Should prefer options.userId over window global in tracking requests when useWindowParameters is true", (done) => { - window.cnstrc = { userId: "window-user-id" }; + it('Should prefer options.userId over window global in tracking requests when useWindowParameters is true', (done) => { + window.cnstrc = { userId: 'window-user-id' }; const instance = new ConstructorIO({ apiKey: testApiKey, useWindowParameters: true, @@ -527,13 +494,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - instance.setClientOptions({ userId: "explicit-user-id" }); + instance.setClientOptions({ userId: 'explicit-user-id' }); - instance.tracker.on("success", () => { + instance.tracker.on('success', () => { const requestedUrlParams = helpers.extractUrlParamsFromFetch(fetchSpy); - expect(requestedUrlParams) - .to.have.property("ui") - .to.equal("explicit-user-id"); + expect(requestedUrlParams).to.have.property('ui').to.equal('explicit-user-id'); done(); }); @@ -541,73 +506,67 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackInputFocus", () => { - it("V2 Should respond with a valid response", (done) => { + describe('trackInputFocus', () => { + it('V2 Should respond with a valid response', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const userInput = "Test User Input"; + const userInput = 'Test User Input'; const parameters = { analyticsTags: testAnalyticsTag, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams).to.have.property("user_input").to.equal(userInput); - expect(bodyParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(bodyParams).to.have.property('user_input').to.equal(userInput); + expect(bodyParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); expect(tracker.trackInputFocusV2(userInput, parameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -615,29 +574,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should respond with a valid response", (done) => { + it('Should respond with a valid response', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("action").to.equal("focus"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('action').to.equal('focus'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -645,8 +604,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should respond with a valid response with segments", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response with segments', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -654,16 +613,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -671,8 +630,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should respond with a valid response with userId", (done) => { - const userId = "user-id"; + it('Should respond with a valid response with userId', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -680,16 +639,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -697,7 +656,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -705,7 +664,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -713,8 +672,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -722,7 +681,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -730,16 +689,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).not.to.have.property("origin_referrer"); + expect(requestParams).not.to.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -747,8 +706,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should respond with a valid response with testCells", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response with testCells', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -756,18 +715,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -776,13 +733,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -790,7 +747,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus({ timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -799,7 +756,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -808,8 +765,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -818,16 +775,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -835,10 +792,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackInputFocus()).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -846,16 +803,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -864,256 +821,202 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackAutocompleteSelect", () => { - const term = "Where The Wild Things Are"; + describe('trackAutocompleteSelect', () => { + const term = 'Where The Wild Things Are'; const requiredParameters = { - originalQuery: "original-query", - section: "Search Suggestions", + originalQuery: 'original-query', + section: 'Search Suggestions', }; const optionalParameters = { - tr: "click", - groupId: "all", - displayName: "display-name", - itemId: "12345", - slCampaignOwner: "Campaign Man", - slCampaignId: "Campaign 123", + tr: 'click', + groupId: 'all', + displayName: 'display-name', + itemId: '12345', + slCampaignOwner: 'Campaign Man', + slCampaignId: 'Campaign 123', }; const v2Parameters = { - variationId: "12345-A", + variationId: '12345-A', }; - it("V2 Should respond with a valid response when term and required parameters are provided", (done) => { + it('V2 Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("section") - .to.equal(requiredParameters.section); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('section').to.equal(requiredParameters.section); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("user_input") - .to.equal(requiredParameters.originalQuery); - expect(bodyParams) - .to.have.property("tr") - .to.equal(optionalParameters.tr); - expect(bodyParams) - .to.have.property("item_id") - .to.equal(optionalParameters.itemId); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(v2Parameters.variationId); - expect(bodyParams) - .to.have.property("section") - .to.deep.equal(requiredParameters.section); - expect(bodyParams).to.have.property("item_name").to.equal(term); - expect(bodyParams) - .to.have.property("group_id") - .to.equal(optionalParameters.groupId); - expect(bodyParams) - .to.have.property("sl_campaign_id") - .to.equal(optionalParameters.slCampaignId); - expect(bodyParams) - .to.have.property("sl_campaign_owner") - .to.deep.equal(optionalParameters.slCampaignOwner); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); - - done(); - }); - - tracker.on("error", (error) => { + expect(bodyParams).to.have.property('user_input').to.equal(requiredParameters.originalQuery); + expect(bodyParams).to.have.property('tr').to.equal(optionalParameters.tr); + expect(bodyParams).to.have.property('item_id').to.equal(optionalParameters.itemId); + expect(bodyParams).to.have.property('variation_id').to.equal(v2Parameters.variationId); + expect(bodyParams).to.have.property('section').to.deep.equal(requiredParameters.section); + expect(bodyParams).to.have.property('item_name').to.equal(term); + expect(bodyParams).to.have.property('group_id').to.equal(optionalParameters.groupId); + expect(bodyParams).to.have.property('sl_campaign_id').to.equal(optionalParameters.slCampaignId); + expect(bodyParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + tracker.on('error', (error) => { done(error); }); // eslint-disable-next-line max-len - expect( - tracker.trackAutocompleteSelectV2(term, { - ...requiredParameters, - ...optionalParameters, - ...v2Parameters, - }), - ).to.equal(true); + expect(tracker.trackAutocompleteSelectV2(term, { ...requiredParameters, ...optionalParameters, ...v2Parameters })).to.equal(true); }); - it("Backwards Compatibility - V2 Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - V2 Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: "original-query", - section: "Search Suggestions", - tr: "click", - group_id: "all", - display_name: "display-name", - variation_id: "12345-A", - item_id: "12345", + original_query: 'original-query', + section: 'Search Suggestions', + tr: 'click', + group_id: 'all', + display_name: 'display-name', + variation_id: '12345-A', + item_id: '12345', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("section") - .to.equal(requiredParameters.section); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('section').to.equal(requiredParameters.section); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("user_input") - .to.equal(snakeCaseParameters.original_query); - expect(bodyParams) - .to.have.property("tr") - .to.equal(optionalParameters.tr); - expect(bodyParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(snakeCaseParameters.variation_id); - expect(bodyParams) - .to.have.property("section") - .to.deep.equal(snakeCaseParameters.section); - expect(bodyParams).to.have.property("item_name").to.equal(term); - expect(bodyParams) - .to.have.property("group_id") - .to.equal(optionalParameters.groupId); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); - - done(); - }); - - tracker.on("error", (error) => { + expect(bodyParams).to.have.property('user_input').to.equal(snakeCaseParameters.original_query); + expect(bodyParams).to.have.property('tr').to.equal(optionalParameters.tr); + expect(bodyParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(bodyParams).to.have.property('variation_id').to.equal(snakeCaseParameters.variation_id); + expect(bodyParams).to.have.property('section').to.deep.equal(snakeCaseParameters.section); + expect(bodyParams).to.have.property('item_name').to.equal(term); + expect(bodyParams).to.have.property('group_id').to.equal(optionalParameters.groupId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + tracker.on('error', (error) => { done(error); }); // eslint-disable-next-line max-len - expect( - tracker.trackAutocompleteSelectV2(term, snakeCaseParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelectV2(term, snakeCaseParameters)).to.equal(true); }); - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: "original-query", - section: "Search Suggestions", - tr: "click", - group_id: "all", - display_name: "display-name", - item_id: "12345", + original_query: 'original-query', + section: 'Search Suggestions', + tr: 'click', + group_id: 'all', + display_name: 'display-name', + item_id: '12345', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("original_query") - .to.equal(snakeCaseParameters.original_query); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); - expect(requestParams) - .to.have.property("section") - .to.equal(snakeCaseParameters.section); - expect(requestParams).to.have.property("group").to.deep.equal({ + expect(requestParams).to.have.property('original_query').to.equal(snakeCaseParameters.original_query); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('section').to.equal(snakeCaseParameters.section); + expect(requestParams).to.have.property('group').to.deep.equal({ display_name: snakeCaseParameters.display_name, group_id: snakeCaseParameters.group_id, }); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, snakeCaseParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("original_query") - .to.equal(requiredParameters.originalQuery); - expect(requestParams) - .to.have.property("section") - .to.equal(requiredParameters.section); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('original_query').to.equal(requiredParameters.originalQuery); + expect(requestParams).to.have.property('section').to.equal(requiredParameters.section); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -1121,27 +1024,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1149,27 +1050,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1177,132 +1076,106 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required and optional parameters are provided", (done) => { + it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("tr") - .to.equal(optionalParameters.tr); - expect(requestParams) - .to.have.property("item_id") - .to.equal(optionalParameters.itemId); - expect(requestParams).to.have.property("group").to.deep.equal({ + expect(requestParams).to.have.property('tr').to.equal(optionalParameters.tr); + expect(requestParams).to.have.property('item_id').to.equal(optionalParameters.itemId); + expect(requestParams).to.have.property('group').to.deep.equal({ group_id: optionalParameters.groupId, display_name: optionalParameters.displayName, }); - expect(requestParams) - .to.have.property("sl_campaign_owner") - .to.deep.equal(optionalParameters.slCampaignOwner); - expect(requestParams) - .to.have.property("sl_campaign_id") - .to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, { - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, { ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should throw an error when invalid term is provided", () => { + it('Should throw an error when invalid term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect([], requiredParameters)).to.be.an( - "error", - ); + expect(tracker.trackAutocompleteSelect([], requiredParameters)).to.be.an('error'); }); - it("Should throw an error when no term is provided", () => { + it('Should throw an error when no term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackAutocompleteSelect(null, requiredParameters), - ).to.be.an("error"); + expect(tracker.trackAutocompleteSelect(null, requiredParameters)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect(term, [])).to.be.an("error"); + expect(tracker.trackAutocompleteSelect(term, [])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAutocompleteSelect(term)).to.be.an("error"); + expect(tracker.trackAutocompleteSelect(term)).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1310,7 +1183,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -1318,18 +1191,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1337,45 +1208,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -1384,19 +1249,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); } - it("Should properly encode path parameter", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode path parameter', (done) => { + const specialCharacters = '+[]&'; const termSpecialCharacters = `apple ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -1404,32 +1267,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request expect(fetchSpy).to.have.been.called; - expect(requestUrl).to.include( - encodeURIComponent(termSpecialCharacters), - ); + expect(requestUrl).to.include(encodeURIComponent(termSpecialCharacters)); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect( - termSpecialCharacters, - requiredParameters, - ), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(termSpecialCharacters, requiredParameters)).to.equal(true); }); - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -1438,29 +1294,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1468,74 +1322,66 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAutocompleteSelect(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackAutocompleteSelect(term, requiredParameters)).to.equal(true); }); }); - describe("trackItemDetailLoad", () => { + describe('trackItemDetailLoad', () => { const requiredParameters = { - itemId: "test1", - itemName: "test name", - url: "http://constructor.io", + itemId: 'test1', + itemName: 'test name', + url: 'http://constructor.io', }; const optionalParameters = { - variationId: "test1-small", + variationId: 'test1-small', analyticsTags: testAnalyticsTag, }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: "test1", - item_name: "test name", - url: "http://constructor.io", - variation_id: "test1-small", + item_id: 'test1', + item_name: 'test name', + url: 'http://constructor.io', + variation_id: 'test1-small', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); - expect(requestParams) - .to.have.property("item_name") - .to.equal(snakeCaseParameters.item_name); - expect(requestParams) - .to.have.property("variation_id") - .to.equal(snakeCaseParameters.variation_id); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); + expect(requestParams).to.have.property('variation_id').to.equal(snakeCaseParameters.variation_id); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1543,34 +1389,30 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1578,8 +1420,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -1587,16 +1429,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1604,8 +1446,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -1613,16 +1455,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1630,8 +1472,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1639,18 +1481,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1658,87 +1498,71 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackItemDetailLoad({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackItemDetailLoad({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("variation_id") - .to.deep.equal(optionalParameters.variationId); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('variation_id').to.deep.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackItemDetailLoad({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackItemDetailLoad({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackItemDetailLoad([])).to.be.an("error"); + expect(tracker.trackItemDetailLoad([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackItemDetailLoad()).to.be.an("error"); + expect(tracker.trackItemDetailLoad()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1746,7 +1570,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -1754,8 +1578,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1763,7 +1587,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackItemDetailLoad(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -1771,16 +1595,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -1789,23 +1613,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackItemDetailLoad(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackItemDetailLoad(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -1814,7 +1636,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -1823,7 +1645,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should truncate url param to 2048 characters max", (done) => { + it('Should truncate url param to 2048 characters max', (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -1833,7 +1655,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -1852,188 +1674,165 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackSearchSubmit", () => { - const term = "Where The Wild Things Are"; - const requiredParameters = { originalQuery: "original-query" }; + describe('trackSearchSubmit', () => { + const term = 'Where The Wild Things Are'; + const requiredParameters = { originalQuery: 'original-query' }; const optionalParameters = { - groupId: "group-id", - displayName: "display-name", + groupId: 'group-id', + displayName: 'display-name', analyticsTags: testAnalyticsTag, }; - it("Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided", (done) => { + it('Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: "original-query", - group_id: "group-id", - display_name: "display-name", + original_query: 'original-query', + group_id: 'group-id', + display_name: 'display-name', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("user_input") - .to.equal(snakeCaseParameters.original_query); - expect(bodyParams).to.have.property("search_term").to.equal(term); - expect(bodyParams.filters) - .to.have.property("group_id") - .to.equal(snakeCaseParameters.group_id); + expect(bodyParams).to.have.property('user_input').to.equal(snakeCaseParameters.original_query); + expect(bodyParams).to.have.property('search_term').to.equal(term); + expect(bodyParams.filters).to.have.property('group_id').to.equal(snakeCaseParameters.group_id); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackSearchSubmitV2(term, snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmitV2(term, snakeCaseParameters)).to.equal(true); }); - it("V2 Should respond with a valid response when term and required parameters are provided", (done) => { + it('V2 Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("user_input") - .to.equal(requiredParameters.originalQuery); - expect(bodyParams).to.have.property("search_term").to.equal(term); - expect(bodyParams.filters) - .to.have.property("group_id") - .to.equal(optionalParameters.groupId); + expect(bodyParams).to.have.property('user_input').to.equal(requiredParameters.originalQuery); + expect(bodyParams).to.have.property('search_term').to.equal(term); + expect(bodyParams.filters).to.have.property('group_id').to.equal(optionalParameters.groupId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect( - tracker.trackSearchSubmitV2(term, { - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackSearchSubmitV2(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - original_query: "original-query", - group_id: "group-id", - display_name: "display-name", + original_query: 'original-query', + group_id: 'group-id', + display_name: 'display-name', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("original_query") - .to.equal(snakeCaseParameters.original_query); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('original_query').to.equal(snakeCaseParameters.original_query); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("original_query") - .to.equal(requiredParameters.originalQuery); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('original_query').to.equal(requiredParameters.originalQuery); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -2041,27 +1840,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -2069,27 +1866,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2097,125 +1892,101 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchSubmit(term, { - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackSearchSubmit(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when term, required and optional parameters are provided", (done) => { + it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("group").to.deep.equal({ + expect(requestParams).to.have.property('group').to.deep.equal({ group_id: optionalParameters.groupId, display_name: optionalParameters.displayName, }); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchSubmit(term, { - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackSearchSubmit(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when invalid term is provided", () => { + it('Should throw an error when invalid term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit([], requiredParameters)).to.be.an( - "error", - ); + expect(tracker.trackSearchSubmit([], requiredParameters)).to.be.an('error'); }); - it("Should throw an error when no term is provided", () => { + it('Should throw an error when no term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit(null, requiredParameters)).to.be.an( - "error", - ); + expect(tracker.trackSearchSubmit(null, requiredParameters)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit(term, [])).to.be.an("error"); + expect(tracker.trackSearchSubmit(term, [])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchSubmit(term)).to.be.an("error"); + expect(tracker.trackSearchSubmit(term)).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2223,7 +1994,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -2231,18 +2002,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2250,43 +2019,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackSearchSubmit(term, requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackSearchSubmit(term, requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -2295,19 +2060,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); } - it("Should properly encode path parameter", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode path parameter', (done) => { + const specialCharacters = '+[]&'; const termSpecialCharacters = `apple ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2315,29 +2078,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request expect(fetchSpy).to.have.been.called; - expect(requestUrl).to.include( - encodeURIComponent(termSpecialCharacters), - ); + expect(requestUrl).to.include(encodeURIComponent(termSpecialCharacters)); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchSubmit(termSpecialCharacters, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchSubmit(termSpecialCharacters, requiredParameters)).to.equal(true); }); - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2346,29 +2105,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -2376,35 +2133,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchSubmit(term, requiredParameters)).to.equal(true); }); - it("Should properly obfuscate PII in a path parameter", (done) => { - const termWithPII = " test-email@gmail.com"; - const replaceWith = ""; + it('Should properly obfuscate PII in a path parameter', (done) => { + const termWithPII = ' test-email@gmail.com'; + const replaceWith = ''; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request @@ -2413,53 +2168,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(requestUrl).to.not.include(termWithPII); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII }), - ).to.equal(true); + expect(tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII })).to.equal(true); }); - it("Should properly obfuscate PII in a query parameter", (done) => { - const termWithPII = " test-email@gmail.com"; - const replaceWith = ""; + it('Should properly obfuscate PII in a query parameter', (done) => { + const termWithPII = ' test-email@gmail.com'; + const replaceWith = ''; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("original_query") - .to.equal(replaceWith); - expect(requestParams) - .to.have.property("original_query") - .to.not.include(termWithPII); + expect(requestParams).to.have.property('original_query').to.equal(replaceWith); + expect(requestParams).to.have.property('original_query').to.not.include(termWithPII); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII }), - ).to.equal(true); + expect(tracker.trackSearchSubmit(termWithPII, { originalQuery: termWithPII })).to.equal(true); }); }); - describe("trackSearchResultsLoaded", () => { - const term = "Cat in the Hat"; + describe('trackSearchResultsLoaded', () => { + const term = 'Cat in the Hat'; const requiredParameters = { numResults: 1337 }; const optionalParameters = { itemIds: [1, 2, 3] }; const legacyParameters = { @@ -2467,31 +2214,20 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { customerIds: [1, 2, 3], }; const v2Parameters = { - url: "test", + url: 'test', resultPage: 3, - resultId: "test", - sortOrder: "descending", - sortBy: "test", - selectedFilters: { test: ["test"] }, - section: "Products", + resultId: 'test', + sortOrder: 'descending', + sortBy: 'test', + selectedFilters: { test: ['test'] }, + section: 'Products', analyticsTags: testAnalyticsTag, - items: [ - { - itemId: "1", - slCampaignId: "Campaign 123", - slCampaignOwner: "Campaign Man", - }, - { item_id: "2" }, - ], + items: [{ itemId: '1', slCampaignId: 'Campaign 123', slCampaignOwner: 'Campaign Man' }, { item_id: '2' }], }; - const transformedItems = [ - { item_id: "1" }, - { item_id: "2" }, - { item_id: "3" }, - ]; + const transformedItems = [{ item_id: '1' }, { item_id: '2' }, { item_id: '3' }]; - it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2500,200 +2236,145 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const snakeCaseParameters = { num_results: 1337, item_ids: [1, 2, 3], - url: "test", + url: 'test', result_page: 3, - result_id: "test", - sort_order: "descending", - sort_by: "test", - selected_filters: { test: ["test"] }, - section: "Products", + result_id: 'test', + sort_order: 'descending', + sort_by: 'test', + selected_filters: { test: ['test'] }, + section: 'Products', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("result_count") - .to.equal(snakeCaseParameters.num_results); - expect(bodyParams) - .to.have.property("url") - .to.equal(snakeCaseParameters.url); - expect(bodyParams) - .to.have.property("result_page") - .to.equal(snakeCaseParameters.result_page); - expect(bodyParams) - .to.have.property("result_id") - .to.equal(snakeCaseParameters.result_id); - expect(bodyParams) - .to.have.property("sort_order") - .to.equal(snakeCaseParameters.sort_order); - expect(bodyParams) - .to.have.property("sort_by") - .to.equal(snakeCaseParameters.sort_by); - expect(bodyParams) - .to.have.property("selected_filters") - .to.deep.equal(snakeCaseParameters.selected_filters); - expect(bodyParams) - .to.have.property("section") - .to.deep.equal(snakeCaseParameters.section); - expect(bodyParams) - .to.have.property("items") - .to.deep.equal(transformedItems); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); - - done(); - }); - - tracker.on("error", (error) => { + expect(bodyParams).to.have.property('result_count').to.equal(snakeCaseParameters.num_results); + expect(bodyParams).to.have.property('url').to.equal(snakeCaseParameters.url); + expect(bodyParams).to.have.property('result_page').to.equal(snakeCaseParameters.result_page); + expect(bodyParams).to.have.property('result_id').to.equal(snakeCaseParameters.result_id); + expect(bodyParams).to.have.property('sort_order').to.equal(snakeCaseParameters.sort_order); + expect(bodyParams).to.have.property('sort_by').to.equal(snakeCaseParameters.sort_by); + expect(bodyParams).to.have.property('selected_filters').to.deep.equal(snakeCaseParameters.selected_filters); + expect(bodyParams).to.have.property('section').to.deep.equal(snakeCaseParameters.section); + expect(bodyParams).to.have.property('items').to.deep.equal(transformedItems); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + tracker.on('error', (error) => { done(error); }); // eslint-disable-next-line max-len - expect( - tracker.trackSearchResultsLoaded(term, snakeCaseParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when term and parameters are provided", (done) => { + it('Should respond with a valid response when term and parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("result_count") - .to.equal(requiredParameters.numResults); - expect(bodyParams).to.have.property("url").to.equal(v2Parameters.url); - expect(bodyParams) - .to.have.property("result_page") - .to.equal(v2Parameters.resultPage); - expect(bodyParams) - .to.have.property("result_id") - .to.equal(v2Parameters.resultId); - expect(bodyParams) - .to.have.property("sort_order") - .to.equal(v2Parameters.sortOrder); - expect(bodyParams) - .to.have.property("sort_by") - .to.equal(v2Parameters.sortBy); - expect(bodyParams) - .to.have.property("selected_filters") - .to.deep.equal(v2Parameters.selectedFilters); - expect(bodyParams) - .to.have.property("section") - .to.deep.equal(v2Parameters.section); - expect(bodyParams) - .to.have.property("analytics_tags") - .to.deep.equal(v2Parameters.analyticsTags); - expect(bodyParams) - .to.have.property("items") - .to.deep.equal( - v2Parameters.items.map((item) => - clientHelpers.toSnakeCaseKeys(item, false), - ), - ); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); - - done(); - }); - - tracker.on("error", (error) => { + expect(bodyParams).to.have.property('result_count').to.equal(requiredParameters.numResults); + expect(bodyParams).to.have.property('url').to.equal(v2Parameters.url); + expect(bodyParams).to.have.property('result_page').to.equal(v2Parameters.resultPage); + expect(bodyParams).to.have.property('result_id').to.equal(v2Parameters.resultId); + expect(bodyParams).to.have.property('sort_order').to.equal(v2Parameters.sortOrder); + expect(bodyParams).to.have.property('sort_by').to.equal(v2Parameters.sortBy); + expect(bodyParams).to.have.property('selected_filters').to.deep.equal(v2Parameters.selectedFilters); + expect(bodyParams).to.have.property('section').to.deep.equal(v2Parameters.section); + expect(bodyParams).to.have.property('analytics_tags').to.deep.equal(v2Parameters.analyticsTags); + expect(bodyParams).to.have.property('items').to.deep.equal(v2Parameters.items.map((item) => clientHelpers.toSnakeCaseKeys(item, false))); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + tracker.on('error', (error) => { done(error); }); // eslint-disable-next-line max-len - expect( - tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - ...v2Parameters, - }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, { ...requiredParameters, ...v2Parameters })).to.equal(true); }); - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("result_count") - .to.equal(requiredParameters.numResults); - expect(bodyParams) - .to.have.property("url") - .to.equal(window?.location?.href); - expect(bodyParams).to.have.property("search_term").to.equal(term); - expect(bodyParams) - .to.have.property("url") - .to.equal(window?.location?.href); - expect(bodyParams).to.have.property("key"); - expect(bodyParams).to.have.property("i"); - expect(bodyParams).to.have.property("s"); - expect(bodyParams).to.have.property("c").to.equal(clientVersion); - expect(bodyParams).to.have.property("_dt"); + expect(bodyParams).to.have.property('result_count').to.equal(requiredParameters.numResults); + expect(bodyParams).to.have.property('url').to.equal(window?.location?.href); + expect(bodyParams).to.have.property('search_term').to.equal(term); + expect(bodyParams).to.have.property('url').to.equal(window?.location?.href); + expect(bodyParams).to.have.property('key'); + expect(bodyParams).to.have.property('i'); + expect(bodyParams).to.have.property('s'); + expect(bodyParams).to.have.property('c').to.equal(clientVersion); + expect(bodyParams).to.have.property('_dt'); validateOriginReferrer(bodyParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { - const segments = ["foo", "bar"]; + it('Should send along document_referrer and canonical_url query param', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -2701,41 +2382,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Body - expect(bodyParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(bodyParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(bodyParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(bodyParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -2743,31 +2414,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Body - expect(bodyParams).to.have.property("us").to.deep.equal(segments); + expect(bodyParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -2775,31 +2444,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Body - expect(bodyParams).to.have.property("ui").to.equal(userId); + expect(bodyParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2807,123 +2474,105 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Body - expect(bodyParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(bodyParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required and optional parameters are provided", (done) => { + it('Should respond with a valid response when term, required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; // Body - expect(bodyParams) - .to.have.property("items") - .to.deep.equal(transformedItems); + expect(bodyParams).to.have.property('items').to.deep.equal(transformedItems); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, { ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should respond with a valid response when term and legacy parameters are provided", (done) => { + it('Should respond with a valid response when term and legacy parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; // Body - expect(bodyParams) - .to.have.property("items") - .to.deep.equal(transformedItems); + expect(bodyParams).to.have.property('items').to.deep.equal(transformedItems); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultsLoaded(term, legacyParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultsLoaded(term, legacyParameters)).to.equal(true); }); - it("Should respond with a valid response when term, and zero value num_results parameter are provided", (done) => { + it('Should respond with a valid response when term, and zero value num_results parameter are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property("result_count").to.equal(0); + expect(bodyParams).to.have.property('result_count').to.equal(0); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, { num_results: 0 }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, { num_results: 0 })).to.equal(true); }); - it("Should trim term parameter if extra spaces are provided", (done) => { + it('Should trim term parameter if extra spaces are provided', (done) => { const spaceTerm = ` ${term} `; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -2931,50 +2580,44 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property("search_term").to.equal(term); + expect(bodyParams).to.have.property('search_term').to.equal(term); done(); }); - expect( - tracker.trackSearchResultsLoaded(spaceTerm, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(spaceTerm, requiredParameters)).to.equal(true); }); - it("Should throw an error when invalid term is provided", () => { + it('Should throw an error when invalid term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded([], requiredParameters)).to.be.an( - "error", - ); + expect(tracker.trackSearchResultsLoaded([], requiredParameters)).to.be.an('error'); }); - it("Should throw an error when no term is provided", () => { + it('Should throw an error when no term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackSearchResultsLoaded(null, requiredParameters), - ).to.be.an("error"); + expect(tracker.trackSearchResultsLoaded(null, requiredParameters)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded(term, [])).to.be.an("error"); + expect(tracker.trackSearchResultsLoaded(term, [])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultsLoaded(term)).to.be.an("error"); + expect(tracker.trackSearchResultsLoaded(term)).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -2982,7 +2625,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); @@ -2994,18 +2637,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(bodyParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3013,49 +2654,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Body - expect(bodyParams).to.not.have.property("origin_referrer"); + expect(bodyParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -3064,18 +2699,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); } - it("Should send all items when more than 100 items are provided", (done) => { + it('Should send all items when more than 100 items are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3088,19 +2721,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { item_ids: itemIDs, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(bodyParams) - .to.have.property("items") - .to.deep.equal(formattedItems); + expect(bodyParams).to.have.property('items').to.deep.equal(formattedItems); expect(bodyParams.items).to.have.lengthOf(150); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -3108,8 +2739,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchResultsLoaded(term, parameters)).to.equal(true); }); - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -3118,33 +2749,31 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Body - expect(bodyParams).to.have.property("ui").to.equal(userId); + expect(bodyParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -3152,30 +2781,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Body - expect(bodyParams).to.have.property("ui").to.equal(userIdExpected); + expect(bodyParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, requiredParameters)).to.equal(true); }); - it("Should truncate url param to 2048 characters max", (done) => { + it('Should truncate url param to 2048 characters max', (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -3185,7 +2812,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -3203,113 +2830,105 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackSearchResultsLoaded(term, parameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + })).to.equal(true); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackSearchResultsLoaded(term, { - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackSearchResultsLoaded(term, { + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackSearchResultClick", () => { - const term = "Where The Wild Things Are"; + describe('trackSearchResultClick', () => { + const term = 'Where The Wild Things Are'; const requiredParameters = { - itemName: "name", - itemId: "customer-id", + itemName: 'name', + itemId: 'customer-id', }; const legacyParameters = { - name: "name", - customerId: "customer-id", + name: 'name', + customerId: 'customer-id', }; const optionalParameters = { - variationId: "foobar", - resultId: "result-id", - section: "Products", + variationId: 'foobar', + resultId: 'result-id', + section: 'Products', analyticsTags: testAnalyticsTag, - slCampaignOwner: "Campaign Man", - slCampaignId: "Campaign 123", + slCampaignOwner: 'Campaign Man', + slCampaignId: 'Campaign 123', }; const v2Parameters = { resultCount: 1337, @@ -3317,335 +2936,267 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { resultPositionOnPage: 3, numResultsPerPage: 20, selectedFilters: { - test: ["test"], + test: ['test'], }, analyticsTags: testAnalyticsTag, }; - it("Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided", (done) => { + it('Backwards Compatibility - V2 Should respond with a valid response when term and snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_name: "name", - item_id: "customer-id", - variation_id: "foobar", - result_id: "result-id", + item_name: 'name', + item_id: 'customer-id', + variation_id: 'foobar', + result_id: 'result-id', result_count: 1337, result_page: 3, result_position_on_page: 3, num_results_per_page: 20, selected_filters: { - test: ["test"], + test: ['test'], }, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("item_name") - .to.equal(snakeCaseParameters.item_name); - expect(bodyParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(snakeCaseParameters.variation_id); - expect(bodyParams) - .to.have.property("result_page") - .to.equal(snakeCaseParameters.result_page); - expect(bodyParams) - .to.have.property("result_position_on_page") - .to.equal(snakeCaseParameters.result_position_on_page); - expect(bodyParams) - .to.have.property("result_count") - .to.equal(snakeCaseParameters.result_count); - expect(bodyParams) - .to.have.property("num_results_per_page") - .to.equal(snakeCaseParameters.num_results_per_page); - expect(bodyParams) - .to.have.property("selected_filters") - .to.deep.equal(snakeCaseParameters.selected_filters); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); - - done(); - }); - - tracker.on("error", (error) => { - done(error); - }); + expect(bodyParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); + expect(bodyParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(bodyParams).to.have.property('variation_id').to.equal(snakeCaseParameters.variation_id); + expect(bodyParams).to.have.property('result_page').to.equal(snakeCaseParameters.result_page); + expect(bodyParams).to.have.property('result_position_on_page').to.equal(snakeCaseParameters.result_position_on_page); + expect(bodyParams).to.have.property('result_count').to.equal(snakeCaseParameters.result_count); + expect(bodyParams).to.have.property('num_results_per_page').to.equal(snakeCaseParameters.num_results_per_page); + expect(bodyParams).to.have.property('selected_filters').to.deep.equal(snakeCaseParameters.selected_filters); - // eslint-disable-next-line max-len - expect( - tracker.trackSearchResultClickV2(term, snakeCaseParameters), - ).to.equal(true); + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); + + done(); + }); + + tracker.on('error', (error) => { + done(error); + }); + + // eslint-disable-next-line max-len + expect(tracker.trackSearchResultClickV2(term, snakeCaseParameters)).to.equal(true); }); - it("V2 Should respond with a valid response when term and required parameters are provided", (done) => { + it('V2 Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(bodyParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("section") - .to.deep.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("sl_campaign_id") - .to.equal(optionalParameters.slCampaignId); - expect(bodyParams) - .to.have.property("sl_campaign_owner") - .to.deep.equal(optionalParameters.slCampaignOwner); - expect(bodyParams) - .to.have.property("result_page") - .to.equal(v2Parameters.resultPage); - expect(bodyParams) - .to.have.property("result_position_on_page") - .to.equal(v2Parameters.resultPositionOnPage); - expect(bodyParams) - .to.have.property("result_count") - .to.equal(v2Parameters.resultCount); - expect(bodyParams) - .to.have.property("num_results_per_page") - .to.equal(v2Parameters.numResultsPerPage); - expect(bodyParams) - .to.have.property("selected_filters") - .to.deep.equal(v2Parameters.selectedFilters); - expect(bodyParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(bodyParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(bodyParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('section').to.deep.equal(optionalParameters.section); + expect(bodyParams).to.have.property('sl_campaign_id').to.equal(optionalParameters.slCampaignId); + expect(bodyParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); + expect(bodyParams).to.have.property('result_page').to.equal(v2Parameters.resultPage); + expect(bodyParams).to.have.property('result_position_on_page').to.equal(v2Parameters.resultPositionOnPage); + expect(bodyParams).to.have.property('result_count').to.equal(v2Parameters.resultCount); + expect(bodyParams).to.have.property('num_results_per_page').to.equal(v2Parameters.numResultsPerPage); + expect(bodyParams).to.have.property('selected_filters').to.deep.equal(v2Parameters.selectedFilters); + expect(bodyParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); // eslint-disable-next-line max-len - expect( - tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - ...optionalParameters, - ...v2Parameters, - }), - ).to.equal(true); + expect(tracker.trackSearchResultClickV2(term, { ...requiredParameters, ...optionalParameters, ...v2Parameters })).to.equal(true); }); - it("V2 Should return valid response when resultOffset is passed as an integer", (done) => { + it('V2 Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("V2 Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('V2 Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + })).to.equal(true); }); - it("V2 Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('V2 Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackSearchResultClickV2(term, { - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackSearchResultClickV2(term, { + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); - it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_name: "name", - item_id: "customer-id", - variation_id: "foobar", - result_id: "result-id", + item_name: 'name', + item_id: 'customer-id', + variation_id: 'foobar', + result_id: 'result-id', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("name") - .to.equal(snakeCaseParameters.item_name); - expect(requestParams) - .to.have.property("customer_id") - .to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('name').to.equal(snakeCaseParameters.item_name); + expect(requestParams).to.have.property('customer_id').to.equal(snakeCaseParameters.item_id); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultClick(term, snakeCaseParameters), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("customer_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('customer_id').to.equal(requiredParameters.itemId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -3653,58 +3204,50 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -3712,27 +3255,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3740,204 +3281,166 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and variation id is provided", (done) => { + it('Should respond with a valid response when term, required parameters and variation id is provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("variation_id") - .to.equal("variation-id"); + expect(requestParams).to.have.property('variation_id').to.equal('variation-id'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultClick(term, { - ...requiredParameters, - variation_id: "variation-id", - }), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, { + ...requiredParameters, + variation_id: 'variation-id', + })).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and optional parameters are provided", (done) => { + it('Should respond with a valid response when term, required parameters and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); - expect(requestParams) - .to.have.property("sl_campaign_owner") - .to.deep.equal(optionalParameters.slCampaignOwner); - expect(requestParams) - .to.have.property("sl_campaign_id") - .to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultClick( - term, - Object.assign(requiredParameters, optionalParameters), - ), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, Object.assign( + requiredParameters, + optionalParameters, + ))).to.equal(true); }); - it("Should respond with a valid response when term and legacy parameters are provided", (done) => { + it('Should respond with a valid response when term and legacy parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("customer_id") - .to.equal(legacyParameters.customerId); - expect(requestParams) - .to.have.property("name") - .to.equal(legacyParameters.name); + expect(requestParams).to.have.property('customer_id').to.equal(legacyParameters.customerId); + expect(requestParams).to.have.property('name').to.equal(legacyParameters.name); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, legacyParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, legacyParameters)).to.equal(true); }); - it("Should respond with a valid response when term and item_is_convertible are provided", (done) => { + it('Should respond with a valid response when term and item_is_convertible are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("customer_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('customer_id').to.equal(requiredParameters.itemId); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("item_is_convertible") - .to.equal("false"); + expect(requestParams).to.have.property('item_is_convertible').to.equal('false'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultClick(term, { - ...requiredParameters, - item_is_convertible: false, - }), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, { + ...requiredParameters, + item_is_convertible: false, + })).to.equal(true); }); - it("Should throw an error when invalid term is provided", () => { + it('Should throw an error when invalid term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick([], requiredParameters)).to.be.an( - "error", - ); + expect(tracker.trackSearchResultClick([], requiredParameters)).to.be.an('error'); }); - it("Should throw an error when no term is provided", () => { + it('Should throw an error when no term is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(null, requiredParameters)).to.be.an( - "error", - ); + expect(tracker.trackSearchResultClick(null, requiredParameters)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term, [])).to.be.an("error"); + expect(tracker.trackSearchResultClick(term, [])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term)).to.be.an("error"); + expect(tracker.trackSearchResultClick(term)).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3945,7 +3448,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -3953,18 +3456,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -3972,45 +3473,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackSearchResultClick(term, requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -4019,19 +3514,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackSearchResultClick(term, requiredParameters), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); } - it("Should properly encode path parameter", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode path parameter', (done) => { + const specialCharacters = '+[]&'; const termSpecialCharacters = `apple ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4039,32 +3532,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestUrl = fetchSpy.args[0][0]; // Request expect(fetchSpy).to.have.been.called; - expect(requestUrl).to.include( - encodeURIComponent(termSpecialCharacters), - ); + expect(requestUrl).to.include(encodeURIComponent(termSpecialCharacters)); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackSearchResultClick( - termSpecialCharacters, - requiredParameters, - ), - ).to.equal(true); + expect(tracker.trackSearchResultClick(termSpecialCharacters, requiredParameters)).to.equal(true); }); - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4073,29 +3559,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -4103,98 +3587,87 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("GET"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('GET'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackSearchResultClick(term, requiredParameters)).to.equal(true); }); - it("Should be rejected when an invalid section is used", (done) => { + it('Should be rejected when an invalid section is used', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { - expect(message).to.equal("Unknown section: non-existent"); + tracker.on('error', ({ message }) => { + expect(message).to.equal('Unknown section: non-existent'); done(); }); - expect( - tracker.trackSearchResultClick(term, { - ...requiredParameters, - section: "non-existent", - }), - ).to.equal(true); + expect(tracker.trackSearchResultClick(term, { ...requiredParameters, section: 'non-existent' })).to.equal(true); }); }); - describe("trackConversion", () => { - const term = "Where The Wild Things Are"; + describe('trackConversion', () => { + const term = 'Where The Wild Things Are'; const requiredParameters = { - itemId: "customer-id", + itemId: 'customer-id', revenue: 123, }; const optionalParameters = { - itemName: "item_name", - variationId: "variation-id", - section: "Products", + itemName: 'item_name', + variationId: 'variation-id', + section: 'Products', }; const legacyParameters = { - customerId: "customer-id", + customerId: 'customer-id', revenue: 123, - name: "item_name", + name: 'item_name', }; - it("Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when term and snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: "item_name", + item_id: 'item_name', revenue: 123, - item_name: "item_name", - variation_id: "variation-id", + item_name: 'item_name', + variation_id: 'variation-id', is_custom_type: true, - display_name: "Add To Wishlist", + display_name: 'Add To Wishlist', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); - expect(requestParams) - .to.have.property("revenue") - .to.equal(snakeCaseParameters.revenue.toString()); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('revenue').to.equal(snakeCaseParameters.revenue.toString()); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4202,34 +3675,30 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("revenue") - .to.equal(requiredParameters.revenue.toString()); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('revenue').to.equal(requiredParameters.revenue.toString()); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4237,60 +3706,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters, and optional parameters are provided", (done) => { + it('Should respond with a valid response when term, required parameters, and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const queryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(queryParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("revenue") - .to.equal(requiredParameters.revenue.toString()); - expect(requestParams) - .to.have.property("item_name") - .to.equal(optionalParameters.itemName); - expect(requestParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); + expect(queryParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('revenue').to.equal(requiredParameters.revenue.toString()); + expect(requestParams).to.have.property('item_name').to.equal(optionalParameters.itemName); + expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackConversion(term, { - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackConversion(term, { ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when term and required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when term and required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4298,16 +3750,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4317,28 +3769,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, clonedParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4346,8 +3794,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -4355,16 +3803,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4372,8 +3820,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when term, required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -4381,16 +3829,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4398,7 +3846,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should ensure userId is passed as a string", (done) => { + it('Should ensure userId is passed as a string', (done) => { const userId = 123; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4407,16 +3855,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(String(userId)); + expect(requestParams).to.have.property('ui').to.equal(String(userId)); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4424,8 +3872,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when term, required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4433,18 +3881,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4452,26 +3898,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and conversion type are provided", (done) => { + it('Should respond with a valid response when term, required parameters and conversion type are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const fullParameters = { ...requiredParameters, type: "add_to_wishlist" }; + const fullParameters = { ...requiredParameters, type: 'add_to_wishlist' }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("type") - .to.equal(fullParameters.type); + expect(requestParams).to.have.property('type').to.equal(fullParameters.type); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4479,7 +3923,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and custom conversion type are provided", (done) => { + it('Should respond with a valid response when term, required parameters and custom conversion type are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4487,29 +3931,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const fullParameters = { ...requiredParameters, - type: "add_to_loves", - displayName: "Add To Loves List", + type: 'add_to_loves', + displayName: 'Add To Loves List', isCustomType: true, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("type") - .to.equal(fullParameters.type); - expect(requestParams) - .to.have.property("is_custom_type") - .to.equal(fullParameters.isCustomType); - expect(requestParams) - .to.have.property("display_name") - .to.equal(fullParameters.displayName); + expect(requestParams).to.have.property('type').to.equal(fullParameters.type); + expect(requestParams).to.have.property('is_custom_type').to.equal(fullParameters.isCustomType); + expect(requestParams).to.have.property('display_name').to.equal(fullParameters.displayName); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4517,28 +3955,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it("Should respond with a valid response when term and legacy parameters are provided", (done) => { + it('Should respond with a valid response when term and legacy parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("item_id") - .to.equal(legacyParameters.customerId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(legacyParameters.name); + expect(requestParams).to.have.property('item_id').to.equal(legacyParameters.customerId); + expect(requestParams).to.have.property('item_name').to.equal(legacyParameters.name); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4546,13 +3980,13 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, legacyParameters)).to.equal(true); }); - it("Should respond with a valid response when no term is provided, but parameters are", () => { + it('Should respond with a valid response when no term is provided, but parameters are', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); expect(tracker.trackConversion(null, requiredParameters)).to.equal(true); }); - it("should respond with a valid response if isCustomType is true, displayName is provided, and no type is specified", (done) => { + it('should respond with a valid response if isCustomType is true, displayName is provided, and no type is specified', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4560,26 +3994,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const fullParameters = { ...requiredParameters, - displayName: "Add To Loves List", + displayName: 'Add To Loves List', isCustomType: true, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("display_name") - .to.equal(fullParameters.displayName); - expect(requestParams) - .to.have.property("is_custom_type") - .to.equal(fullParameters.isCustomType); - expect(requestParams).to.not.have.property("type"); + expect(requestParams).to.have.property('display_name').to.equal(fullParameters.displayName); + expect(requestParams).to.have.property('is_custom_type').to.equal(fullParameters.isCustomType); + expect(requestParams).to.not.have.property('type'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4587,7 +4017,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it("should respond with an error if isCustomType is true, type is provided, and no displayName is specified", (done) => { + it('should respond with an error if isCustomType is true, type is provided, and no displayName is specified', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4595,28 +4025,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const fullParameters = { ...requiredParameters, - type: "add_to_loves", + type: 'add_to_loves', isCustomType: true, }; - tracker.on("error", (responseParams) => { + tracker.on('error', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("type") - .to.equal(fullParameters.type); - expect(requestParams) - .to.have.property("is_custom_type") - .to.equal(fullParameters.isCustomType); - expect(requestParams).to.not.have.property("display_name"); + expect(requestParams).to.have.property('type').to.equal(fullParameters.type); + expect(requestParams).to.have.property('is_custom_type').to.equal(fullParameters.isCustomType); + expect(requestParams).to.not.have.property('display_name'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('Invalid parameters'); done(); }); @@ -4624,7 +4048,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, fullParameters)).to.equal(true); }); - it("should support v1 endpoint arguments", (done) => { + it('should support v1 endpoint arguments', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4632,43 +4056,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parameters = { - customerId: "customer-id", - name: "name", - section: "Products", + customerId: 'customer-id', + name: 'name', + section: 'Products', revenue: 123, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const queryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(queryParams) - .to.have.property("section") - .to.equal(parameters.section); - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(parameters.customerId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(parameters.name); - expect(requestParams) - .to.have.property("revenue") - .to.equal(parameters.revenue.toString()); - expect(requestParams) - .to.have.property("section") - .to.equal(parameters.section); + expect(queryParams).to.have.property('section').to.equal(parameters.section); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(parameters.customerId); + expect(requestParams).to.have.property('item_name').to.equal(parameters.name); + expect(requestParams).to.have.property('revenue').to.equal(parameters.revenue.toString()); + expect(requestParams).to.have.property('section').to.equal(parameters.section); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4676,7 +4090,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, parameters)).to.equal(true); }); - it("Should trim term parameter if extra spaces are provided", (done) => { + it('Should trim term parameter if extra spaces are provided', (done) => { const spaceTerm = ` ${term} `; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4684,32 +4098,30 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); - expect(bodyParams).to.have.property("search_term").to.equal(term); + expect(bodyParams).to.have.property('search_term').to.equal(term); done(); }); - expect(tracker.trackConversion(spaceTerm, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackConversion(spaceTerm, requiredParameters)).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term, [])).to.be.an("error"); + expect(tracker.trackSearchResultClick(term, [])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackSearchResultClick(term)).to.be.an("error"); + expect(tracker.trackSearchResultClick(term)).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4717,7 +4129,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -4725,8 +4137,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4734,7 +4146,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4742,16 +4154,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4760,23 +4172,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackConversion(term, requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackConversion(term, requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -4785,19 +4195,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackConversion(term, requiredParameters)).to.equal( - true, - ); + expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -4806,16 +4214,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4823,10 +4231,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -4834,16 +4242,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -4851,7 +4259,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackConversion(term, requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when analyticsTags are provided", (done) => { + it('Should respond with a valid response when analyticsTags are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -4862,91 +4270,83 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { analyticsTags: testAnalyticsTag, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackConversion(term, parametersWithAnalyticsTags), - ).to.equal(true); + expect(tracker.trackConversion(term, parametersWithAnalyticsTags)).to.equal(true); }); }); - describe("trackPurchase", () => { + describe('trackPurchase', () => { const requiredParameters = { items: [ { // cspell:disable-next-line - itemId: "productc60366c42b5d4194ad39962fd88d7266", - variationId: "456", + itemId: 'productc60366c42b5d4194ad39962fd88d7266', + variationId: '456', }, { - itemId: "product55f1b3577fa84947a93ea01b91d52f45", + itemId: 'product55f1b3577fa84947a93ea01b91d52f45', }, ], revenue: 123.45, }; const optionalParameters = { - orderId: "123938123", - section: "Products", + orderId: '123938123', + section: 'Products', analyticsTags: testAnalyticsTag, }; const snakeCaseItems = [ { // cspell:disable-next-line - item_id: "productc60366c42b5d4194ad39962fd88d7266", - variation_id: "456", + item_id: 'productc60366c42b5d4194ad39962fd88d7266', + variation_id: '456', }, { - item_id: "product55f1b3577fa84947a93ea01b91d52f45", + item_id: 'product55f1b3577fa84947a93ea01b91d52f45', }, ]; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - order_id: "123938123", + order_id: '123938123', revenue: 123.45, items: snakeCaseItems, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseParameters.items); - expect(requestParams) - .to.have.property("revenue") - .to.equal(snakeCaseParameters.revenue); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseParameters.items); + expect(requestParams).to.have.property('revenue').to.equal(snakeCaseParameters.revenue); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -4954,34 +4354,30 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); - expect(requestParams) - .to.have.property("revenue") - .to.equal(requiredParameters.revenue); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('revenue').to.equal(requiredParameters.revenue); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -4989,83 +4385,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestQueryParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestQueryParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestQueryParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestQueryParams).to.have.property('document_referrer').to.equal(referrer); // Body - expect(requestBodyParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestBodyParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestBodyParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestBodyParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackPurchase({ ...requiredParameters, ...optionalParameters }), - ).to.equal(true); + expect(tracker.trackPurchase({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when optional parameters are provided", (done) => { + it('Should respond with a valid response when optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestQueryParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestBodyParams) - .to.have.property("order_id") - .to.equal(optionalParameters.orderId); - expect(requestBodyParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestQueryParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestBodyParams).to.have.property('order_id').to.equal(optionalParameters.orderId); + expect(requestBodyParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackPurchase({ ...requiredParameters, ...optionalParameters }), - ).to.equal(true); + expect(tracker.trackPurchase({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -5073,16 +4451,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -5090,23 +4468,23 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -5114,8 +4492,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5123,16 +4501,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -5140,8 +4518,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5149,18 +4527,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -5168,48 +4544,46 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response and limit items to no more than 100", (done) => { + it('Should respond with a valid response and limit items to no more than 100', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestBodyParams).to.have.property("items").length.to.be(100); + expect(requestBodyParams).to.have.property('items').length.to.be(100); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackPurchase({ - ...requiredParameters, - items: Array(200).fill({ item_id: "product55f1b3a93ea01b91d52f45" }), - }), - ).to.equal(true); + expect(tracker.trackPurchase({ + ...requiredParameters, + items: Array(200).fill({ item_id: 'product55f1b3a93ea01b91d52f45' }), + })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase([])).to.be.an("error"); + expect(tracker.trackPurchase([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase()).to.be.an("error"); + expect(tracker.trackPurchase()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5217,7 +4591,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -5225,8 +4599,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -5234,7 +4608,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5242,16 +4616,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -5261,24 +4635,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { // store2 doesn't seem to maintain the `window` context for bundled version if (!bundled) { - it("Should not send a purchase event if the order has been tracked already", (done) => { + it('Should not send a purchase event if the order has been tracked already', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const orderId = "848291039"; + const orderId = '848291039'; const apiKey = testApiKey; addOrderIdRecord({ orderId, apiKey }); - expect( - tracker.trackPurchase({ - ...requiredParameters, - ...optionalParameters, - orderId, - }), - ).to.equal(false); + expect(tracker.trackPurchase({ + ...requiredParameters, + ...optionalParameters, + orderId, + })).to.equal(false); setTimeout(() => { // Request @@ -5289,75 +4661,67 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should send a purchase event if the order has not been tracked yet", (done) => { + it('Should send a purchase event if the order has not been tracked yet', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestQueryParams = helpers.extractUrlParamsFromFetch(fetchSpy); const requestBodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestQueryParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestBodyParams) - .to.have.property("order_id") - .to.equal("328192019"); + expect(requestQueryParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestBodyParams).to.have.property('order_id').to.equal('328192019'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - addOrderIdRecord({ orderId: "239402919", apiKey: testApiKey }); - addOrderIdRecord({ orderId: "482039192", apiKey: testApiKey }); + addOrderIdRecord({ orderId: '239402919', apiKey: testApiKey }); + addOrderIdRecord({ orderId: '482039192', apiKey: testApiKey }); - expect( - tracker.trackPurchase({ - ...requiredParameters, - ...optionalParameters, - orderId: "328192019", - }), - ).to.equal(true); + expect(tracker.trackPurchase({ + ...requiredParameters, + ...optionalParameters, + orderId: '328192019', + })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase([])).to.be.an("error"); + expect(tracker.trackPurchase([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackPurchase()).to.be.an("error"); + expect(tracker.trackPurchase()).to.be.an('error'); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackPurchase(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackPurchase(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -5366,7 +4730,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -5375,8 +4739,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5385,16 +4749,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -5402,10 +4766,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackPurchase(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5413,16 +4777,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -5431,110 +4795,94 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackRecommendationView", () => { + describe('trackRecommendationView', () => { const requiredParameters = { - podId: "test_pod_id", + podId: 'test_pod_id', numResultsViewed: 5, - url: "https://constructor.io", + url: 'https://constructor.io', }; const optionalParameters = { resultCount: 5, resultPage: 1, - resultId: "result-id", - section: "Products", + resultId: 'result-id', + section: 'Products', analyticsTags: testAnalyticsTag, }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - pod_id: "test_pod_id", + pod_id: 'test_pod_id', num_results_viewed: 5, - url: "https://constructor.io", + url: 'https://constructor.io', result_count: 5, result_page: 1, - result_id: "result_id", - section: "Products", + result_id: 'result_id', + section: 'Products', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("url") - .to.equal(snakeCaseParameters.url); - expect(requestParams) - .to.have.property("pod_id") - .to.equal(snakeCaseParameters.pod_id); - expect(requestParams) - .to.have.property("num_results_viewed") - .to.equal(snakeCaseParameters.num_results_viewed); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('url').to.equal(snakeCaseParameters.url); + expect(requestParams).to.have.property('pod_id').to.equal(snakeCaseParameters.pod_id); + expect(requestParams).to.have.property('num_results_viewed').to.equal(snakeCaseParameters.num_results_viewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationView(snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("url") - .to.equal(requiredParameters.url); - expect(requestParams) - .to.have.property("pod_id") - .to.equal(requiredParameters.podId); - expect(requestParams) - .to.have.property("num_results_viewed") - .to.equal(requiredParameters.numResultsViewed); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); + expect(requestParams).to.have.property('pod_id').to.equal(requiredParameters.podId); + expect(requestParams).to.have.property('num_results_viewed').to.equal(requiredParameters.numResultsViewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5542,21 +4890,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -5566,7 +4910,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(clonedParameters)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5574,16 +4918,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -5593,11 +4937,14 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(clonedParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and items are provided", (done) => { - const items = [{ itemId: "123", variationId: "234" }, { itemId: "abc" }]; + it('Should respond with a valid response when required parameters and items are provided', (done) => { + const items = [ + { itemId: '123', variationId: '234' }, + { itemId: 'abc' }, + ]; const snakeCaseItems = [ - { item_id: "123", variation_id: "234" }, - { item_id: "abc" }, + { item_id: '123', variation_id: '234' }, + { item_id: 'abc' }, ]; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5605,28 +4952,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView({ items, ...requiredParameters }), - ).to.equal(true); + expect(tracker.trackRecommendationView({ items, ...requiredParameters })).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -5634,27 +4977,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5662,29 +5003,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5692,81 +5029,64 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("result_count") - .to.equal(optionalParameters.resultCount); - expect(requestParams) - .to.have.property("result_page") - .to.equal(optionalParameters.resultPage); - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); + expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackRecommendationView({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationView([])).to.be.an("error"); + expect(tracker.trackRecommendationView([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationView()).to.be.an("error"); + expect(tracker.trackRecommendationView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5774,7 +5094,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -5782,18 +5102,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5801,43 +5119,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackRecommendationView(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackRecommendationView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -5846,19 +5160,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5867,29 +5179,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -5897,27 +5207,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when seedItemIds is an array", (done) => { - const seedItemIds = ["123"]; + it('Should respond with a valid response when seedItemIds is an array', (done) => { + const seedItemIds = ['123']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5928,28 +5236,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on("success", (responseParams) => { + 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(["123"]); + expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(['123']); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView(requiredParamsWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and convert seedItemIds to an array if it's is a number", (done) => { + it('Should respond with a valid response and convert seedItemIds to an array if it\'s is a number', (done) => { const seedItemIds = 123; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -5961,29 +5265,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on("success", (responseParams) => { + 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(["123"]); + expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(['123']); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView(requiredParamsWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and convert seedItemIds to an array if it's a string", (done) => { - const seedItemIds = "123"; + it('Should respond with a valid response and convert seedItemIds to an array if it\'s a string', (done) => { + const seedItemIds = '123'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -5994,28 +5294,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on("success", (responseParams) => { + 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(["123"]); + expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(['123']); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView(requiredParamsWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and omit seed_item_ids if seedItemIds is null", (done) => { + it('Should respond with a valid response and omit seed_item_ids if seedItemIds is null', (done) => { const seedItemIds = null; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -6027,27 +5323,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on("success", (responseParams) => { + 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"); + 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"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView(requiredParamsWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and omit seed_item_ids if seedItemIds is an object", (done) => { - const seedItemIds = { seedItemIds: "123" }; + it('Should respond with a valid response and omit seed_item_ids if seedItemIds is an object', (done) => { + const seedItemIds = { seedItemIds: '123' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6058,26 +5352,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, }; - tracker.on("success", (responseParams) => { + 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"); + 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"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView(requiredParamsWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationView(requiredParamsWithSeedItemIds)).to.equal(true); }); - it("Should truncate url param to 2048 characters max", (done) => { + it('Should truncate url param to 2048 characters max', (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -6087,7 +5379,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -6105,297 +5397,257 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationView(parameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackRecommendationView({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationView({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackRecommendationView({ + ...requiredParameters, + })).to.equal(true); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackRecommendationView({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackRecommendationView({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackRecommendationClick", () => { + describe('trackRecommendationClick', () => { // Note: `variation_id` parameter not being passed as none are defined for this item_id in catalog const requiredParameters = { - podId: "test_pod_id", - strategyId: "strategy-id", - itemId: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", + podId: 'test_pod_id', + strategyId: 'strategy-id', + itemId: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', }; const optionalParameters = { resultPositionOnPage: 10, numResultsPerPage: 5, resultCount: 5, resultPage: 1, - resultId: "result-id", - section: "Products", + resultId: 'result-id', + section: 'Products', analyticsTags: testAnalyticsTag, - slCampaignOwner: "Campaign Man", - slCampaignId: "Campaign 123", + slCampaignOwner: 'Campaign Man', + slCampaignId: 'Campaign 123', }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - pod_id: "test_pod_id", - strategy_id: "strategy-id", - item_id: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", + pod_id: 'test_pod_id', + strategy_id: 'strategy-id', + item_id: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', result_position_on_page: 10, num_results_per_page: 5, result_count: 5, result_page: 1, - result_id: "result-id", - section: "Products", + result_id: 'result-id', + section: 'Products', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("pod_id") - .to.equal(snakeCaseParameters.pod_id); - expect(requestParams) - .to.have.property("strategy_id") - .to.equal(snakeCaseParameters.strategy_id); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('pod_id').to.equal(snakeCaseParameters.pod_id); + expect(requestParams).to.have.property('strategy_id').to.equal(snakeCaseParameters.strategy_id); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("pod_id") - .to.equal(requiredParameters.podId); - expect(requestParams) - .to.have.property("strategy_id") - .to.equal(requiredParameters.strategyId); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('pod_id').to.equal(requiredParameters.podId); + expect(requestParams).to.have.property('strategy_id').to.equal(requiredParameters.strategyId); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Backwards Compatibility - Should respond with a valid response when only item_name is provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when only item_name is provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const parametersWithItemName = { - pod_id: "test_pod_id", - strategy_id: "strategy-id", - item_name: "product", + pod_id: 'test_pod_id', + strategy_id: 'strategy-id', + item_name: 'product', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("pod_id") - .to.equal(parametersWithItemName.pod_id); - expect(requestParams) - .to.have.property("strategy_id") - .to.equal(parametersWithItemName.strategy_id); - expect(requestParams) - .to.have.property("item_name") - .to.equal(parametersWithItemName.item_name); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('pod_id').to.equal(parametersWithItemName.pod_id); + expect(requestParams).to.have.property('strategy_id').to.equal(parametersWithItemName.strategy_id); + expect(requestParams).to.have.property('item_name').to.equal(parametersWithItemName.item_name); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal(true); }); - it("Should respond with a valid response when only item_name is provided", (done) => { + it('Should respond with a valid response when only item_name is provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const parametersWithItemName = { - podId: "test_pod_id", - strategyId: "strategy-id", - itemName: "product", + podId: 'test_pod_id', + strategyId: 'strategy-id', + itemName: 'product', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("pod_id") - .to.equal(parametersWithItemName.podId); - expect(requestParams) - .to.have.property("strategy_id") - .to.equal(parametersWithItemName.strategyId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(parametersWithItemName.itemName); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('pod_id').to.equal(parametersWithItemName.podId); + expect(requestParams).to.have.property('strategy_id').to.equal(parametersWithItemName.strategyId); + expect(requestParams).to.have.property('item_name').to.equal(parametersWithItemName.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(parametersWithItemName)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -6403,16 +5655,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -6422,39 +5674,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackRecommendationClick(clonedParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -6462,27 +5708,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -6490,27 +5734,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6518,95 +5760,68 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + 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(optionalParameters.resultPositionOnPage); - expect(requestParams) - .to.have.property("num_results_per_page") - .to.equal(optionalParameters.numResultsPerPage); - expect(requestParams) - .to.have.property("result_count") - .to.equal(optionalParameters.resultCount); - expect(requestParams) - .to.have.property("result_page") - .to.equal(optionalParameters.resultPage); - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); - expect(requestParams) - .to.have.property("sl_campaign_id") - .to.deep.equal(optionalParameters.slCampaignId); - expect(requestParams) - .to.have.property("sl_campaign_owner") - .to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams).to.have.property('result_position_on_page').to.equal(optionalParameters.resultPositionOnPage); + expect(requestParams).to.have.property('num_results_per_page').to.equal(optionalParameters.numResultsPerPage); + expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); + expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackRecommendationClick({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationClick([])).to.be.an("error"); + expect(tracker.trackRecommendationClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackRecommendationClick()).to.be.an("error"); + expect(tracker.trackRecommendationClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6614,7 +5829,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -6622,18 +5837,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6641,43 +5854,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackRecommendationClick(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackRecommendationClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -6686,19 +5895,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -6707,29 +5914,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -6737,26 +5942,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackRecommendationClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackRecommendationClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when seedItemIds is provided as an array of strings", (done) => { + it('Should respond with a valid response when seedItemIds is provided as an array of strings', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6764,26 +5967,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parametersWithSeedItemIds = { ...requiredParameters, - seedItemIds: ["item-123", "item-456", "item-789"], + seedItemIds: ['item-123', 'item-456', 'item-789'], }; - tracker.on("success", (responseParams) => { + 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(["item-123", "item-456", "item-789"]); + expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(['item-123', 'item-456', 'item-789']); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick(parametersWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and convert seedItemIds to array when provided as string", (done) => { + it('Should respond with a valid response and convert seedItemIds to array when provided as string', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6791,26 +5990,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parametersWithSeedItemIds = { ...requiredParameters, - seedItemIds: "item-123", + seedItemIds: 'item-123', }; - tracker.on("success", (responseParams) => { + 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(["item-123"]); + expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(['item-123']); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick(parametersWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and convert seedItemIds to array when provided as number", (done) => { + it('Should respond with a valid response and convert seedItemIds to array when provided as number', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6820,24 +6015,20 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, seedItemIds: 123, }; - tracker.on("success", (responseParams) => { + 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(["123"]); + expect(requestParams).to.have.property('seed_item_ids').to.deep.equal(['123']); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick(parametersWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and omit seed_item_ids when seedItemIds is empty string", (done) => { + it('Should respond with a valid response and omit seed_item_ids when seedItemIds is empty string', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6845,24 +6036,22 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); const parametersWithSeedItemIds = { ...requiredParameters, - seedItemIds: "", + seedItemIds: '', }; - tracker.on("success", (responseParams) => { + 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"); + 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"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick(parametersWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); }); - it("Should respond with a valid response and omit seed_item_ids when seedItemIds is empty array", (done) => { + it('Should respond with a valid response and omit seed_item_ids when seedItemIds is empty array', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -6872,255 +6061,221 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requiredParameters, seedItemIds: [], }; - tracker.on("success", (responseParams) => { + 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"); + 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"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick(parametersWithSeedItemIds), - ).to.equal(true); + expect(tracker.trackRecommendationClick(parametersWithSeedItemIds)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackRecommendationClick({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackRecommendationClick({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackRecommendationClick({ + ...requiredParameters, + })).to.equal(true); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackRecommendationClick({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackRecommendationClick({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackBrowseResultsLoaded", () => { + describe('trackBrowseResultsLoaded', () => { const requiredParameters = { - sortBy: "price", - sortOrder: "ascending", - filterName: "group_id", - filterValue: "Clothing", - url: "http://constructor.io", + sortBy: 'price', + sortOrder: 'ascending', + filterName: 'group_id', + filterValue: 'Clothing', + url: 'http://constructor.io', }; const optionalParameters = { - section: "Products", + section: 'Products', resultCount: 5, resultPage: 1, - resultId: "result-id", - selectedFilters: { foo: ["bar"] }, + resultId: 'result-id', + selectedFilters: { foo: ['bar'] }, items: [ { - itemId: "123", - variationId: "456", - slCampaignId: "Campaign 123", - slCampaignOwner: "Campaign Man", + itemId: '123', + variationId: '456', + slCampaignId: 'Campaign 123', + slCampaignOwner: 'Campaign Man', }, { - itemId: "789", + itemId: '789', }, ], analyticsTags: testAnalyticsTag, }; const snakeCaseItems = [ { - item_id: "123", - variation_id: "456", - sl_campaign_id: "Campaign 123", - sl_campaign_owner: "Campaign Man", + item_id: '123', + variation_id: '456', + sl_campaign_id: 'Campaign 123', + sl_campaign_owner: 'Campaign Man', }, { - item_id: "789", + item_id: '789', }, ]; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - sort_by: "price", - sort_order: "ascending", - filter_name: "group_id", - filter_value: "Clothing", - url: "http://constructor.io", + sort_by: 'price', + sort_order: 'ascending', + filter_name: 'group_id', + filter_value: 'Clothing', + url: 'http://constructor.io', result_count: 5, result_page: 1, - result_id: "result-id", - selected_filters: { foo: ["bar"] }, + result_id: 'result-id', + selected_filters: { foo: ['bar'] }, items: snakeCaseItems, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("sort_by") - .to.equal(snakeCaseParameters.sort_by); - expect(requestParams) - .to.have.property("sort_order") - .to.equal(snakeCaseParameters.sort_order); - expect(requestParams) - .to.have.property("filter_name") - .to.equal(snakeCaseParameters.filter_name); - expect(requestParams) - .to.have.property("filter_value") - .to.equal(snakeCaseParameters.filter_value); - expect(requestParams) - .to.have.property("url") - .to.equal(snakeCaseParameters.url); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('sort_by').to.equal(snakeCaseParameters.sort_by); + expect(requestParams).to.have.property('sort_order').to.equal(snakeCaseParameters.sort_order); + expect(requestParams).to.have.property('filter_name').to.equal(snakeCaseParameters.filter_name); + expect(requestParams).to.have.property('filter_value').to.equal(snakeCaseParameters.filter_value); + expect(requestParams).to.have.property('url').to.equal(snakeCaseParameters.url); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultsLoaded(snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("sort_by") - .to.equal(requiredParameters.sortBy); - expect(requestParams) - .to.have.property("sort_order") - .to.equal(requiredParameters.sortOrder); - expect(requestParams) - .to.have.property("filter_name") - .to.equal(requiredParameters.filterName); - expect(requestParams) - .to.have.property("filter_value") - .to.equal(requiredParameters.filterValue); - expect(requestParams) - .to.have.property("url") - .to.equal(requiredParameters.url); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('sort_by').to.equal(requiredParameters.sortBy); + expect(requestParams).to.have.property('sort_order').to.equal(requiredParameters.sortOrder); + expect(requestParams).to.have.property('filter_name').to.equal(requiredParameters.filterName); + expect(requestParams).to.have.property('filter_value').to.equal(requiredParameters.filterValue); + expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7128,16 +6283,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7147,39 +6302,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(clonedParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -7187,27 +6336,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7215,27 +6362,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7243,101 +6388,76 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("result_count") - .to.equal(optionalParameters.resultCount); - expect(requestParams) - .to.have.property("result_page") - .to.equal(optionalParameters.resultPage); - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("selected_filters") - .to.deep.equal(optionalParameters.selectedFilters); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); + expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('selected_filters').to.deep.equal(optionalParameters.selectedFilters); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultsLoaded({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should send all items when more than 100 items are provided", (done) => { + it('Should send all items when more than 100 items are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - const items = [...Array(150).keys()].map((i) => ({ - item_id: i.toString(), - })); + const items = [...Array(150).keys()].map((i) => ({ item_id: i.toString() })); const parameters = { ...requiredParameters, items, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("items").to.deep.equal(items); + expect(requestParams).to.have.property('items').to.deep.equal(items); expect(requestParams.items).to.have.lengthOf(150); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7345,19 +6465,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(parameters)).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultsLoaded([])).to.be.an("error"); + expect(tracker.trackBrowseResultsLoaded([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultsLoaded()).to.be.an("error"); + expect(tracker.trackBrowseResultsLoaded()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7365,7 +6485,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -7373,18 +6493,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7392,43 +6510,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackBrowseResultsLoaded(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackBrowseResultsLoaded(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -7437,19 +6551,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7458,29 +6570,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7488,26 +6598,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should truncate url param to 2048 characters max", (done) => { + it('Should truncate url param to 2048 characters max', (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -7517,7 +6625,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -7535,142 +6643,128 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultsLoaded(parameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + })).to.equal(true); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackBrowseResultsLoaded({ - ...requiredParameters, - ...optionalParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultsLoaded({ + ...requiredParameters, + ...optionalParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackBrowseRedirect", () => { + describe('trackBrowseRedirect', () => { const requiredParameters = { - filterName: "group_id", - filterValue: "Clothing", - searchTerm: "books", + filterName: 'group_id', + filterValue: 'Clothing', + searchTerm: 'books', }; const optionalParameters = { - section: "Products", - selectedFilters: { foo: ["bar"] }, + section: 'Products', + selectedFilters: { foo: ['bar'] }, analyticsTags: testAnalyticsTag, - redirectToUrl: "https://demo.constructor.io/books", - userInput: "book", + redirectToUrl: 'https://demo.constructor.io/books', + userInput: 'book', }; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("filter_name") - .to.equal(requiredParameters.filterName); - expect(requestParams) - .to.have.property("filter_value") - .to.equal(requiredParameters.filterValue); - expect(requestParams) - .to.have.property("search_term") - .to.equal(requiredParameters.searchTerm); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('filter_name').to.equal(requiredParameters.filterName); + expect(requestParams).to.have.property('filter_value').to.equal(requiredParameters.filterValue); + expect(requestParams).to.have.property('search_term').to.equal(requiredParameters.searchTerm); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7678,7 +6772,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7686,16 +6780,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7705,28 +6799,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(clonedParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7734,8 +6824,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -7743,16 +6833,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7760,8 +6850,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7769,16 +6859,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7786,8 +6876,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7795,18 +6885,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -7814,62 +6902,47 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("redirect_to_url") - .to.equal(optionalParameters.redirectToUrl); - expect(requestParams) - .to.have.property("user_input") - .to.equal(optionalParameters.userInput); - expect(requestParams) - .to.have.property("selected_filters") - .to.deep.equal(optionalParameters.selectedFilters); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('redirect_to_url').to.equal(optionalParameters.redirectToUrl); + expect(requestParams).to.have.property('user_input').to.equal(optionalParameters.userInput); + expect(requestParams).to.have.property('selected_filters').to.deep.equal(optionalParameters.selectedFilters); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseRedirect({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackBrowseRedirect({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseRedirect([])).to.be.an("error"); + expect(tracker.trackBrowseRedirect([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseRedirect()).to.be.an("error"); + expect(tracker.trackBrowseRedirect()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7877,7 +6950,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -7885,8 +6958,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -7894,7 +6967,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -7902,16 +6975,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -7920,23 +6993,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackBrowseRedirect(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackBrowseRedirect(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -7945,7 +7016,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -7954,8 +7025,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -7964,16 +7035,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -7981,10 +7052,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseRedirect(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -7992,16 +7063,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8010,123 +7081,105 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackBrowseResultClick", () => { + describe('trackBrowseResultClick', () => { // Note: `variation_id` parameter not being passed as none are defined for this item_id in catalog const requiredParameters = { - itemId: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", - filterName: "group_id", - filterValue: "BrandXY", - itemName: "Pencil", + itemId: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', + filterName: 'group_id', + filterValue: 'BrandXY', + itemName: 'Pencil', }; const legacyParameters = { - filterName: "group_id", - filterValue: "BrandXY", - name: "Pencil", - customerId: "customer-id", + filterName: 'group_id', + filterValue: 'BrandXY', + name: 'Pencil', + customerId: 'customer-id', }; const optionalParameters = { - section: "Products", + section: 'Products', resultCount: 5, resultPage: 1, - resultId: "result-id", + resultId: 'result-id', resultPositionOnPage: 10, numResultsPerPage: 5, - selectedFilters: { foo: ["bar"] }, + selectedFilters: { foo: ['bar'] }, analyticsTags: testAnalyticsTag, - slCampaignOwner: "Campaign Man", - slCampaignId: "Campaign 123", + slCampaignOwner: 'Campaign Man', + slCampaignId: 'Campaign 123', }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", - item_name: "Pencil", - variation_id: "product-variation", - filter_name: "group_id", - filter_value: "Clothing", + item_id: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', + item_name: 'Pencil', + variation_id: 'product-variation', + filter_name: 'group_id', + filter_value: 'Clothing', result_count: 5, result_page: 1, - result_id: "result-id", + result_id: 'result-id', result_position_on_page: 10, num_results_per_page: 5, - selected_filters: { foo: ["bar"] }, + selected_filters: { foo: ['bar'] }, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); - expect(requestParams) - .to.have.property("item_name") - .to.equal(snakeCaseParameters.item_name); - expect(requestParams) - .to.have.property("filter_name") - .to.equal(snakeCaseParameters.filter_name); - expect(requestParams) - .to.have.property("filter_value") - .to.equal(snakeCaseParameters.filter_value); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); + expect(requestParams).to.have.property('filter_name').to.equal(snakeCaseParameters.filter_name); + expect(requestParams).to.have.property('filter_value').to.equal(snakeCaseParameters.filter_value); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackBrowseResultClick(snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultClick(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("filter_name") - .to.equal(requiredParameters.filterName); - expect(requestParams) - .to.have.property("filter_value") - .to.equal(requiredParameters.filterValue); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('filter_name').to.equal(requiredParameters.filterName); + expect(requestParams).to.have.property('filter_value').to.equal(requiredParameters.filterValue); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8134,7 +7187,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -8142,16 +7195,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8161,28 +7214,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(clonedParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8190,8 +7239,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -8199,16 +7248,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8216,8 +7265,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8225,16 +7274,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8242,8 +7291,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8251,18 +7300,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8270,65 +7317,40 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("result_count") - .to.equal(optionalParameters.resultCount); - expect(requestParams) - .to.have.property("result_page") - .to.equal(optionalParameters.resultPage); - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("result_position_on_page") - .to.equal(optionalParameters.resultPositionOnPage); - expect(requestParams) - .to.have.property("num_results_per_page") - .to.equal(optionalParameters.numResultsPerPage); - expect(requestParams) - .to.have.property("selected_filters") - .to.deep.equal(optionalParameters.selectedFilters); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); - expect(requestParams) - .to.have.property("sl_campaign_id") - .to.deep.equal(optionalParameters.slCampaignId); - expect(requestParams) - .to.have.property("sl_campaign_owner") - .to.deep.equal(optionalParameters.slCampaignOwner); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); + expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('result_position_on_page').to.equal(optionalParameters.resultPositionOnPage); + expect(requestParams).to.have.property('num_results_per_page').to.equal(optionalParameters.numResultsPerPage); + expect(requestParams).to.have.property('selected_filters').to.deep.equal(optionalParameters.selectedFilters); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('sl_campaign_id').to.deep.equal(optionalParameters.slCampaignId); + expect(requestParams).to.have.property('sl_campaign_owner').to.deep.equal(optionalParameters.slCampaignOwner); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseResultClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultClick({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when required parameters and non-existent item id are provided", (done) => { + 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, @@ -8337,39 +7359,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const parameters = { ...requiredParameters, ...optionalParameters, - itemId: "non-existent-item-id", + itemId: 'non-existent-item-id', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (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); + 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.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8377,19 +7385,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(parameters)).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultClick([])).to.be.an("error"); + expect(tracker.trackBrowseResultClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackBrowseResultClick()).to.be.an("error"); + expect(tracker.trackBrowseResultClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8397,7 +7405,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -8405,8 +7413,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8414,7 +7422,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8422,16 +7430,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8440,23 +7448,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackBrowseResultClick(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackBrowseResultClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -8465,19 +7471,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -8486,16 +7490,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8503,10 +7507,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8514,16 +7518,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8531,28 +7535,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when legacy parameters are provided", (done) => { + it('Should respond with a valid response when legacy parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("item_id") - .to.equal(legacyParameters.customerId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(legacyParameters.name); + expect(requestParams).to.have.property('item_id').to.equal(legacyParameters.customerId); + expect(requestParams).to.have.property('item_name').to.equal(legacyParameters.name); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8560,181 +7560,165 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackBrowseResultClick(legacyParameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseResultClick({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultClick({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackBrowseResultClick({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultClick({ + ...requiredParameters, + })).to.equal(true); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackBrowseResultClick({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackBrowseResultClick({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackGenericResultClick", () => { + describe('trackGenericResultClick', () => { // Note: `variation_id` parameter not being passed as none are defined for this item_id in catalog const requiredParameters = { - itemId: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", + itemId: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', }; const optionalParameters = { - itemName: "Example Product Name", - section: "Products", + itemName: 'Example Product Name', + section: 'Products', analyticsTags: testAnalyticsTag, }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - item_id: "product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new", - item_name: "Example Product Name", - variation_id: "product-variation", + item_id: 'product0dbae320-3950-11ea-9251-8dee6d0eb3cd-new', + item_name: 'Example Product Name', + variation_id: 'product-variation', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackGenericResultClick(snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response and section should be defaulted when required parameters are provided", (done) => { + it('Should respond with a valid response and section should be defaulted when required parameters are provided', (done) => { const clonedParameters = cloneDeep(requiredParameters); const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -8742,16 +7726,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -8761,39 +7745,33 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackGenericResultClick(clonedParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -8801,27 +7779,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -8829,27 +7805,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8857,7 +7831,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -8867,58 +7841,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { .to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(optionalParameters.itemName); - expect(requestParams) - .to.have.property("analytics_tags") - .to.deep.equal(testAnalyticsTag); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(optionalParameters.itemName); + expect(requestParams).to.have.property('analytics_tags').to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackGenericResultClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackGenericResultClick({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when required parameters and non-existent item id are provided", (done) => { + 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, @@ -8927,27 +7886,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { const parameters = { ...requiredParameters, ...optionalParameters, - itemId: "non-existent-item-id", + itemId: 'non-existent-item-id', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (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.deep.equal(parameters.itemName); + 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.deep.equal(parameters.itemName); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -8955,19 +7908,19 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackGenericResultClick(parameters)).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackGenericResultClick([])).to.be.an("error"); + expect(tracker.trackGenericResultClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackGenericResultClick()).to.be.an("error"); + expect(tracker.trackGenericResultClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -8975,7 +7928,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -8983,18 +7936,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9002,43 +7953,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackGenericResultClick(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackGenericResultClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -9047,19 +7994,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -9068,29 +8013,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9098,281 +8041,235 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackGenericResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackGenericResultClick(requiredParameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackGenericResultClick({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackGenericResultClick({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackGenericResultClick({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackGenericResultClick({ + ...requiredParameters, + })).to.equal(true); }); }); - describe("trackQuizResultsLoaded", () => { + describe('trackQuizResultsLoaded', () => { const requiredParameters = { - quizId: "coffee-quiz", - quizVersionId: "1231243", - quizSessionId: "13443", - url: "www.example.com", + quizId: 'coffee-quiz', + quizVersionId: '1231243', + quizSessionId: '13443', + url: 'www.example.com', }; const optionalParameters = { - section: "Products", + section: 'Products', resultCount: 1, - resultId: "12312", + resultId: '12312', resultPage: 1, items: [ { - itemId: "123", - variationId: "456", + itemId: '123', + variationId: '456', }, { - itemName: "product test", - itemId: "789", + itemName: 'product test', + itemId: '789', }, ], }; const snakeCaseItems = [ { // cspell:disable-next-line - item_id: "123", - variation_id: "456", + item_id: '123', + variation_id: '456', }, { - item_name: "product test", - item_id: "789", + item_name: 'product test', + item_id: '789', }, ]; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - quiz_id: "coffee-quiz", - quiz_version_id: "1231243", - quiz_session_id: "13443", - url: "www.example.com", + quiz_id: 'coffee-quiz', + quiz_version_id: '1231243', + quiz_session_id: '13443', + url: 'www.example.com', items: snakeCaseItems, }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(snakeCaseParameters.quiz_id); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(snakeCaseParameters.quiz_version_id); - expect(requestParams) - .to.have.property("url") - .to.equal(snakeCaseParameters.url); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('quiz_id').to.equal(snakeCaseParameters.quiz_id); + expect(requestParams).to.have.property('quiz_version_id').to.equal(snakeCaseParameters.quiz_version_id); + expect(requestParams).to.have.property('url').to.equal(snakeCaseParameters.url); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackQuizResultsLoaded(snakeCaseParameters)).to.equal( - true, - ); + expect(tracker.trackQuizResultsLoaded(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(requiredParameters.quizId); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(requiredParameters.quizVersionId); - expect(requestParams) - .to.have.property("url") - .to.equal(requiredParameters.url); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); + expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); + expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when result_count is zero", (done) => { + it('Should respond with a valid response when result_count is zero', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(requiredParameters.quizId); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(requiredParameters.quizVersionId); - expect(requestParams) - .to.have.property("url") - .to.equal(requiredParameters.url); - expect(requestParams).to.have.property("result_count").to.equal(0); + expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); + expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); + expect(requestParams).to.have.property('url').to.equal(requiredParameters.url); + expect(requestParams).to.have.property('result_count').to.equal(0); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - result_count: 0, - }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, result_count: 0 })).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9380,8 +8277,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -9389,16 +8286,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9406,8 +8303,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9415,16 +8312,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9432,8 +8329,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9441,18 +8338,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9460,162 +8355,120 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("result_count") - .to.equal(optionalParameters.resultCount); - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("result_page") - .to.equal(optionalParameters.resultPage); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should throw an error when invalid quizId is provided", () => { + it('Should throw an error when invalid quizId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ ...requiredParameters, quizId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, quizId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid quizVersionId is provided", () => { + it('Should throw an error when invalid quizVersionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - quizVersionId: 1, - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, quizVersionId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid quizSessionId is provided", () => { + it('Should throw an error when invalid quizSessionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - quizSessionId: 1, - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, quizSessionId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid url is provided", () => { + it('Should throw an error when invalid url is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ ...requiredParameters, url: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, url: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid section is provided", () => { + it('Should throw an error when invalid section is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid resultCount is provided", () => { + it('Should throw an error when invalid resultCount is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultCount: "1", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, resultCount: '1' })).to.be.an('error'); }); - it("Should throw an error when invalid resultPage is provided", () => { + it('Should throw an error when invalid resultPage is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultPage: "1", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, resultPage: '1' })).to.be.an('error'); }); - it("Should throw an error when invalid resultId is provided", () => { + it('Should throw an error when invalid resultId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ ...requiredParameters, resultId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, resultId: 1 })).to.be.an('error'); }); - it("Should throw an error when no quiz_id is provided", () => { + it('Should throw an error when no quiz_id is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); }); - it("Should throw an error when no quiz_version_id is provided", () => { + it('Should throw an error when no quiz_version_id is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizVersionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); }); - it("Should throw an error when no quiz_session_id is provided", () => { + it('Should throw an error when no quiz_session_id is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizSessionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); }); - it("Should throw an error when no url is provided", () => { + it('Should throw an error when no url is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { url: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultsLoaded(rest)).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded(rest)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded([])).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultsLoaded()).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9623,7 +8476,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -9631,8 +8484,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9640,7 +8493,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -9648,16 +8501,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9666,23 +8519,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackQuizResultsLoaded(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -9691,19 +8542,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -9712,16 +8561,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9729,10 +8578,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -9740,16 +8589,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9757,7 +8606,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true); }); - it("Should truncate url param to 2048 characters max", (done) => { + it('Should truncate url param to 2048 characters max', (done) => { const longUrl = createLongUrl(3000); const truncatedUrl = longUrl.slice(0, 2048); @@ -9767,7 +8616,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", () => { + tracker.on('success', () => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -9785,170 +8634,152 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultsLoaded(parameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded({ + ...requiredParameters, + })).to.equal(true); }); - it("Should return an error when resultOffset is not a number", () => { + it('Should return an error when resultOffset is not a number', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultOffset: "not-a-number", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultOffset: 'not-a-number', + })).to.be.an('error'); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackQuizResultsLoaded({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackQuizResultsLoaded({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackQuizResultClick", () => { + describe('trackQuizResultClick', () => { const requiredParameters = { - quizId: "coffee-quiz", - quizVersionId: "1231243", - quizSessionId: "13443", - itemName: "espresso", - itemId: "1123", + quizId: 'coffee-quiz', + quizVersionId: '1231243', + quizSessionId: '13443', + itemName: 'espresso', + itemId: '1123', }; const optionalParameters = { - section: "Products", + section: 'Products', resultCount: 1, - resultId: "12312", + resultId: '12312', resultPage: 1, numResultsPerPage: 100, resultPositionOnPage: 1, - variationId: "123123", + variationId: '123123', }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - quiz_id: "coffee-quiz", - quiz_version_id: "1231243", - quiz_session_id: "13443", - item_name: "espresso", - item_id: "1123", + quiz_id: 'coffee-quiz', + quiz_version_id: '1231243', + quiz_session_id: '13443', + item_name: 'espresso', + item_id: '1123', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(snakeCaseParameters.quiz_id); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(snakeCaseParameters.quiz_version_id); - expect(requestParams) - .to.have.property("item_name") - .to.equal(snakeCaseParameters.item_name); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('quiz_id').to.equal(snakeCaseParameters.quiz_id); + expect(requestParams).to.have.property('quiz_version_id').to.equal(snakeCaseParameters.quiz_version_id); + expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9956,40 +8787,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(requiredParameters.quizId); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(requiredParameters.quizVersionId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); + expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -9997,8 +8820,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -10006,16 +8829,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10023,28 +8846,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10052,8 +8871,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10061,16 +8880,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10078,8 +8897,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10087,18 +8906,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10106,195 +8923,139 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("result_count") - .to.equal(optionalParameters.resultCount); - expect(requestParams) - .to.have.property("result_id") - .to.equal(optionalParameters.resultId); - expect(requestParams) - .to.have.property("result_page") - .to.equal(optionalParameters.resultPage); - expect(requestParams) - .to.have.property("num_results_per_page") - .to.equal(optionalParameters.numResultsPerPage); - expect(requestParams) - .to.have.property("result_position_on_page") - .to.equal(optionalParameters.resultPositionOnPage); - expect(requestParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('result_count').to.equal(optionalParameters.resultCount); + expect(requestParams).to.have.property('result_id').to.equal(optionalParameters.resultId); + expect(requestParams).to.have.property('result_page').to.equal(optionalParameters.resultPage); + expect(requestParams).to.have.property('num_results_per_page').to.equal(optionalParameters.numResultsPerPage); + expect(requestParams).to.have.property('result_position_on_page').to.equal(optionalParameters.resultPositionOnPage); + expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackQuizResultClick({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should throw an error when invalid quizId is provided", () => { + it('Should throw an error when invalid quizId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ ...requiredParameters, quizId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, quizId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid quizVersionId is provided", () => { + it('Should throw an error when invalid quizVersionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - quizVersionId: 1, - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, quizVersionId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid quizSessionId is provided", () => { + it('Should throw an error when invalid quizSessionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - quizSessionId: 1, - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, quizSessionId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid itemId is provided", () => { + it('Should throw an error when invalid itemId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ ...requiredParameters, itemId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, itemId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid itemName is provided", () => { + it('Should throw an error when invalid itemName is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ ...requiredParameters, itemName: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, itemName: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid section is provided", () => { + it('Should throw an error when invalid section is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultsLoaded({ ...requiredParameters, section: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid resultCount is provided", () => { + it('Should throw an error when invalid resultCount is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - resultCount: "1", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, resultCount: '1' })).to.be.an('error'); }); - it("Should throw an error when invalid resultPage is provided", () => { + it('Should throw an error when invalid resultPage is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - resultPage: "1", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, resultPage: '1' })).to.be.an('error'); }); - it("Should throw an error when invalid resultId is provided", () => { + it('Should throw an error when invalid resultId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ ...requiredParameters, resultId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, resultId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid numResultsPerPage is provided", () => { + it('Should throw an error when invalid numResultsPerPage is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - numResultsPerPage: "1", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, numResultsPerPage: '1' })).to.be.an('error'); }); - it("Should throw an error when invalid resultPositionOnPage is provided", () => { + it('Should throw an error when invalid resultPositionOnPage is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - resultPositionOnPage: "1", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ ...requiredParameters, resultPositionOnPage: '1' })).to.be.an('error'); }); - it("Should throw an error when no quizId is provided", () => { + it('Should throw an error when no quizId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); + expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); }); - it("Should throw an error when no quizVersionId is provided", () => { + it('Should throw an error when no quizVersionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizVersionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); + expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); }); - it("Should throw an error when no quizSessionId is provided", () => { + it('Should throw an error when no quizSessionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizSessionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); + expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); }); - it("Should throw an error when no itemId nor item_name is provided", () => { + it('Should throw an error when no itemId nor item_name is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { itemName: _, itemId: __, ...rest } = requiredParameters; - expect(tracker.trackQuizResultClick(rest)).to.be.an("error"); + expect(tracker.trackQuizResultClick(rest)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick([])).to.be.an("error"); + expect(tracker.trackQuizResultClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizResultClick()).to.be.an("error"); + expect(tracker.trackQuizResultClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10302,7 +9063,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -10310,8 +9071,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10319,7 +9080,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10327,16 +9088,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10345,23 +9106,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackQuizResultClick(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackQuizResultClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -10370,7 +9129,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -10379,8 +9138,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -10389,16 +9148,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10406,10 +9165,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10417,16 +9176,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10434,169 +9193,151 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizResultClick(requiredParameters)).to.equal(true); }); - it("Should return valid response when resultOffset is passed as an integer", (done) => { + it('Should return valid response when resultOffset is passed as an integer', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_offset").to.equal(1); + expect(requestParams).to.have.property('result_offset').to.equal(1); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackQuizResultClick({ + ...requiredParameters, + resultOffset: 1, + })).to.equal(true); }); - it("Should return valid response and omit result_offset when resultOffset is not provided", (done) => { + it('Should return valid response and omit result_offset when resultOffset is not provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("result_offset"); + expect(requestParams).to.not.have.property('result_offset'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - }), - ).to.equal(true); + expect(tracker.trackQuizResultClick({ + ...requiredParameters, + })).to.equal(true); }); - it("Should return an error when resultOffset is not a number", () => { + it('Should return an error when resultOffset is not a number', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - resultOffset: "not-a-number", - }), - ).to.be.an("error"); + expect(tracker.trackQuizResultClick({ + ...requiredParameters, + resultOffset: 'not-a-number', + })).to.be.an('error'); }); - it("Should receive error from backend when both resultPage and resultOffset are passed", (done) => { + it('Should receive error from backend when both resultPage and resultOffset are passed', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("result_page"); - expect(requestParams).to.have.property("result_offset"); + expect(requestParams).to.have.property('result_page'); + expect(requestParams).to.have.property('result_offset'); // Response - expect(error) - .to.have.property("message") - .to.equal("Invalid parameters"); + expect(error).to.have.property('message').to.equal('Invalid parameters'); done(); }); - expect( - tracker.trackQuizResultClick({ - ...requiredParameters, - resultPage: 10, - resultOffset: 1, - }), - ).to.equal(true); + expect(tracker.trackQuizResultClick({ + ...requiredParameters, + resultPage: 10, + resultOffset: 1, + })).to.equal(true); }); }); - describe("trackQuizConversion", () => { + describe('trackQuizConversion', () => { const requiredParameters = { - quizId: "coffee-quiz", - quizVersionId: "1231243", - quizSessionId: "13443", - itemName: "espresso", - itemId: "1123", + quizId: 'coffee-quiz', + quizVersionId: '1231243', + quizSessionId: '13443', + itemName: 'espresso', + itemId: '1123', }; const optionalParameters = { - variationId: "123", - section: "Products", - type: "add_to_cart", - revenue: "1.0", + variationId: '123', + section: 'Products', + type: 'add_to_cart', + revenue: '1.0', isCustomType: false, - displayName: "name", + displayName: 'name', }; - it("Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided", (done) => { + it('Backwards Compatibility - Should respond with a valid response when snake cased parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); const snakeCaseParameters = { - quiz_id: "coffee-quiz", - quiz_version_id: "1231243", - quiz_session_id: "13443", - item_name: "espresso", - item_id: "1123", + quiz_id: 'coffee-quiz', + quiz_version_id: '1231243', + quiz_session_id: '13443', + item_name: 'espresso', + item_id: '1123', }; - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(snakeCaseParameters.quiz_id); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(snakeCaseParameters.quiz_version_id); - expect(requestParams) - .to.have.property("item_name") - .to.equal(snakeCaseParameters.item_name); - expect(requestParams) - .to.have.property("item_id") - .to.equal(snakeCaseParameters.item_id); + expect(requestParams).to.have.property('quiz_id').to.equal(snakeCaseParameters.quiz_id); + expect(requestParams).to.have.property('quiz_version_id').to.equal(snakeCaseParameters.quiz_version_id); + expect(requestParams).to.have.property('item_name').to.equal(snakeCaseParameters.item_name); + expect(requestParams).to.have.property('item_id').to.equal(snakeCaseParameters.item_id); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10604,40 +9345,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(snakeCaseParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("quiz_id") - .to.equal(requiredParameters.quizId); - expect(requestParams) - .to.have.property("quiz_version_id") - .to.equal(requiredParameters.quizVersionId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('quiz_id').to.equal(requiredParameters.quizId); + expect(requestParams).to.have.property('quiz_version_id').to.equal(requiredParameters.quizVersionId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10645,28 +9378,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10674,8 +9403,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -10683,16 +9412,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10700,8 +9429,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -10709,16 +9438,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10726,8 +9455,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10735,18 +9464,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10754,186 +9481,139 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("type") - .to.equal(optionalParameters.type); - expect(requestParams) - .to.have.property("revenue") - .to.equal(optionalParameters.revenue); - expect(requestParams) - .to.have.property("is_custom_type") - .to.equal(optionalParameters.isCustomType); - expect(requestParams) - .to.have.property("display_name") - .to.equal(optionalParameters.displayName); + expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('type').to.equal(optionalParameters.type); + expect(requestParams).to.have.property('revenue').to.equal(optionalParameters.revenue); + expect(requestParams).to.have.property('is_custom_type').to.equal(optionalParameters.isCustomType); + expect(requestParams).to.have.property('display_name').to.equal(optionalParameters.displayName); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackQuizConversion({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackQuizConversion({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should throw an error when invalid quizId is provided", () => { + it('Should throw an error when invalid quizId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, quizId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, quizId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid quizVersionId is provided", () => { + it('Should throw an error when invalid quizVersionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ - ...requiredParameters, - quizVersionId: 1, - }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, quizVersionId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid quizSessionId is provided", () => { + it('Should throw an error when invalid quizSessionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ - ...requiredParameters, - quizSessionId: 1, - }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, quizSessionId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid itemId is provided", () => { + it('Should throw an error when invalid itemId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, itemId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, itemId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid itemName is provided", () => { + it('Should throw an error when invalid itemName is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, itemName: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, itemName: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid section is provided", () => { + it('Should throw an error when invalid section is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, section: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, section: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid variationId is provided", () => { + it('Should throw an error when invalid variationId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, variationId: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, variationId: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid type is provided", () => { + it('Should throw an error when invalid type is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, type: 0 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, type: 0 })).to.be.an('error'); }); - it("Should throw an error when invalid revenue is provided", () => { + it('Should throw an error when invalid revenue is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, revenue: 1 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, revenue: 1 })).to.be.an('error'); }); - it("Should throw an error when invalid isCustomType is provided", () => { + it('Should throw an error when invalid isCustomType is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ - ...requiredParameters, - isCustomType: "true", - }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, isCustomType: 'true' })).to.be.an('error'); }); - it("Should throw an error when invalid displayName is provided", () => { + it('Should throw an error when invalid displayName is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackQuizConversion({ ...requiredParameters, displayName: 0 }), - ).to.be.an("error"); + expect(tracker.trackQuizConversion({ ...requiredParameters, displayName: 0 })).to.be.an('error'); }); - it("Should throw an error when no quizId is provided", () => { + it('Should throw an error when no quizId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an("error"); + expect(tracker.trackQuizConversion(rest)).to.be.an('error'); }); - it("Should throw an error when no quizVersionId is provided", () => { + it('Should throw an error when no quizVersionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizVersionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an("error"); + expect(tracker.trackQuizConversion(rest)).to.be.an('error'); }); - it("Should throw an error when no quizSessionId is provided", () => { + it('Should throw an error when no quizSessionId is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { quizSessionId: _, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an("error"); + expect(tracker.trackQuizConversion(rest)).to.be.an('error'); }); - it("Should throw an error when no itemId nor itemName is provided", () => { + it('Should throw an error when no itemId nor itemName is provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); const { itemName: _, itemId: __, ...rest } = requiredParameters; - expect(tracker.trackQuizConversion(rest)).to.be.an("error"); + expect(tracker.trackQuizConversion(rest)).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion([])).to.be.an("error"); + expect(tracker.trackQuizConversion([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackQuizConversion()).to.be.an("error"); + expect(tracker.trackQuizConversion()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10941,7 +9621,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -10949,8 +9629,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10958,7 +9638,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -10966,16 +9646,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -10984,23 +9664,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackQuizConversion(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackQuizConversion(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -11009,7 +9687,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -11018,8 +9696,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -11028,16 +9706,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11045,10 +9723,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackQuizConversion(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11056,16 +9734,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11074,32 +9752,32 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("on", () => { - it("Should throw an error when providing an invalid messageType parameter", () => { + describe('on', () => { + it('Should throw an error when providing an invalid messageType parameter', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.on("invalid")).to.be.an("error"); + expect(tracker.on('invalid')).to.be.an('error'); }); - it("Should throw an error when providing no messageType parameter", () => { + 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", () => { + it('Should throw an error when providing an invalid callback parameter', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.on("success", {})).to.be.an("error"); + expect(tracker.on('success', {})).to.be.an('error'); }); - it("Should throw an error when providing no callback parameter", () => { + it('Should throw an error when providing no callback parameter', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.on("success", null)).to.be.an("error"); + expect(tracker.on('success', null)).to.be.an('error'); }); - it("Should receive a success message when making a request to a valid endpoint", (done) => { + it('Should receive a success message when making a request to a valid endpoint', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11108,83 +9786,81 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { tracker.trackSessionStart(); - tracker.on("success", (response) => { - expect(response).to.have.property("url"); - expect(response).to.have.property("method"); - expect(response).to.have.property("message").to.equal("ok"); + tracker.on('success', (response) => { + expect(response).to.have.property('url'); + expect(response).to.have.property('method'); + expect(response).to.have.property('message').to.equal('ok'); done(); }); }); - it("Should receive an error message when making a request to an endpoint that does not return valid JSON", (done) => { + it('Should receive an error message when making a request to an endpoint that does not return valid JSON', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, - serviceUrl: "http://constructor.io", + serviceUrl: 'http://constructor.io', ...requestQueueOptions, }); tracker.trackSessionStart(); - tracker.on("error", (response) => { - expect(response).to.have.property("url"); - expect(response).to.have.property("method"); - expect(response).to.have.property("message"); + tracker.on('error', (response) => { + expect(response).to.have.property('url'); + expect(response).to.have.property('method'); + expect(response).to.have.property('message'); done(); }); }); - it("Should receive an error message when making a request to an invalid endpoint", (done) => { + it('Should receive an error message when making a request to an invalid endpoint', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, - serviceUrl: "invalid", + serviceUrl: 'invalid', ...requestQueueOptions, }); tracker.trackSessionStart(); - tracker.on("error", (response) => { - expect(response).to.have.property("url"); - expect(response).to.have.property("method"); - expect(response).to.have.property("message"); + tracker.on('error', (response) => { + expect(response).to.have.property('url'); + expect(response).to.have.property('method'); + expect(response).to.have.property('message'); done(); }); }); }); - describe("trackAgentSubmit", () => { - const requiredParameters = { intent: "Show me cookie recipes" }; + describe('trackAgentSubmit', () => { + const requiredParameters = { intent: 'Show me cookie recipes' }; const optionalParameters = { - section: "Products", - threadId: "thread-1234", + section: 'Products', + threadId: 'thread-1234', }; - it("Should respond with a valid response when intent and required parameters are provided", (done) => { + it('Should respond with a valid response when intent and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11192,28 +9868,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11221,8 +9893,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -11230,16 +9902,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11247,8 +9919,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11256,16 +9928,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11273,8 +9945,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11282,18 +9954,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11301,51 +9971,44 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); - expect(requestParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal('Products'); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAgentSubmit({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAgentSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSubmit()).to.be.an("error"); + expect(tracker.trackAgentSubmit()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSubmit()).to.be.an("error"); + expect(tracker.trackAgentSubmit()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11353,7 +10016,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -11361,8 +10024,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11370,7 +10033,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11378,16 +10041,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11396,23 +10059,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentSubmit(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackAgentSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -11421,7 +10082,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -11430,8 +10091,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -11440,16 +10101,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11457,10 +10118,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSubmit(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11468,16 +10129,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -11486,81 +10147,71 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackAgentResultLoadStarted", () => { - const requiredParameters = { intent: "Show me cookie recipes" }; + describe('trackAgentResultLoadStarted', () => { + const requiredParameters = { intent: 'Show me cookie recipes' }; const optionalParameters = { - section: "Products", - intentResultId: "123451", - threadId: "thread-123", + section: 'Products', + intentResultId: '123451', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -11568,27 +10219,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11596,27 +10245,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11624,78 +10271,63 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); // eslint-disable-next-line max-len - expect( - tracker.trackAgentResultLoadStarted({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAgentResultLoadStarted({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadStarted()).to.be.an("error"); + expect(tracker.trackAgentResultLoadStarted()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadStarted()).to.be.an("error"); + expect(tracker.trackAgentResultLoadStarted()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11703,7 +10335,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -11711,18 +10343,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11730,45 +10360,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentResultLoadStarted(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -11777,19 +10401,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -11798,29 +10420,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11828,107 +10448,90 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadStarted(requiredParameters)).to.equal(true); }); }); - describe("trackAgentResultLoadFinished", () => { - const requiredParameters = { - intent: "Show me cookie recipes", - searchResultCount: 15, - }; + describe('trackAgentResultLoadFinished', () => { + const requiredParameters = { intent: 'Show me cookie recipes', searchResultCount: 15 }; const optionalParameters = { - section: "Products", - intentResultId: "123451", - threadId: "thread-123", + section: 'Products', + intentResultId: '123451', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_result_count") - .to.equal(requiredParameters.searchResultCount); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_result_count').to.equal(requiredParameters.searchResultCount); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -11936,27 +10539,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -11964,27 +10565,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -11992,78 +10591,63 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); // eslint-disable-next-line max-len - expect( - tracker.trackAgentResultLoadFinished({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAgentResultLoadFinished({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadFinished()).to.be.an("error"); + expect(tracker.trackAgentResultLoadFinished()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultLoadFinished()).to.be.an("error"); + expect(tracker.trackAgentResultLoadFinished()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12071,7 +10655,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -12079,18 +10663,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12098,45 +10680,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentResultLoadFinished(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12145,19 +10721,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -12166,29 +10740,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12196,74 +10768,64 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultLoadFinished(requiredParameters)).to.equal(true); }); }); - describe("trackAgentResultClick", () => { + describe('trackAgentResultClick', () => { const requiredParameters = { - intent: "Show me cookie recipes", - searchResultId: "12341cd", - itemName: "espresso", - itemId: "1123", + intent: 'Show me cookie recipes', + searchResultId: '12341cd', + itemName: 'espresso', + itemId: '1123', }; const optionalParameters = { - section: "Products", - intentResultId: "12312", - variationId: "123123", - threadId: "thread-123", + section: 'Products', + intentResultId: '12312', + variationId: '123123', + threadId: 'thread-123', }; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_result_id") - .to.equal(requiredParameters.searchResultId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12271,28 +10833,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12300,8 +10858,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -12309,16 +10867,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12326,8 +10884,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12335,16 +10893,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12352,8 +10910,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12361,18 +10919,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12380,59 +10936,47 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(requestParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAgentResultClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAgentResultClick({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultClick([])).to.be.an("error"); + expect(tracker.trackAgentResultClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultClick()).to.be.an("error"); + expect(tracker.trackAgentResultClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12440,7 +10984,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -12448,8 +10992,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12457,7 +11001,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12465,16 +11009,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12483,23 +11027,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentResultClick(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackAgentResultClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12508,19 +11050,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -12529,16 +11069,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12546,10 +11086,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12557,16 +11097,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12575,69 +11115,63 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackAgentResultView", () => { + describe('trackAgentResultView', () => { const requiredParameters = { - intent: "Show me cookie recipes", + intent: 'Show me cookie recipes', numResultsViewed: 5, - searchResultId: "123123123", + searchResultId: '123123123', }; const optionalParameters = { - intentResultId: "result-id", - section: "Products", - threadId: "thread-123", + intentResultId: 'result-id', + section: 'Products', + threadId: 'thread-123', items: [ { - itemId: "123", - variationId: "456", + itemId: '123', + variationId: '456', }, { - itemName: "product test", - itemId: "789", + itemName: 'product test', + itemId: '789', }, ], }; const snakeCaseItems = [ { - item_id: "123", - variation_id: "456", + item_id: '123', + variation_id: '456', }, { - item_name: "product test", - item_id: "789", + item_name: 'product test', + item_id: '789', }, ]; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_result_id") - .to.equal(requiredParameters.searchResultId); - expect(requestParams) - .to.have.property("num_results_viewed") - .to.equal(requiredParameters.numResultsViewed); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property('num_results_viewed').to.equal(requiredParameters.numResultsViewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -12645,28 +11179,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -12674,8 +11204,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -12683,16 +11213,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -12700,8 +11230,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12709,18 +11239,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -12728,8 +11256,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12737,16 +11265,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); @@ -12754,59 +11282,46 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackAgentResultView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAgentResultView({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultView([])).to.be.an("error"); + expect(tracker.trackAgentResultView([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentResultView()).to.be.an("error"); + expect(tracker.trackAgentResultView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12814,7 +11329,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -12822,8 +11337,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12831,7 +11346,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -12839,16 +11354,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12857,23 +11372,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentResultView(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackAgentResultView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -12882,7 +11395,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -12891,8 +11404,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -12901,16 +11414,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12918,10 +11431,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentResultView(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -12929,16 +11442,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12947,49 +11460,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackAgentSearchSubmit", () => { - const requiredParameters = { - intent: "Show me cookie recipes", - searchTerm: "Flour", - searchResultId: "123", - }; + describe('trackAgentSearchSubmit', () => { + const requiredParameters = { intent: 'Show me cookie recipes', searchTerm: 'Flour', searchResultId: '123' }; const optionalParameters = { - section: "Products", - intentResultId: "1234", - threadId: "thread-123", + section: 'Products', + intentResultId: '1234', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_term") - .to.equal(requiredParameters.searchTerm); - expect(requestParams) - .to.have.property("search_result_id") - .to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_term').to.equal(requiredParameters.searchTerm); + expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -12997,28 +11500,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13026,8 +11525,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -13035,16 +11534,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13052,8 +11551,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13061,16 +11560,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13078,8 +11577,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13087,18 +11586,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13106,56 +11603,45 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAgentSearchSubmit({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAgentSearchSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSearchSubmit()).to.be.an("error"); + expect(tracker.trackAgentSearchSubmit()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAgentSearchSubmit()).to.be.an("error"); + expect(tracker.trackAgentSearchSubmit()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13163,7 +11649,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -13171,8 +11657,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13180,7 +11666,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13188,16 +11674,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13206,23 +11692,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAgentSearchSubmit(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackAgentSearchSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -13231,19 +11715,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -13252,16 +11734,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13269,10 +11751,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAgentSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13280,16 +11762,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13298,37 +11780,35 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackAssistantSubmit", () => { - const requiredParameters = { intent: "Show me cookie recipes" }; + describe('trackAssistantSubmit', () => { + const requiredParameters = { intent: 'Show me cookie recipes' }; const optionalParameters = { - section: "Products", + section: 'Products', }; - it("Should respond with a valid response when intent and required parameters are provided", (done) => { + it('Should respond with a valid response when intent and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13336,28 +11816,24 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13365,8 +11841,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -13374,16 +11850,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13391,8 +11867,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13400,16 +11876,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13417,8 +11893,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13426,18 +11902,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13445,48 +11919,43 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("section").to.equal("Products"); + expect(requestParams).to.have.property('section').to.equal('Products'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantSubmit({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAssistantSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSubmit()).to.be.an("error"); + expect(tracker.trackAssistantSubmit()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSubmit()).to.be.an("error"); + expect(tracker.trackAssistantSubmit()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13494,7 +11963,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -13502,8 +11971,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13511,7 +11980,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13519,16 +11988,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13537,23 +12006,21 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantSubmit(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackAssistantSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -13562,7 +12029,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -13571,8 +12038,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -13581,16 +12048,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13598,10 +12065,10 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { expect(tracker.trackAssistantSubmit(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13609,16 +12076,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -13627,80 +12094,70 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); }); - describe("trackAssistantResultLoadStarted", () => { - const requiredParameters = { intent: "Show me cookie recipes" }; + describe('trackAssistantResultLoadStarted', () => { + const requiredParameters = { intent: 'Show me cookie recipes' }; const optionalParameters = { - section: "Products", - intentResultId: "123451", + section: 'Products', + intentResultId: '123451', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -13708,27 +12165,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13736,27 +12191,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13764,75 +12217,62 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); // eslint-disable-next-line max-len - expect( - tracker.trackAssistantResultLoadStarted({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadStarted()).to.be.an("error"); + expect(tracker.trackAssistantResultLoadStarted()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadStarted()).to.be.an("error"); + expect(tracker.trackAssistantResultLoadStarted()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13840,7 +12280,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -13848,18 +12288,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -13867,45 +12305,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -13914,19 +12346,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -13935,29 +12365,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -13965,106 +12393,89 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadStarted(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadStarted(requiredParameters)).to.equal(true); }); }); - describe("trackAssistantResultLoadFinished", () => { - const requiredParameters = { - intent: "Show me cookie recipes", - searchResultCount: 15, - }; + describe('trackAssistantResultLoadFinished', () => { + const requiredParameters = { intent: 'Show me cookie recipes', searchResultCount: 15 }; const optionalParameters = { - section: "Products", - intentResultId: "123451", + section: 'Products', + intentResultId: '123451', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_result_count") - .to.equal(requiredParameters.searchResultCount); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_result_count').to.equal(requiredParameters.searchResultCount); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14072,27 +12483,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14100,27 +12509,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14128,75 +12535,62 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); // eslint-disable-next-line max-len - expect( - tracker.trackAssistantResultLoadFinished({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadFinished()).to.be.an("error"); + expect(tracker.trackAssistantResultLoadFinished()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultLoadFinished()).to.be.an("error"); + expect(tracker.trackAssistantResultLoadFinished()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14204,7 +12598,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -14212,18 +12606,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14231,45 +12623,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -14278,19 +12664,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -14299,29 +12683,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14329,115 +12711,97 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultLoadFinished(requiredParameters), - ).to.equal(true); + expect(tracker.trackAssistantResultLoadFinished(requiredParameters)).to.equal(true); }); }); - describe("trackAssistantResultClick", () => { + describe('trackAssistantResultClick', () => { const requiredParameters = { - intent: "Show me cookie recipes", - searchResultId: "12341cd", - itemName: "espresso", - itemId: "1123", + intent: 'Show me cookie recipes', + searchResultId: '12341cd', + itemName: 'espresso', + itemId: '1123', }; const optionalParameters = { - section: "Products", - intentResultId: "12312", - variationId: "123123", + section: 'Products', + intentResultId: '12312', + variationId: '123123', }; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_result_id") - .to.equal(requiredParameters.searchResultId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14445,27 +12809,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14473,27 +12835,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14501,77 +12861,63 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantResultClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultClick({ ...requiredParameters, ...optionalParameters })) + .to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultClick([])).to.be.an("error"); + expect(tracker.trackAssistantResultClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultClick()).to.be.an("error"); + expect(tracker.trackAssistantResultClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14579,7 +12925,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -14587,18 +12933,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14606,45 +12950,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantResultClick(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -14653,19 +12991,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -14674,29 +13010,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14704,130 +13038,114 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultClick(requiredParameters)).to.equal(true); }); }); - describe("trackAssistantResultView", () => { + describe('trackAssistantResultView', () => { const requiredParameters = { - intent: "Show me cookie recipes", + intent: 'Show me cookie recipes', numResultsViewed: 5, - searchResultId: "123123123", + searchResultId: '123123123', }; const optionalParameters = { - intentResultId: "result-id", - section: "Products", + intentResultId: 'result-id', + section: 'Products', items: [ { - itemId: "123", - variationId: "456", + itemId: '123', + variationId: '456', }, { - itemName: "product test", - itemId: "789", + itemName: 'product test', + itemId: '789', }, ], }; const snakeCaseItems = [ { - item_id: "123", - variation_id: "456", + item_id: '123', + variation_id: '456', }, { - item_name: "product test", - item_id: "789", + item_name: 'product test', + item_id: '789', }, ]; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_result_id") - .to.equal(requiredParameters.searchResultId); - expect(requestParams) - .to.have.property("num_results_viewed") - .to.equal(requiredParameters.numResultsViewed); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property('num_results_viewed').to.equal(requiredParameters.numResultsViewed); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -14835,27 +13153,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14863,29 +13179,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -14893,75 +13205,62 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); - expect(requestParams) - .to.have.property("items") - .to.deep.equal(snakeCaseItems); - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('items').to.deep.equal(snakeCaseItems); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message'); done(); }); - expect( - tracker.trackAssistantResultView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAssistantResultView({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultView([])).to.be.an("error"); + expect(tracker.trackAssistantResultView([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantResultView()).to.be.an("error"); + expect(tracker.trackAssistantResultView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14969,7 +13268,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -14977,18 +13276,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -14996,43 +13293,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantResultView(requiredParameters, { timeout: 10 }), - ).to.equal(true); + expect(tracker.trackAssistantResultView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -15041,19 +13334,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); } - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -15062,29 +13353,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15092,110 +13381,90 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantResultView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantResultView(requiredParameters)).to.equal(true); }); }); - describe("trackAssistantSearchSubmit", () => { - const requiredParameters = { - intent: "Show me cookie recipes", - searchTerm: "Flour", - searchResultId: "123", - }; + describe('trackAssistantSearchSubmit', () => { + const requiredParameters = { intent: 'Show me cookie recipes', searchTerm: 'Flour', searchResultId: '123' }; const optionalParameters = { - section: "Products", - intentResultId: "1234", + section: 'Products', + intentResultId: '1234', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("intent") - .to.equal(requiredParameters.intent); - expect(requestParams) - .to.have.property("search_term") - .to.equal(requiredParameters.searchTerm); - expect(requestParams) - .to.have.property("search_result_id") - .to.equal(requiredParameters.searchResultId); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('intent').to.equal(requiredParameters.intent); + expect(requestParams).to.have.property('search_term').to.equal(requiredParameters.searchTerm); + expect(requestParams).to.have.property('search_result_id').to.equal(requiredParameters.searchResultId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -15203,27 +13472,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15231,27 +13498,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15259,74 +13524,61 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(requestParams) - .to.have.property("intent_result_id") - .to.equal(optionalParameters.intentResultId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(requestParams).to.have.property('intent_result_id').to.equal(optionalParameters.intentResultId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackAssistantSearchSubmit({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackAssistantSearchSubmit({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSearchSubmit()).to.be.an("error"); + expect(tracker.trackAssistantSearchSubmit()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackAssistantSearchSubmit()).to.be.an("error"); + expect(tracker.trackAssistantSearchSubmit()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15334,7 +13586,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -15342,18 +13594,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15361,45 +13611,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackAssistantSearchSubmit(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackAssistantSearchSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -15408,19 +13652,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -15429,29 +13671,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15459,128 +13699,110 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackAssistantSearchSubmit(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentViews", () => { + describe('trackProductInsightsAgentViews', () => { const requiredParameters = { - itemId: "1", - itemName: "item1", + itemId: '1', + itemName: 'item1', questions: [ - { question: "Why choose this?" }, - { question: "How is this product made?" }, - { question: "What are the dimensions of this product?" }, + { question: 'Why choose this?' }, + { question: 'How is this product made?' }, + { question: 'What are the dimensions of this product?' }, ], viewTimespans: [ { - start: "2025-05-19T14:30:00+02:00", - end: "2025-05-19T14:30:05+02:00", + start: '2025-05-19T14:30:00+02:00', + end: '2025-05-19T14:30:05+02:00', }, { - start: "2025-05-19T14:30:10+02:00", - end: "2025-05-19T14:30:15+02:00", + start: '2025-05-19T14:30:10+02:00', + end: '2025-05-19T14:30:15+02:00', }, ], }; const optionalParameters = { - section: "Products", - variationId: "2", - threadId: "thread-123", + section: 'Products', + variationId: '2', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("questions") - .to.deep.equal(requiredParameters.questions); - expect(requestParams) - .to.have.property("view_timespans") - .to.deep.equal(requiredParameters.viewTimespans); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('questions').to.deep.equal(requiredParameters.questions); + expect(requestParams).to.have.property('view_timespans').to.deep.equal(requiredParameters.viewTimespans); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -15588,27 +13810,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15616,27 +13836,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15644,78 +13862,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentViews()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentViews()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentViews()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentViews()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15723,7 +13928,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -15731,18 +13936,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -15750,45 +13953,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -15797,19 +13994,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -15818,29 +14013,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15848,115 +14041,99 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentViews(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentViews(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentView", () => { + describe('trackProductInsightsAgentView', () => { const requiredParameters = { - itemId: "1", - itemName: "item1", + itemId: '1', + itemName: 'item1', questions: [ - { question: "Why choose this?" }, - { question: "How is this product made?" }, - { question: "What are the dimensions of this product?" }, + { question: 'Why choose this?' }, + { question: 'How is this product made?' }, + { question: 'What are the dimensions of this product?' }, ], }; const optionalParameters = { - section: "Products", - variationId: "2", - threadId: "thread-123", + section: 'Products', + variationId: '2', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("questions") - .to.deep.equal(requiredParameters.questions); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('questions').to.deep.equal(requiredParameters.questions); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -15964,27 +14141,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -15992,27 +14167,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16020,78 +14193,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentView()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentView()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentView()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16099,7 +14259,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -16107,18 +14267,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16126,45 +14284,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -16173,19 +14325,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -16194,29 +14344,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16224,73 +14372,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentView(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentOutOfView", () => { - const requiredParameters = { itemId: "1", itemName: "item1" }; + describe('trackProductInsightsAgentOutOfView', () => { + const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { - section: "Products", - variationId: "2", - threadId: "thread-123", + section: 'Products', + variationId: '2', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { - const segments = ["foo", "bar"]; + it('Should send along document_referrer and canonical_url query param', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -16298,32 +14438,26 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -16331,27 +14465,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16359,27 +14491,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16387,78 +14517,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentOutOfView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16466,7 +14583,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -16474,18 +14591,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16493,45 +14608,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -16540,19 +14649,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -16561,29 +14668,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16591,104 +14696,90 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentOutOfView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentOutOfView(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentFocus", () => { - const requiredParameters = { itemId: "1", itemName: "item1" }; + describe('trackProductInsightsAgentFocus', () => { + const requiredParameters = { itemId: '1', itemName: 'item1' }; const optionalParameters = { - section: "Products", - variationId: "2", - threadId: "thread-123", + section: 'Products', + variationId: '2', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -16696,27 +14787,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16724,27 +14813,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16752,78 +14839,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentFocus()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentFocus()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentFocus()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentFocus()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16831,7 +14905,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -16839,18 +14913,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -16858,45 +14930,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -16905,19 +14971,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -16926,29 +14990,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -16956,112 +15018,92 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentFocus(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentFocus(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentQuestionClick", () => { - const requiredParameters = { - itemId: "1", - itemName: "item1", - question: "Why choose this?", - }; + describe('trackProductInsightsAgentQuestionClick', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { - section: "Products", - variationId: "2", - threadId: "thread-123", - questionTopic: "pricing", + section: 'Products', + variationId: '2', + threadId: 'thread-123', + questionTopic: 'pricing', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("question") - .to.equal(requiredParameters.question); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -17069,27 +15111,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -17097,27 +15137,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17125,85 +15163,66 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); - expect(bodyParams) - .to.have.property("question_topic") - .to.equal(optionalParameters.questionTopic); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(bodyParams).to.have.property('question_topic').to.equal(optionalParameters.questionTopic); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentQuestionClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17211,7 +15230,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -17219,18 +15238,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17238,45 +15255,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -17285,19 +15296,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -17306,29 +15315,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -17336,112 +15343,92 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionClick(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentQuestionSubmit", () => { - const requiredParameters = { - itemId: "1", - itemName: "item1", - question: "Why choose this?", - }; + describe('trackProductInsightsAgentQuestionSubmit', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?' }; const optionalParameters = { - section: "Products", - variationId: "2", - threadId: "thread-123", - questionTopic: "pricing", + section: 'Products', + variationId: '2', + threadId: 'thread-123', + questionTopic: 'pricing', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("question") - .to.equal(requiredParameters.question); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -17449,27 +15436,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -17477,27 +15462,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17505,85 +15488,66 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); - expect(bodyParams) - .to.have.property("question_topic") - .to.equal(optionalParameters.questionTopic); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(bodyParams).to.have.property('question_topic').to.equal(optionalParameters.questionTopic); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentQuestionSubmit()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17591,7 +15555,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -17599,18 +15563,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17618,45 +15580,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -17665,19 +15621,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -17686,29 +15640,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -17716,124 +15668,95 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentQuestionSubmit(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentAnswerView", () => { - const requiredParameters = { - itemId: "1", - itemName: "item1", - question: "Why choose this?", - answerText: "This product is awesome!", - }; + describe('trackProductInsightsAgentAnswerView', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', answerText: 'This product is awesome!' }; const optionalParameters = { - section: "Products", - variationId: "2", - qnaResultId: "0daf0015-fc29-4727-9140-8d5313a1902c", - threadId: "thread-123", - items: [ - { itemId: "rec1", itemName: "Rec Product 1" }, - { itemId: "rec2", itemName: "Rec Product 2" }, - ], - followUpQuestions: [ - { value: "What about size?" }, - { value: "Is it machine washable?" }, - ], + section: 'Products', + variationId: '2', + qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', + threadId: 'thread-123', + items: [{ itemId: 'rec1', itemName: 'Rec Product 1' }, { itemId: 'rec2', itemName: 'Rec Product 2' }], + followUpQuestions: [{ value: 'What about size?' }, { value: 'Is it machine washable?' }], }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("question") - .to.equal(requiredParameters.question); - expect(requestParams) - .to.have.property("answer_text") - .to.equal(requiredParameters.answerText); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + expect(requestParams).to.have.property('answer_text').to.equal(requiredParameters.answerText); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -17841,27 +15764,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -17869,27 +15790,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17897,98 +15816,71 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("qna_result_id") - .to.equal(optionalParameters.qnaResultId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); - expect(bodyParams) - .to.have.property("items") - .to.be.an("array") - .with.lengthOf(2); - expect(bodyParams.items[0]) - .to.have.property("item_id") - .to.equal("rec1"); - expect(bodyParams.items[0]) - .to.have.property("item_name") - .to.equal("Rec Product 1"); - expect(bodyParams) - .to.have.property("follow_up_questions") - .to.be.an("array") - .with.lengthOf(2); - expect(bodyParams.follow_up_questions[0]) - .to.have.property("value") - .to.equal("What about size?"); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(bodyParams).to.have.property('items').to.be.an('array').with.lengthOf(2); + expect(bodyParams.items[0]).to.have.property('item_id').to.equal('rec1'); + expect(bodyParams.items[0]).to.have.property('item_name').to.equal('Rec Product 1'); + expect(bodyParams).to.have.property('follow_up_questions').to.be.an('array').with.lengthOf(2); + expect(bodyParams.follow_up_questions[0]).to.have.property('value').to.equal('What about size?'); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentAnswerView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -17996,7 +15888,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -18004,18 +15896,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18023,45 +15913,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -18070,19 +15954,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -18091,29 +15973,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -18121,112 +16001,92 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerView(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerView(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentAnswerFeedback", () => { - const requiredParameters = { - itemId: "1", - itemName: "item1", - feedbackLabel: "thumbs_up", - }; + describe('trackProductInsightsAgentAnswerFeedback', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', feedbackLabel: 'thumbs_up' }; const optionalParameters = { - section: "Products", - variationId: "2", - qnaResultId: "0daf0015-fc29-4727-9140-8d5313a1902c", - threadId: "thread-123", + section: 'Products', + variationId: '2', + qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', + threadId: 'thread-123', }; - it("Should respond with a valid response when term and required parameters are provided", (done) => { + it('Should respond with a valid response when term and required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("feedback_label") - .to.equal(requiredParameters.feedbackLabel); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('feedback_label').to.equal(requiredParameters.feedbackLabel); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should send along document_referrer and canonical_url query param", (done) => { + it('Should send along document_referrer and canonical_url query param', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when term, required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when term, required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -18234,27 +16094,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -18262,27 +16120,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18290,84 +16146,65 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(requestParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("qna_result_id") - .to.equal(optionalParameters.qnaResultId); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentAnswerFeedback()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18375,7 +16212,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request @@ -18383,18 +16220,16 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18402,45 +16237,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -18449,19 +16278,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); } - it("Should properly encode query parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should properly encode query parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKey, @@ -18470,29 +16297,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -18500,151 +16325,115 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentAnswerFeedback(requiredParameters)).to.equal(true); }); }); - describe("trackProductInsightsAgentResultClick", () => { - const requiredParameters = { - itemId: "1", - itemName: "item1", - question: "Why choose this?", - seedItemId: "seed-1", - }; + describe('trackProductInsightsAgentResultClick', () => { + const requiredParameters = { itemId: '1', itemName: 'item1', question: 'Why choose this?', seedItemId: 'seed-1' }; const optionalParameters = { - section: "Products", - variationId: "2", + section: 'Products', + variationId: '2', position: 1, - seedItemName: "Seed Product", - seedVariationId: "seed-var-1", - threadId: "thread-123", - qnaResultId: "0daf0015-fc29-4727-9140-8d5313a1902c", + seedItemName: 'Seed Product', + seedVariationId: 'seed-var-1', + threadId: 'thread-123', + qnaResultId: '0daf0015-fc29-4727-9140-8d5313a1902c', }; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("item_id") - .to.equal(requiredParameters.itemId); - expect(requestParams) - .to.have.property("item_name") - .to.equal(requiredParameters.itemName); - expect(requestParams) - .to.have.property("question") - .to.equal(requiredParameters.question); - expect(requestParams) - .to.have.property("seed_item_id") - .to.equal(requiredParameters.seedItemId); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('item_id').to.equal(requiredParameters.itemId); + expect(requestParams).to.have.property('item_name').to.equal(requiredParameters.itemName); + expect(requestParams).to.have.property('question').to.equal(requiredParameters.question); + expect(requestParams).to.have.property('seed_item_id').to.equal(requiredParameters.seedItemId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentResultClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams) - .to.have.property("section") - .to.equal(optionalParameters.section); - expect(bodyParams) - .to.have.property("variation_id") - .to.equal(optionalParameters.variationId); - expect(bodyParams) - .to.have.property("position") - .to.equal(optionalParameters.position); - expect(bodyParams) - .to.have.property("seed_item_name") - .to.equal(optionalParameters.seedItemName); - expect(bodyParams) - .to.have.property("seed_variation_id") - .to.equal(optionalParameters.seedVariationId); - expect(bodyParams) - .to.have.property("thread_id") - .to.equal(optionalParameters.threadId); - expect(bodyParams) - .to.have.property("qna_result_id") - .to.equal(optionalParameters.qnaResultId); - - // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(requestParams).to.have.property('section').to.equal(optionalParameters.section); + expect(bodyParams).to.have.property('variation_id').to.equal(optionalParameters.variationId); + expect(bodyParams).to.have.property('position').to.equal(optionalParameters.position); + expect(bodyParams).to.have.property('seed_item_name').to.equal(optionalParameters.seedItemName); + expect(bodyParams).to.have.property('seed_variation_id').to.equal(optionalParameters.seedVariationId); + expect(bodyParams).to.have.property('thread_id').to.equal(optionalParameters.threadId); + expect(bodyParams).to.have.property('qna_result_id').to.equal(optionalParameters.qnaResultId); + + // Response + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentResultClick({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentResultClick( + { ...requiredParameters, ...optionalParameters }, + )).to.equal(true); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentResultClick()).to.be.an("error"); + expect(tracker.trackProductInsightsAgentResultClick()).to.be.an('error'); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackProductInsightsAgentResultClick("invalid")).to.be.an( - "error", - ); + expect(tracker.trackProductInsightsAgentResultClick('invalid')).to.be.an('error'); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -18652,27 +16441,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("us").to.deep.equal(segments); + expect(requestParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentResultClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -18680,45 +16467,39 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - expect( - tracker.trackProductInsightsAgentResultClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentResultClick(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentResultClick(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -18727,143 +16508,126 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackProductInsightsAgentResultClick(requiredParameters), - ).to.equal(true); + expect(tracker.trackProductInsightsAgentResultClick(requiredParameters)).to.equal(true); }); } }); - describe("trackResultsImpressionView", () => { + describe('trackResultsImpressionView', () => { const requiredParameters = { items: [ { - itemId: "1", - itemName: "Item 1", - variationId: "VAR-1", - slCampaignId: "campaign-123", - slCampaignOwner: "owner-abc", + itemId: '1', + itemName: 'Item 1', + variationId: 'VAR-1', + slCampaignId: 'campaign-123', + slCampaignOwner: 'owner-abc', }, { - itemId: "2", - itemName: "Item 2", - variationId: "VAR-2", - slCampaignId: "campaign-456", - slCampaignOwner: "owner-def", + itemId: '2', + itemName: 'Item 2', + variationId: 'VAR-2', + slCampaignId: 'campaign-456', + slCampaignOwner: 'owner-def', }, ], }; const optionalParameters = { - filterName: "category", - filterValue: "shoes", - searchTerm: "red shoes", + filterName: 'category', + filterValue: 'shoes', + searchTerm: 'red shoes', }; - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); validateOriginReferrer(requestParams); // Body - expect(bodyParams) - .to.have.property("items") - .to.deep.equal([ - { - item_id: "1", - item_name: "Item 1", - variation_id: "VAR-1", - sl_campaign_id: "campaign-123", - sl_campaign_owner: "owner-abc", - }, - { - item_id: "2", - item_name: "Item 2", - variation_id: "VAR-2", - sl_campaign_id: "campaign-456", - sl_campaign_owner: "owner-def", - }, - ]); + expect(bodyParams).to.have.property('items').to.deep.equal([ + { + item_id: '1', + item_name: 'Item 1', + variation_id: 'VAR-1', + sl_campaign_id: 'campaign-123', + sl_campaign_owner: 'owner-abc', + }, + { + item_id: '2', + item_name: 'Item 2', + variation_id: 'VAR-2', + sl_campaign_id: 'campaign-456', + sl_campaign_owner: 'owner-def', + }, + ]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property("items"); - expect(bodyParams) - .to.have.property("filter_name") - .to.equal(optionalParameters.filterName); - expect(bodyParams) - .to.have.property("filter_value") - .to.equal(optionalParameters.filterValue); - expect(bodyParams) - .to.have.property("search_term") - .to.equal(optionalParameters.searchTerm); + expect(bodyParams).to.have.property('items'); + expect(bodyParams).to.have.property('filter_name').to.equal(optionalParameters.filterName); + expect(bodyParams).to.have.property('filter_value').to.equal(optionalParameters.filterValue); + expect(bodyParams).to.have.property('search_term').to.equal(optionalParameters.searchTerm); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect( - tracker.trackResultsImpressionView({ - ...requiredParameters, - ...optionalParameters, - }), - ).to.equal(true); + expect(tracker.trackResultsImpressionView({ ...requiredParameters, ...optionalParameters })).to.equal(true); }); - it("Should respond with a valid response when required parameters and segments are provided", (done) => { - const segments = ["foo", "bar"]; + it('Should respond with a valid response when required parameters and segments are provided', (done) => { + const segments = ['foo', 'bar']; const { tracker } = new ConstructorIO({ apiKey: testApiKey, segments, @@ -18871,31 +16635,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property("us").to.deep.equal(segments); + expect(bodyParams).to.have.property('us').to.deep.equal(segments); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and userId are provided", (done) => { - const userId = "user-id"; + it('Should respond with a valid response when required parameters and userId are provided', (done) => { + const userId = 'user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKey, userId, @@ -18903,31 +16665,29 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.have.property("ui").to.equal(userId); + expect(bodyParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); - it("Should respond with a valid response when required parameters and testCells are provided", (done) => { - const testCells = { foo: "bar" }; + it('Should respond with a valid response when required parameters and testCells are provided', (done) => { + const testCells = { foo: 'bar' }; const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18935,32 +16695,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams) - .to.have.property(`ef-${Object.keys(testCells)[0]}`) - .to.equal(Object.values(testCells)[0]); + expect(bodyParams).to.have.property(`ef-${Object.keys(testCells)[0]}`).to.equal(Object.values(testCells)[0]); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18968,7 +16724,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body @@ -18976,22 +16732,20 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(bodyParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, fetch: fetchSpy, @@ -18999,99 +16753,85 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const bodyParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Body expect(fetchSpy).to.have.been.called; - expect(bodyParams).to.not.have.property("origin_referrer"); + expect(bodyParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); - tracker.on("error", (error) => { + tracker.on('error', (error) => { done(error); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { + it('Should throw an error when invalid parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView([])).to.be.an("error"); + expect(tracker.trackResultsImpressionView([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { + it('Should throw an error when no parameters are provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView()).to.be.an("error"); + expect(tracker.trackResultsImpressionView()).to.be.an('error'); }); - it("Should throw an error when items is not provided", () => { + it('Should throw an error when items is not provided', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({})).to.be.an("error"); + expect(tracker.trackResultsImpressionView({})).to.be.an('error'); }); - it("Should throw an error when items is an empty array", () => { + it('Should throw an error when items is an empty array', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect(tracker.trackResultsImpressionView({ items: [] })).to.be.an( - "error", - ); + expect(tracker.trackResultsImpressionView({ items: [] })).to.be.an('error'); }); - it("Should throw an error when an item is missing itemId", () => { + it('Should throw an error when an item is missing itemId', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackResultsImpressionView({ items: [{ itemName: "Shoe" }] }), - ).to.be.an("error"); + expect(tracker.trackResultsImpressionView({ items: [{ itemName: 'Shoe' }] })).to.be.an('error'); }); - it("Should throw an error when an item is missing itemName", () => { + it('Should throw an error when an item is missing itemName', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackResultsImpressionView({ items: [{ itemId: "1" }] }), - ).to.be.an("error"); + expect(tracker.trackResultsImpressionView({ items: [{ itemId: '1' }] })).to.be.an('error'); }); - it("Should throw an error when items contains non-object entries", () => { + it('Should throw an error when items contains non-object entries', () => { const { tracker } = new ConstructorIO({ apiKey: testApiKey }); - expect( - tracker.trackResultsImpressionView({ items: ["string"] }), - ).to.be.an("error"); + expect(tracker.trackResultsImpressionView({ items: ['string'] })).to.be.an('error'); }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect( - tracker.trackResultsImpressionView(requiredParameters, { - timeout: 10, - }), - ).to.equal(true); + expect(tracker.trackResultsImpressionView(requiredParameters, { timeout: 10 })).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKey, networkParameters: { @@ -19100,19 +16840,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); - expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal( - true, - ); + expect(tracker.trackResultsImpressionView(requiredParameters)).to.equal(true); }); } }); - describe("trackMediaImpressionView", () => { + describe('trackMediaImpressionView', () => { let requiredParameters; const optionalParameters = { @@ -19120,9 +16858,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; before(async () => { - const response = await fetch( - `https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`, - ); + const response = await fetch(`https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`); const data = await response.json(); const ad = data.display_ads[testPlacementId]; requiredParameters = { @@ -19131,40 +16867,36 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); - expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); - expect(requestParams) - .to.have.property("banner_ad_id") + .to.have.property('banner_ad_id') .to.equal(requiredParameters.bannerAdId); expect(requestParams) - .to.have.property("placement_id") + .to.have.property('placement_id') .to.equal(requiredParameters.placementId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19174,64 +16906,59 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; expect(requestParams) - .to.have.property("analytics_tags") + .to.have.property('analytics_tags') .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); expect( - tracker.trackMediaImpressionView({ - ...requiredParameters, - ...optionalParameters, - }), + tracker.trackMediaImpressionView( + { ...requiredParameters, ...optionalParameters }, + ), ).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKeyWithAdPlacements, - }); + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); - expect(tracker.trackMediaImpressionView([])).to.be.an("error"); + expect(tracker.trackMediaImpressionView([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKeyWithAdPlacements, - }); + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); - expect(tracker.trackMediaImpressionView()).to.be.an("error"); + expect(tracker.trackMediaImpressionView()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: true, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -19239,8 +16966,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19250,25 +16977,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: false, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19278,27 +17005,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, userId, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19309,14 +17036,14 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -19326,17 +17053,17 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', networkParameters: { timeout: 20, }, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -19348,7 +17075,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { } }); - describe("trackMediaImpressionClick", () => { + describe('trackMediaImpressionClick', () => { let requiredParameters; const optionalParameters = { @@ -19356,9 +17083,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; before(async () => { - const response = await fetch( - `https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`, - ); + const response = await fetch(`https://display.media-cnstrc.com/display-ads?key=${testApiKeyWithAdPlacements}&placement_ids=${testPlacementId}`); const data = await response.json(); const ad = data.display_ads[testPlacementId]; @@ -19368,40 +17093,36 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }; }); - it("Should respond with a valid response when required parameters are provided", (done) => { + it('Should respond with a valid response when required parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("key"); - expect(requestParams).to.have.property("i"); - expect(requestParams).to.have.property("s"); - expect(requestParams).to.have.property("c").to.equal(clientVersion); - expect(requestParams).to.have.property("_dt"); + expect(requestParams).to.have.property('key'); + expect(requestParams).to.have.property('i'); + expect(requestParams).to.have.property('s'); + expect(requestParams).to.have.property('c').to.equal(clientVersion); + expect(requestParams).to.have.property('_dt'); + expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl); + expect(requestParams).to.have.property('document_referrer').to.equal(referrer); expect(requestParams) - .to.have.property("canonical_url") - .to.equal(canonicalUrl); - expect(requestParams) - .to.have.property("document_referrer") - .to.equal(referrer); - expect(requestParams) - .to.have.property("banner_ad_id") + .to.have.property('banner_ad_id') .to.equal(requiredParameters.bannerAdId); expect(requestParams) - .to.have.property("placement_id") + .to.have.property('placement_id') .to.equal(requiredParameters.placementId); validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19411,64 +17132,59 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it("Should respond with a valid response when required and optional parameters are provided", (done) => { + it('Should respond with a valid response when required and optional parameters are provided', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; expect(requestParams) - .to.have.property("analytics_tags") + .to.have.property('analytics_tags') .to.deep.equal(testAnalyticsTag); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); expect( - tracker.trackMediaImpressionClick({ - ...requiredParameters, - ...optionalParameters, - }), + tracker.trackMediaImpressionClick( + { ...requiredParameters, ...optionalParameters }, + ), ).to.equal(true); }); - it("Should throw an error when invalid parameters are provided", () => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKeyWithAdPlacements, - }); + it('Should throw an error when invalid parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); - expect(tracker.trackMediaImpressionClick([])).to.be.an("error"); + expect(tracker.trackMediaImpressionClick([])).to.be.an('error'); }); - it("Should throw an error when no parameters are provided", () => { - const { tracker } = new ConstructorIO({ - apiKey: testApiKeyWithAdPlacements, - }); + it('Should throw an error when no parameters are provided', () => { + const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements }); - expect(tracker.trackMediaImpressionClick()).to.be.an("error"); + expect(tracker.trackMediaImpressionClick()).to.be.an('error'); }); - it("Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true", (done) => { + it('Should send along origin_referrer query param if sendReferrerWithTrackingEvents is true', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: true, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request @@ -19476,8 +17192,8 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { validateOriginReferrer(requestParams); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19487,25 +17203,25 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it("Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false", (done) => { + it('Should not send along origin_referrer query param if sendReferrerWithTrackingEvents is false', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, fetch: fetchSpy, sendReferrerWithTrackingEvents: false, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractUrlParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.not.have.property("origin_referrer"); + expect(requestParams).to.not.have.property('origin_referrer'); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19515,27 +17231,27 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { ); }); - it("Should not encode body parameters", (done) => { - const specialCharacters = "+[]&"; + it('Should not encode body parameters', (done) => { + const specialCharacters = '+[]&'; const userId = `user-id ${specialCharacters}`; const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, userId, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userId); + expect(requestParams).to.have.property('ui').to.equal(userId); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); }); @@ -19546,36 +17262,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); if (!skipNetworkTimeoutTests) { - it("Should be rejected when network request timeout is provided and reached", (done) => { + it('Should be rejected when network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); expect( - tracker.trackMediaImpressionClick(requiredParameters, { - timeout: 10, - }), + tracker.trackMediaImpressionClick(requiredParameters, { timeout: 10 }), ).to.equal(true); }); - it("Should be rejected when global network request timeout is provided and reached", (done) => { + it('Should be rejected when global network request timeout is provided and reached', (done) => { const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', networkParameters: { timeout: 20, }, ...requestQueueOptions, }); - tracker.on("error", ({ message }) => { + tracker.on('error', ({ message }) => { expect(message).to.equal(timeoutRejectionMessage); done(); }); @@ -19586,28 +17300,28 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => { }); } - it("Should properly transform non-breaking spaces in parameters", (done) => { - const breakingSpaces = "   "; + it('Should properly transform non-breaking spaces in parameters', (done) => { + const breakingSpaces = '   '; const userId = `user-id ${breakingSpaces} user-id`; - const userIdExpected = "user-id user-id"; + const userIdExpected = 'user-id user-id'; const { tracker } = new ConstructorIO({ apiKey: testApiKeyWithAdPlacements, userId, - mediaServiceUrl: "https://media-cnstrc.com", + mediaServiceUrl: 'https://media-cnstrc.com', fetch: fetchSpy, ...requestQueueOptions, }); - tracker.on("success", (responseParams) => { + tracker.on('success', (responseParams) => { const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy); // Request expect(fetchSpy).to.have.been.called; - expect(requestParams).to.have.property("ui").to.equal(userIdExpected); + expect(requestParams).to.have.property('ui').to.equal(userIdExpected); // Response - expect(responseParams).to.have.property("method").to.equal("POST"); - expect(responseParams).to.have.property("message").to.equal("ok"); + expect(responseParams).to.have.property('method').to.equal('POST'); + expect(responseParams).to.have.property('message').to.equal('ok'); done(); });