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..4058f4435ca 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,73 @@ 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); + }); + }); + + // 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 + 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(); + } + }); + + // emit an auction end event to run the submodule callback + events.emit(CONSTANTS.EVENTS.AUCTION_END, 'parrableIdSubmoduleMock'); + }); }); });