Skip to content

Commit

Permalink
add fix and move logic that resyncs s2sadunits (#2795)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker authored Jul 27, 2018
1 parent 58ce989 commit c2310ba
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
27 changes: 15 additions & 12 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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 @@ -200,6 +199,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 @@ -313,17 +327,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

0 comments on commit c2310ba

Please sign in to comment.