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 module: fix auctionDelay submodules with callbacks #5891

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,13 @@ function hasGDPRConsent(consentData) {
* @param {function} cb - callback for after processing is done.
*/
function processSubmoduleCallbacks(submodules, cb) {
const done = cb ? utils.delayExecution(cb, submodules.length) : function () { };
let done = () => {};
if (cb) {
done = utils.delayExecution(() => {
clearTimeout(timeoutID);
cb();
}, submodules.length);
}
submodules.forEach(function (submodule) {
submodule.callback(function callbackCompleted(idObj) {
// if valid, id data should be saved to cookie/html storage
Expand All @@ -338,7 +344,6 @@ function processSubmoduleCallbacks(submodules, cb) {
// clear callback, this prop is used to test if all submodule callbacks are complete below
submodule.callback = undefined;
});
clearTimeout(timeoutID);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ describe('User ID', function () {
beforeEach(function () {
sandbox = sinon.createSandbox();
sandbox.stub(global, 'setTimeout').returns(2);
sandbox.stub(global, 'clearTimeout');
sandbox.stub(events, 'on');
sandbox.stub(coreStorage, 'getCookie');

Expand Down Expand Up @@ -662,6 +663,7 @@ describe('User ID', function () {
requestBidsHook(auctionSpy, {adUnits});

// check auction was delayed
global.clearTimeout.calledOnce.should.equal(false);
global.setTimeout.calledOnce.should.equal(true);
global.setTimeout.calledWith(sinon.match.func, 33);
auctionSpy.calledOnce.should.equal(false);
Expand Down Expand Up @@ -696,6 +698,7 @@ describe('User ID', function () {

// check auction was delayed
// global.setTimeout.calledOnce.should.equal(true);
global.clearTimeout.calledOnce.should.equal(false);
global.setTimeout.calledWith(sinon.match.func, 33);
auctionSpy.calledOnce.should.equal(false);

Expand Down