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

fix and move logic that updates adUnitsS2SCopy based sizeMapping results #2795

Merged
merged 1 commit into from
Jul 27, 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
27 changes: 15 additions & 12 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout,
auctionId,
bidderRequestId,
tid,
adUnitsS2SCopy,
bids: getBids({bidderCode, auctionId, bidderRequestId, 'adUnits': adUnitsS2SCopy, labels}),
auctionStart: auctionStart,
timeout: _s2sConfig.timeout,
Expand All @@ -189,6 +188,21 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout,
bidRequests.push(bidderRequest);
}
});

// update the s2sAdUnits object and remove all bids that didn't pass sizeConfig/label checks from getBids()
// this is to keep consistency and only allow bids/adunits that passed the checks to go to pbs
adUnitsS2SCopy.forEach((adUnitCopy) => {
let validBids = adUnitCopy.bids.filter((adUnitBid) => {
return find(bidRequests, request => {
return find(request.bids, (reqBid) => reqBid.bidId === adUnitBid.bid_id);
});
});
adUnitCopy.bids = validBids;
});

bidRequests.forEach(request => {
request.adUnitsS2SCopy = adUnitsS2SCopy.filter(adUnitCopy => adUnitCopy.bids.length > 0);
});
}

// client adapters
Expand Down Expand Up @@ -301,17 +315,6 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb, requestCallbac
const s2sAdapter = _bidderRegistry[_s2sConfig.adapter];
let tid = serverBidRequests[0].tid;
let adUnitsS2SCopy = serverBidRequests[0].adUnitsS2SCopy;
adUnitsS2SCopy.forEach((adUnitCopy) => {
let validBids = adUnitCopy.bids.filter((bid) => {
return find(serverBidRequests, request => {
return request.bidderCode === bid.bidder &&
find(request.bids, (reqBid) => reqBid.adUnitCode === adUnitCopy.code);
});
});
adUnitCopy.bids = validBids;
});

adUnitsS2SCopy = adUnitsS2SCopy.filter(adUnitCopy => adUnitCopy.bids.length > 0);

if (s2sAdapter) {
let s2sBidRequest = {tid, 'ad_units': adUnitsS2SCopy};
Expand Down
32 changes: 30 additions & 2 deletions test/spec/unit/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('adapterManager tests', () => {
'auctionId': '1ff753bd4ae5cb',
'startTime': 1463510220995,
'status': 1,
'bid_id': '378a8914450b334'
'bid_id': '68136e1c47023d'
}
]
},
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('adapterManager tests', () => {
'bidderRequestId': '55e24a66bed717',
'auctionId': '1ff753bd4ae5cb',
'startTime': 1463510220996,
'bid_id': '387d9d9c32ca47c'
'bid_id': '7e5d6af25ed188'
}
]
}
Expand Down Expand Up @@ -792,6 +792,7 @@ describe('adapterManager tests', () => {

afterEach(() => {
matchMedia.restore();
config.resetConfig();
setSizeConfig([]);
});

Expand Down Expand Up @@ -887,6 +888,33 @@ describe('adapterManager tests', () => {
expect(bidRequests[0].bids.length).to.equal(1);
expect(bidRequests[0].bids[0].adUnitCode).to.equal(adUnits[1].code);
});

it('should filter adUnits/bidders based on applid labels for s2s requests', () => {
adUnits[0].labelAll = ['visitor-uk', 'mobile'];
adUnits[1].labelAny = ['visitor-uk', 'desktop'];
adUnits[1].bids[0].labelAny = ['mobile'];
adUnits[1].bids[1].labelAll = ['desktop'];

let TESTING_CONFIG = utils.deepClone(CONFIG);
TESTING_CONFIG.bidders = ['appnexus', 'rubicon'];
config.setConfig({ s2sConfig: TESTING_CONFIG });

let bidRequests = AdapterManager.makeBidRequests(
adUnits,
Date.now(),
utils.getUniqueIdentifierStr(),
function callback() {},
['visitor-uk', 'desktop']
);

expect(bidRequests.length).to.equal(1);
expect(bidRequests[0].adUnitsS2SCopy.length).to.equal(1);
expect(bidRequests[0].adUnitsS2SCopy[0].bids.length).to.equal(1);
expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].bidder).to.equal('rubicon');
expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].placementCode).to.equal(adUnits[1].code);
expect(bidRequests[0].adUnitsS2SCopy[0].bids[0].bid_id).to.equal(bidRequests[0].bids[0].bid_id);
expect(bidRequests[0].adUnitsS2SCopy[0].labelAny).to.deep.equal(['visitor-uk', 'desktop']);
});
});

describe('gdpr consent module', () => {
Expand Down