Skip to content

Commit

Permalink
BugFix UserID module refreshUserIds
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniniguez committed Jun 28, 2021
1 parent 19e8f52 commit ce953c9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@ function refreshUserIds(options, callback) {

utils.logInfo(`${MODULE_NAME} - refreshing ${submodule.submodule.name}`);
populateSubmoduleId(submodule, consentData, storedConsentData, true);
updateInitializedSubmodules(submodule);

if (initializedSubmodules.length) {
setPrebidServerEidPermissions(initializedSubmodules);
}

if (utils.isFn(submodule.callback)) {
callbackSubmodules.push(submodule);
Expand Down Expand Up @@ -711,6 +716,20 @@ function initSubmodules(submodules, consentData) {
}, []);
}

function updateInitializedSubmodules(submodule) {
let updated = false;
for (let i = 0; i < initializedSubmodules.length; i++) {
if (submodule.config.name.toLowerCase() === initializedSubmodules[i].config.name.toLowerCase()) {
updated = true;
initializedSubmodules[i] = submodule;
}
}

if (!updated) {
initializedSubmodules.push(submodule);
}
}

/**
* list of submodule configurations with valid 'storage' or 'value' obj definitions
* * storage config: contains values for storing/retrieving User ID data in browser storage
Expand Down
40 changes: 40 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,46 @@ describe('User ID', function () {
expect(mockIdCallback.callCount).to.equal(1);
});

it('pbjs.refreshUserIds updates submodules', function() {
let sandbox = sinon.createSandbox();
let mockIdCallback = sandbox.stub().returns({id: {'MOCKID': '1111'}});
let mockIdSystem = {
name: 'mockId',
decode: function(value) {
return {
'mid': value['MOCKID']
};
},
getId: mockIdCallback
};
setSubmoduleRegistry([mockIdSystem]);
init(config);
config.setConfig({
userSync: {
syncDelay: 0,
userIds: [{
name: 'mockId',
value: {id: {mockId: '1111'}}
}]
}
});

expect(getGlobal().getUserIds().id.mockId).to.equal('1111');

// update to new config value
config.setConfig({
userSync: {
syncDelay: 0,
userIds: [{
name: 'mockId',
value: {id: {mockId: '1212'}}
}]
}
});
getGlobal().refreshUserIds({ submoduleNames: ['mockId'] });
expect(getGlobal().getUserIds().id.mockId).to.equal('1212');
});

it('pbjs.refreshUserIds refreshes single', function() {
coreStorage.setCookie('MOCKID', '', EXPIRED_COOKIE_DATE);
coreStorage.setCookie('REFRESH', '', EXPIRED_COOKIE_DATE);
Expand Down

0 comments on commit ce953c9

Please sign in to comment.