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

execute bidsBackHandler when auction is canceled by consent module #2555

Merged
merged 2 commits into from
May 22, 2018
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
13 changes: 10 additions & 3 deletions modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let consentData;
let context;
let args;
let nextFn;
let bidsBackHandler;

let timer;
let haveExited;
Expand Down Expand Up @@ -154,15 +155,16 @@ function lookupIabConsent(cmpSuccess, cmpError, adUnits) {
* user's encoded consent string from the supported CMP. Once obtained, the module will store this
* data as part of a gdprConsent object which gets transferred to adaptermanager's gdprDataHandler object.
* This information is later added into the bidRequest object for any supported adapters to read/pass along to their system.
* @param {object} config required; This is the same param that's used in pbjs.requestBids.
* @param {object} reqBidsConfigObj required; This is the same param that's used in pbjs.requestBids.
* @param {function} fn required; The next function in the chain, used by hook.js
*/
export function requestBidsHook(config, fn) {
export function requestBidsHook(reqBidsConfigObj, fn) {
context = this;
args = arguments;
nextFn = fn;
haveExited = false;
let adUnits = config.adUnits || $$PREBID_GLOBAL$$.adUnits;
let adUnits = reqBidsConfigObj.adUnits || $$PREBID_GLOBAL$$.adUnits;
bidsBackHandler = reqBidsConfigObj.bidsBackHandler;

// in case we already have consent (eg during bid refresh)
if (consentData) {
Expand Down Expand Up @@ -262,6 +264,11 @@ function exitModule(errMsg) {
nextFn.apply(context, args);
} else {
utils.logError(errMsg + ' Canceling auction as per consentManagement config.');
if (typeof bidsBackHandler === 'function') {
bidsBackHandler();
} else {
utils.logError('Error executing bidsBackHandler');
}
}
} else {
nextFn.apply(context, args);
Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/consentManagement_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,22 @@ describe('consentManagement', function () {

it('throws an error when processCmpData check failed while config had allowAuction set to false', () => {
let testConsentData = null;
let bidsBackHandlerReturn = false;

cmpStub = sinon.stub(window, '__cmp').callsFake((...args) => {
args[2](testConsentData);
});

setConfig(goodConfigWithCancelAuction);

requestBidsHook({}, () => {
requestBidsHook({ bidsBackHandler: () => bidsBackHandlerReturn = true }, () => {
didHookReturn = true;
});
let consent = gdprDataHandler.getConsentData();

sinon.assert.calledOnce(utils.logError);
expect(didHookReturn).to.be.false;
expect(bidsBackHandlerReturn).to.be.true;
expect(consent).to.be.null;
});

Expand Down