Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserID: bugfix for refreshUserIds with updated info #7105

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
aaroniniguez marked this conversation as resolved.
Show resolved Hide resolved
}

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