Skip to content

Commit

Permalink
[feature] Add a config list of submodules that require refreshing the…
Browse files Browse the repository at this point in the history
… stored ID after each bid request (prebid#4325)

* add a feature to always refresh stored id on each bid request for submodules that require that

* update test comments
  • Loading branch information
eyas-ranjous authored and sa1omon committed Nov 28, 2019
1 parent 201340e commit c180628
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,8 @@
"BID_STATUS" : {
"BID_TARGETING_SET": "targetingSet",
"RENDERED": "rendered"
},
"SUBMODULES_THAT_ALWAYS_REFRESH_ID": {
"parrableId": true
}
}
70 changes: 70 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit c180628

Please sign in to comment.