From 6637c7b355cb37e832a96c431e99437767eb1531 Mon Sep 17 00:00:00 2001 From: jsnellbaker <31102355+jsnellbaker@users.noreply.github.com> Date: Fri, 22 Jun 2018 15:23:36 -0400 Subject: [PATCH] check if bidder exists before making request object (#2695) * check if bidder exists before making request object * remove redundant check --- src/adaptermanager.js | 29 +++++++++++----------- test/spec/unit/core/adapterManager_spec.js | 3 ++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 1c8a2ff4a3ee..0dc5a9177db8 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -203,7 +203,12 @@ exports.makeBidRequests = function(adUnits, auctionStart, auctionId, cbTimeout, auctionStart: auctionStart, timeout: cbTimeout }; - if (bidderRequest.bids && bidderRequest.bids.length !== 0) { + const adapter = _bidderRegistry[bidderCode]; + if (!adapter) { + utils.logError(`Trying to make a request for bidder that does not exist: ${bidderCode}`); + } + + if (adapter && bidderRequest.bids && bidderRequest.bids.length !== 0) { bidRequests.push(bidderRequest); } }); @@ -347,19 +352,15 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb, requestCallbac bidRequest.start = timestamp(); // TODO : Do we check for bid in pool from here and skip calling adapter again ? const adapter = _bidderRegistry[bidRequest.bidderCode]; - if (adapter) { - utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`); - events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest); - bidRequest.doneCbCallCount = 0; - let done = doneCb(bidRequest.bidderRequestId); - let ajax = ajaxBuilder(clientBidRequests[0].timeout, requestCallbacks ? { - request: requestCallbacks.request.bind(null, bidRequest.bidderCode), - done: requestCallbacks.done - } : undefined); - adapter.callBids(bidRequest, addBidResponse, done, ajax); - } else { - utils.logError(`Adapter trying to be called which does not exist: ${bidRequest.bidderCode} adaptermanager.callBids`); - } + utils.logMessage(`CALLING BIDDER ======= ${bidRequest.bidderCode}`); + events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest); + bidRequest.doneCbCallCount = 0; + let done = doneCb(bidRequest.bidderRequestId); + let ajax = ajaxBuilder(clientBidRequests[0].timeout, requestCallbacks ? { + request: requestCallbacks.request.bind(null, bidRequest.bidderCode), + done: requestCallbacks.done + } : undefined); + adapter.callBids(bidRequest, addBidResponse, done, ajax); }); } diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index c4dcc87198ba..9050a0871df4 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -92,7 +92,8 @@ describe('adapterManager tests', () => { }]; let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); - AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); + expect(bidRequests.length).to.equal(1); + expect(bidRequests[0].bidderCode).to.equal('appnexus'); sinon.assert.called(utils.logError); });