From bd056c9d37633d6f30c6220ba43e9d8d3258a0c9 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Wed, 16 Oct 2019 17:54:21 -0500 Subject: [PATCH 1/2] add a feature to always refresh stored id on each bid request for submodules that require that --- modules/userId/index.js | 4 ++ src/constants.json | 3 ++ test/spec/modules/userId_spec.js | 69 ++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/modules/userId/index.js b/modules/userId/index.js index ac96fd2cec8..91eaff13d47 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -386,6 +386,10 @@ function initSubmodules(submodules, consentData) { refreshNeeded = storedDate && (Date.now() - storedDate.getTime() > submodule.config.storage.refreshInSeconds * 1000); } + if (CONSTANTS.SUBMODULES_THAT_ALWAYS_REFRESH_ID[submodule.config.name] === true) { + refreshNeeded = true; + } + if (!storedId || refreshNeeded) { // No previously saved id. Request one from submodule. response = submodule.submodule.getId(submodule.config.params, consentData, storedId); diff --git a/src/constants.json b/src/constants.json index 99e2bd792b9..d993a6531ad 100644 --- a/src/constants.json +++ b/src/constants.json @@ -95,5 +95,8 @@ "BID_STATUS" : { "BID_TARGETING_SET": "targetingSet", "RENDERED": "rendered" + }, + "SUBMODULES_THAT_ALWAYS_REFRESH_ID": { + "parrableId": true } } diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index cd72ca9670f..042395906fb 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -985,6 +985,7 @@ describe('User ID', function() { sinon.stub(utils, 'triggerPixel'); utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE); + utils.setCookie('_parrable_eid', '', EXPIRED_COOKIE_DATE); }); afterEach(function() { @@ -993,6 +994,7 @@ describe('User ID', function() { utils.triggerPixel.restore(); utils.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); utils.setCookie('unifiedid', '', EXPIRED_COOKIE_DATE); + utils.setCookie('_parrable_eid', '', EXPIRED_COOKIE_DATE); }); it('pubcid callback with url', function () { @@ -1042,5 +1044,72 @@ describe('User ID', function() { events.emit(CONSTANTS.EVENTS.AUCTION_END, {}); expect(requests[0].url).to.equal('//match.adsrvr.org/track/rid?ttd_pid=rubicon&fmt=json'); }); + + it('callback for submodules that always need to refresh stored id', function(done) { + let adUnits = [getAdUnitMock()]; + let innerAdUnits; + const parrableStoredId = '01.1111111111.test-eid'; + const parrableRefreshedId = '02.2222222222.test-eid'; + utils.setCookie('_parrable_eid', parrableStoredId, (new Date(Date.now() + 5000).toUTCString())); + + const parrableIdSubmoduleMock = { + name: 'parrableId', + decode: function(value) { + return { 'parrableid': value }; + }, + getId: function() { + return { + callback: function(cb) { + cb(parrableRefreshedId); + } + }; + } + }; + + const parrableConfigMock = { + userSync: { + syncDelay: 0, + userIds: [{ + name: 'parrableId', + storage: { + type: 'cookie', + name: '_parrable_eid' + } + }] + } + }; + + setSubmoduleRegistry([parrableIdSubmoduleMock]); + attachIdSystem(parrableIdSubmoduleMock); + init(config); + config.setConfig(parrableConfigMock); + + // make first bid request, should use stored id value + requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits}); + innerAdUnits.forEach(unit => { + unit.bids.forEach(bid => { + expect(bid).to.have.deep.nested.property('userId.parrableid'); + expect(bid.userId.parrableid).to.equal(parrableStoredId); + }); + }); + + // emit an auction end event to run the mock callback + events.on(CONSTANTS.EVENTS.AUCTION_END, function handler(submodule) { + if (submodule === 'parrableIdSubmoduleMock') { + // make the second bid request, id should have been refreshed + requestBidsHook((config) => { innerAdUnits = config.adUnits }, {adUnits}); + innerAdUnits.forEach(unit => { + unit.bids.forEach(bid => { + expect(bid).to.have.deep.nested.property('userId.parrableid'); + expect(bid.userId.parrableid).to.equal(parrableRefreshedId); + }); + }); + events.off(CONSTANTS.EVENTS.AUCTION_END, handler); + done(); + } + }); + + events.emit(CONSTANTS.EVENTS.AUCTION_END, 'parrableIdSubmoduleMock'); + }); }); }); From 93bc3f29174447a5beb10e9658cf06c2181d6d89 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Wed, 16 Oct 2019 19:32:54 -0500 Subject: [PATCH 2/2] update test comments --- test/spec/modules/userId_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index 042395906fb..4058f4435ca 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -1093,7 +1093,7 @@ describe('User ID', function() { }); }); - // emit an auction end event to run the mock callback + // attach a handler for auction end event to run the second bid request events.on(CONSTANTS.EVENTS.AUCTION_END, function handler(submodule) { if (submodule === 'parrableIdSubmoduleMock') { // make the second bid request, id should have been refreshed @@ -1109,6 +1109,7 @@ describe('User ID', function() { } }); + // emit an auction end event to run the submodule callback events.emit(CONSTANTS.EVENTS.AUCTION_END, 'parrableIdSubmoduleMock'); }); });