diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 0dc5a9177db..7f63a950283 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -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, @@ -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 @@ -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}; diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index 9050a0871df..51b34f8d1b8 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -191,7 +191,7 @@ describe('adapterManager tests', () => { 'auctionId': '1ff753bd4ae5cb', 'startTime': 1463510220995, 'status': 1, - 'bid_id': '378a8914450b334' + 'bid_id': '68136e1c47023d' } ] }, @@ -228,7 +228,7 @@ describe('adapterManager tests', () => { 'bidderRequestId': '55e24a66bed717', 'auctionId': '1ff753bd4ae5cb', 'startTime': 1463510220996, - 'bid_id': '387d9d9c32ca47c' + 'bid_id': '7e5d6af25ed188' } ] } @@ -792,6 +792,7 @@ describe('adapterManager tests', () => { afterEach(() => { matchMedia.restore(); + config.resetConfig(); setSizeConfig([]); }); @@ -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', () => {