From a367816384951d75dbdf64af27b6aabd38415ebe Mon Sep 17 00:00:00 2001 From: adg Date: Tue, 11 Dec 2018 14:37:41 +0100 Subject: [PATCH 1/3] RVR-2087 - Remove sendAuction call from ExpiringQueue --- modules/rivrAnalyticsAdapter.js | 3 +-- test/spec/modules/rivrAnalyticsAdapter_spec.js | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/modules/rivrAnalyticsAdapter.js b/modules/rivrAnalyticsAdapter.js index fd42be334c0..61075289f56 100644 --- a/modules/rivrAnalyticsAdapter.js +++ b/modules/rivrAnalyticsAdapter.js @@ -37,7 +37,7 @@ let rivrAnalytics = Object.assign(adapter({analyticsType}), { * @param ttl * @constructor */ -export function ExpiringQueue(sendImpressions, sendAuction, ttl, log) { +export function ExpiringQueue(sendImpressions, ttl, log) { let queue = []; let timeoutId; @@ -71,7 +71,6 @@ export function ExpiringQueue(sendImpressions, sendAuction, ttl, log) { clearTimeout(timeoutId); } timeoutId = setTimeout(() => { - sendAuction(); if (queue.length) { sendImpressions(); } diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js index e822becef15..fc00ccd1104 100644 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ b/test/spec/modules/rivrAnalyticsAdapter_spec.js @@ -2,7 +2,6 @@ import * as utils from 'src/utils'; import analyticsAdapter from 'modules/rivrAnalyticsAdapter'; import { ExpiringQueue, - sendAuction, sendImpressions, handleClickEventWithClosureScope, createUnOptimisedParamsField, @@ -96,12 +95,8 @@ describe('RIVR Analytics adapter', () => { expect(Date.now()).to.be.equal(200); done(); }; - const sendAuctionMock = () => {}; - let queue = new ExpiringQueue( - sendImpressionMock, - sendAuctionMock, - EXPIRING_QUEUE_TIMEOUT_MOCK); + let queue = new ExpiringQueue(sendImpressionMock, EXPIRING_QUEUE_TIMEOUT_MOCK); queue.push(1); From d87e046ec8d9e9be224e07db230cbc3733efae89 Mon Sep 17 00:00:00 2001 From: adg Date: Tue, 11 Dec 2018 15:04:01 +0100 Subject: [PATCH 2/3] RVR-2147 - Fix test failing on IE 11.0.0 --- modules/rivrAnalyticsAdapter.js | 3 +-- test/spec/modules/rivrAnalyticsAdapter_spec.js | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/rivrAnalyticsAdapter.js b/modules/rivrAnalyticsAdapter.js index 61075289f56..a7a5f8221b0 100644 --- a/modules/rivrAnalyticsAdapter.js +++ b/modules/rivrAnalyticsAdapter.js @@ -1,6 +1,5 @@ import {ajax} from 'src/ajax'; import adapter from 'src/AnalyticsAdapter'; -import find from 'core-js/library/fn/array/find'; import CONSTANTS from 'src/constants.json'; import adaptermanager from 'src/adaptermanager'; import * as utils from 'src/utils'; @@ -84,7 +83,7 @@ rivrAnalytics.originEnableAnalytics = rivrAnalytics.enableAnalytics; // override enableAnalytics so we can get access to the config passed in from the page rivrAnalytics.enableAnalytics = (config) => { if (window.rivraddon && window.rivraddon.analytics) { - window.rivraddon.analytics.enableAnalytics(config, ExpiringQueue, {utils, ajax, find}); + window.rivraddon.analytics.enableAnalytics(config, ExpiringQueue, {utils, ajax}); rivrAnalytics.originEnableAnalytics(config); } }; diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js index fc00ccd1104..51905e05228 100644 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ b/test/spec/modules/rivrAnalyticsAdapter_spec.js @@ -120,11 +120,9 @@ describe('RIVR Analytics adapter', () => { expect(firstArgument.provider).to.be.equal('rivr'); expect(typeof secondArgument).to.be.equal('function'); - expect(secondArgument.name).to.be.equal('ExpiringQueue'); expect(thirdArgument).to.have.property('utils'); expect(thirdArgument).to.have.property('ajax'); - expect(thirdArgument).to.have.property('find'); }); it('Firing an event when rivraddon context is not defined it should do nothing', () => { From e873cdfafdd15a691de064adbc9c52248897893d Mon Sep 17 00:00:00 2001 From: adg Date: Tue, 11 Dec 2018 15:23:19 +0100 Subject: [PATCH 3/3] RVR-2087 - Remove ExpiringQueue --- modules/rivrAnalyticsAdapter.js | 49 +------------------ .../spec/modules/rivrAnalyticsAdapter_spec.js | 33 +------------ 2 files changed, 3 insertions(+), 79 deletions(-) diff --git a/modules/rivrAnalyticsAdapter.js b/modules/rivrAnalyticsAdapter.js index a7a5f8221b0..867cc3d68bc 100644 --- a/modules/rivrAnalyticsAdapter.js +++ b/modules/rivrAnalyticsAdapter.js @@ -30,60 +30,13 @@ let rivrAnalytics = Object.assign(adapter({analyticsType}), { } }); -/** - * Expiring queue implementation. Fires callback on elapsed timeout since last last update or creation. - * @param callback - * @param ttl - * @constructor - */ -export function ExpiringQueue(sendImpressions, ttl, log) { - let queue = []; - let timeoutId; - - this.push = (event) => { - if (event instanceof Array) { - queue.push.apply(queue, event); - } else { - queue.push(event); - } - reset(); - }; - - this.popAll = () => { - let result = queue; - queue = []; - reset(); - return result; - }; - /** - * For test/debug purposes only - * @return {Array} - */ - this.peekAll = () => { - return queue; - }; - - this.init = reset; - - function reset() { - if (timeoutId) { - clearTimeout(timeoutId); - } - timeoutId = setTimeout(() => { - if (queue.length) { - sendImpressions(); - } - }, ttl); - } -}; - // save the base class function rivrAnalytics.originEnableAnalytics = rivrAnalytics.enableAnalytics; // override enableAnalytics so we can get access to the config passed in from the page rivrAnalytics.enableAnalytics = (config) => { if (window.rivraddon && window.rivraddon.analytics) { - window.rivraddon.analytics.enableAnalytics(config, ExpiringQueue, {utils, ajax}); + window.rivraddon.analytics.enableAnalytics(config, {utils, ajax}); rivrAnalytics.originEnableAnalytics(config); } }; diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js index 51905e05228..5bd526579ac 100644 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ b/test/spec/modules/rivrAnalyticsAdapter_spec.js @@ -1,7 +1,6 @@ import * as utils from 'src/utils'; import analyticsAdapter from 'modules/rivrAnalyticsAdapter'; import { - ExpiringQueue, sendImpressions, handleClickEventWithClosureScope, createUnOptimisedParamsField, @@ -86,43 +85,15 @@ describe('RIVR Analytics adapter', () => { delete window.rivraddon; }); - it('ExpiringQueue should call sendImpression callback after expiring queue timeout is elapsed', (done) => { - const sendImpressionMock = () => { - let elements = queue.popAll(); - expect(elements).to.be.eql([1, 2, 3, 4]); - elements = queue.popAll(); - expect(elements).to.have.lengthOf(0); - expect(Date.now()).to.be.equal(200); - done(); - }; - - let queue = new ExpiringQueue(sendImpressionMock, EXPIRING_QUEUE_TIMEOUT_MOCK); - - queue.push(1); - - setTimeout(() => { - queue.push([2, 3]); - timer.tick(50); - }, 50); - setTimeout(() => { - queue.push([4]); - timer.tick(100); - }, 100); - timer.tick(50); - }); - it('enableAnalytics - should call rivraddon enableAnalytics with the correct arguments', () => { // adaptermanager.enableAnalytics() is called in beforeEach. If just called here it doesn't seem to work. const firstArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[0]; const secondArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[1]; - const thirdArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[2]; expect(firstArgument.provider).to.be.equal('rivr'); - expect(typeof secondArgument).to.be.equal('function'); - - expect(thirdArgument).to.have.property('utils'); - expect(thirdArgument).to.have.property('ajax'); + expect(secondArgument).to.have.property('utils'); + expect(secondArgument).to.have.property('ajax'); }); it('Firing an event when rivraddon context is not defined it should do nothing', () => {