Skip to content

Commit

Permalink
Consistent targeting set (#2592)
Browse files Browse the repository at this point in the history
* Populate adUnitCode's even though there's no bid available

* Add new targeting test for no bids, and upgrade old implicit getAdserverTargeting calls

* Updated to a more simplex generation method
  • Loading branch information
ptomasroos authored and jaiminpanchal27 committed Jun 5, 2018
1 parent 646a971 commit 6fbc404
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ export function newTargeting(auctionManager) {
});

targeting = flattenTargeting(targeting);

// make sure at least there is a entry per adUnit code in the targetingSet so receivers of SET_TARGETING call's can know what ad units are being invoked

adUnitCodes.forEach(code => {
if (!targeting[code]) {
targeting[code] = {};
}
});

return targeting;
};

Expand Down
30 changes: 30 additions & 0 deletions test/spec/unit/core/targeting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,36 @@ describe('targeting tests', () => {
});
}); // end getAllTargeting tests

describe('getAllTargeting without bids return empty object', () => {
let amBidsReceivedStub;
let amGetAdUnitsStub;
let bidExpiryStub;

beforeEach(() => {
$$PREBID_GLOBAL$$._sendAllBids = false;
amBidsReceivedStub = sinon.stub(auctionManager, 'getBidsReceived').callsFake(function() {
return [];
});
amGetAdUnitsStub = sinon.stub(auctionManager, 'getAdUnitCodes').callsFake(function() {
return ['/123456/header-bid-tag-0'];
});
bidExpiryStub = sinon.stub(targetingModule, 'isBidExpired').returns(true);
});

afterEach(() => {
auctionManager.getBidsReceived.restore();
auctionManager.getAdUnitCodes.restore();
targetingModule.isBidExpired.restore();
});

it('returns targetingSet correctly', () => {
let targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);

// we should only get the targeting data for the one requested adunit to at least exist even though it has no keys to set
expect(Object.keys(targeting).length).to.equal(1);
});
}); // end getAllTargeting without bids return empty object

describe('Targeting in concurrent auctions', () => {
describe('check getOldestBid', () => {
let bidExpiryStub;
Expand Down
18 changes: 9 additions & 9 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ describe('Unit: Prebid Module', function () {

it('should return current targeting data for slots', function () {
$$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true });
const targeting = $$PREBID_GLOBAL$$.getAdserverTargeting();
const expected = getAdServerTargeting();
const targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);
const expected = getAdServerTargeting(['/19968336/header-bid-tag-0, /19968336/header-bid-tag1']);
assert.deepEqual(targeting, expected, 'targeting ok');
});

it('should return correct targeting with default settings', () => {
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting();
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);
var expected = {
'/19968336/header-bid-tag-0': {
foobar: '0x0,300x250,300x600',
Expand All @@ -230,8 +230,8 @@ describe('Unit: Prebid Module', function () {

it('should return correct targeting with bid landscape targeting on', () => {
$$PREBID_GLOBAL$$.setConfig({ enableSendAllBids: true });
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting();
var expected = getAdServerTargeting();
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);
var expected = getAdServerTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);
assert.deepEqual(targeting, expected);
});

Expand All @@ -248,7 +248,7 @@ describe('Unit: Prebid Module', function () {

auction.getBidsReceived = function() { return _bidsReceived };

var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting();
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);

// Ensure targeting for both ad placements includes the custom key.
assert.equal(
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('Unit: Prebid Module', function () {
}
};

var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting();
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);

var expected = {
'/19968336/header-bid-tag-0': {
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('Unit: Prebid Module', function () {

auction.getBidsReceived = function() { return _bidsReceived };

var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting();
var targeting = $$PREBID_GLOBAL$$.getAdserverTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']);

var expected = {
'/19968336/header-bid-tag-0': {
Expand Down Expand Up @@ -1488,7 +1488,7 @@ describe('Unit: Prebid Module', function () {
assert.ok(spyCallBids.calledTwice, 'When two requests for bids are made both should be' +
' callBids immediately');

let result = targeting.getAllTargeting(); // $$PREBID_GLOBAL$$.getAdserverTargeting();
let result = targeting.getAllTargeting(['/19968336/header-bid-tag-0', '/19968336/header-bid-tag1']); // $$PREBID_GLOBAL$$.getAdserverTargeting();
let expected = {
'/19968336/header-bid-tag-0': {
'foobar': '0x0,300x250,300x600',
Expand Down

0 comments on commit 6fbc404

Please sign in to comment.