Skip to content

Commit

Permalink
execute bidsBackHandler when auction is canceled by consent module (#…
Browse files Browse the repository at this point in the history
…2555)

* add support to execute bidsBackHandler when auction is canceled by consent module

* rename config variable
  • Loading branch information
jsnellbaker authored and jaiminpanchal27 committed May 22, 2018
1 parent 18b9fbc commit 60cabb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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 @@ -302,20 +302,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

0 comments on commit 60cabb7

Please sign in to comment.