From 7d7c484856df7dbd9cd1968b7dedef57b7cc7617 Mon Sep 17 00:00:00 2001 From: jsnellbaker <31102355+jsnellbaker@users.noreply.github.com> Date: Fri, 27 Jul 2018 13:01:19 -0400 Subject: [PATCH] add fix and move logic that resyncs s2sadunits (#2795) --- src/adaptermanager.js | 27 ++++++++++-------- test/spec/unit/core/adapterManager_spec.js | 32 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 24c3db6f9490..2ee0d4625a8f 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -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, @@ -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 @@ -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}; diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index 9050a0871df4..51b34f8d1b84 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', () => {