Skip to content

Commit

Permalink
Do not call onBidViewable, onBidWon, etc for S2S bids (#9919)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored May 11, 2023
1 parent a9e357a commit a5ae1f6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 78 deletions.
8 changes: 5 additions & 3 deletions src/adapterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,11 @@ function invokeBidderMethod(bidder, method, spec, fn, ...params) {
}

function tryCallBidderMethod(bidder, method, param) {
const target = getBidderMethod(bidder, method);
if (target != null) {
invokeBidderMethod(bidder, method, ...target, param);
if (param?.src !== CONSTANTS.S2S.SRC) {
const target = getBidderMethod(bidder, method);
if (target != null) {
invokeBidderMethod(bidder, method, ...target, param);
}
}
}

Expand Down
126 changes: 51 additions & 75 deletions test/spec/unit/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,103 +353,79 @@ describe('adapterManager tests', function () {
});
}); // end callTimedOutBidders

describe('onBidWon', function () {
var criteoSpec = { onBidWon: sinon.stub() }
var criteoAdapter = {
bidder: 'criteo',
getSpec: function() { return criteoSpec; }
}
describe('bidder spec methods', () => {
let adUnits, bids, criteoSpec;
before(function () {
config.setConfig({s2sConfig: { enabled: false }});
});

beforeEach(function () {
adapterManager.bidderRegistry['criteo'] = criteoAdapter;
});

afterEach(function () {
delete adapterManager.bidderRegistry['criteo'];
});

it('should call spec\'s onBidWon callback when a bid is won', function () {
const bids = [
beforeEach(() => {
criteoSpec = {}
adapterManager.bidderRegistry['criteo'] = {
bidder: 'criteo',
getSpec: function() { return criteoSpec; },
}
bids = [
{bidder: 'criteo', params: {placementId: 'id'}},
];
const adUnits = [{
adUnits = [{
code: 'adUnit-code',
sizes: [[728, 90]],
bids
}];

adapterManager.callBidWonBidder(bids[0].bidder, bids[0], adUnits);
sinon.assert.called(criteoSpec.onBidWon);
});
}); // end onBidWon

describe('onSetTargeting', function () {
var criteoSpec = { onSetTargeting: sinon.stub() }
var criteoAdapter = {
bidder: 'criteo',
getSpec: function() { return criteoSpec; }
}
before(function () {
config.setConfig({s2sConfig: { enabled: false }});
});

beforeEach(function () {
adapterManager.bidderRegistry['criteo'] = criteoAdapter;
});

afterEach(function () {
delete adapterManager.bidderRegistry['criteo'];
});

it('should call spec\'s onSetTargeting callback when setTargeting is called', function () {
const bids = [
{bidder: 'criteo', params: {placementId: 'id'}},
];
const adUnits = [{
code: 'adUnit-code',
sizes: [[728, 90]],
bids
}];
adapterManager.callSetTargetingBidder(bids[0].bidder, bids[0], adUnits);
sinon.assert.called(criteoSpec.onSetTargeting);
});
}); // end onSetTargeting
describe('onBidWon', function () {
beforeEach(() => {
criteoSpec.onBidWon = sinon.stub()
});
it('should call spec\'s onBidWon callback when a bid is won', function () {
adapterManager.callBidWonBidder(bids[0].bidder, bids[0], adUnits);
sinon.assert.called(criteoSpec.onBidWon);
});

describe('onBidViewable', function () {
var criteoSpec = { onBidViewable: sinon.stub() }
var criteoAdapter = {
bidder: 'criteo',
getSpec: function() { return criteoSpec; }
}
before(function () {
config.setConfig({s2sConfig: { enabled: false }});
it('should NOT call onBidWon when the bid is S2S', () => {
bids[0].src = CONSTANTS.S2S.SRC
adapterManager.callBidWonBidder(bids[0].bidder, bids[0], adUnits);
sinon.assert.notCalled(criteoSpec.onBidWon);
})
});

beforeEach(function () {
adapterManager.bidderRegistry['criteo'] = criteoAdapter;
});
describe('onSetTargeting', function () {
beforeEach(() => {
criteoSpec.onSetTargeting = sinon.stub()
})

afterEach(function () {
delete adapterManager.bidderRegistry['criteo'];
});
it('should call spec\'s onSetTargeting callback when setTargeting is called', function () {
adapterManager.callSetTargetingBidder(bids[0].bidder, bids[0], adUnits);
sinon.assert.called(criteoSpec.onSetTargeting);
});

it('should call spec\'s onBidViewable callback when callBidViewableBidder is called', function () {
const bids = [
{bidder: 'criteo', params: {placementId: 'id'}},
];
const adUnits = [{
code: 'adUnit-code',
sizes: [[728, 90]],
bids
}];
adapterManager.callBidViewableBidder(bids[0].bidder, bids[0]);
sinon.assert.called(criteoSpec.onBidViewable);
it('should NOT call onSetTargeting when bid is S2S', () => {
bids[0].src = CONSTANTS.S2S.SRC;
adapterManager.callSetTargetingBidder(bids[0].bidder, bids[0], adUnits);
sinon.assert.notCalled(criteoSpec.onSetTargeting);
})
}); // end onSetTargeting
describe('onBidViewable', function () {
beforeEach(() => {
criteoSpec.onBidViewable = sinon.stub();
})
it('should call spec\'s onBidViewable callback when callBidViewableBidder is called', function () {
adapterManager.callBidViewableBidder(bids[0].bidder, bids[0]);
sinon.assert.called(criteoSpec.onBidViewable);
});
it('should NOT call onBidViewable when bid is S2S', () => {
bids[0].src = CONSTANTS.S2S.SRC;
adapterManager.callBidViewableBidder(bids[0].bidder, bids[0]);
sinon.assert.notCalled(criteoSpec.onBidViewable);
})
});
}); // end onBidViewable

})
describe('onBidderError', function () {
const bidder = 'appnexus';
const appnexusSpec = { onBidderError: sinon.stub() };
Expand Down

0 comments on commit a5ae1f6

Please sign in to comment.