diff --git a/modules/prebidServerBidAdapter.js b/modules/prebidServerBidAdapter.js index 3cd698c7ccd..67348059f5f 100644 --- a/modules/prebidServerBidAdapter.js +++ b/modules/prebidServerBidAdapter.js @@ -3,11 +3,11 @@ import bidfactory from 'src/bidfactory'; import bidmanager from 'src/bidmanager'; import * as utils from 'src/utils'; import { ajax } from 'src/ajax'; -import { STATUS } from 'src/constants'; +import { STATUS, S2S } from 'src/constants'; import { queueSync, persist } from 'src/cookie'; import adaptermanager from 'src/adaptermanager'; -const TYPE = 's2s'; +const TYPE = S2S.SRC; const cookiePersistMessage = `Your browser may be blocking 3rd party cookies. By clicking on this page you allow Prebid Server and other advertising partners to place cookies to help us advertise. You can opt out of their cookies here.`; const cookiePersistUrl = '//ib.adnxs.com/seg?add=1&redir='; @@ -185,6 +185,6 @@ PrebidServer.createNew = function() { return new PrebidServer(); }; -adaptermanager.registerBidAdapter(new PrebidServer, 'prebidServer'); +adaptermanager.registerBidAdapter(new PrebidServer(), 'prebidServer'); module.exports = PrebidServer; diff --git a/src/adaptermanager.js b/src/adaptermanager.js index 7aa9a4f8cb4..bafe77f6fc1 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -90,6 +90,11 @@ exports.callBids = ({adUnits, cbTimeout}) => { }); }); + // don't send empty requests + adUnitsCopy = adUnitsCopy.filter(adUnit => { + return adUnit.bids.length !== 0; + }); + let tid = utils.generateUUID(); adaptersServerSide.forEach(bidderCode => { const bidderRequestId = utils.getUniqueIdentifierStr(); @@ -101,10 +106,12 @@ exports.callBids = ({adUnits, cbTimeout}) => { bids: getBids({bidderCode, requestId, bidderRequestId, 'adUnits': adUnitsCopy}), start: new Date().getTime(), auctionStart: auctionStart, - timeout: _s2sConfig.timeout + timeout: _s2sConfig.timeout, + src: CONSTANTS.S2S.SRC }; - // Pushing server side bidder - $$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest); + if (bidderRequest.bids.length !== 0) { + $$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest); + } }); let s2sBidRequest = {tid, 'ad_units': adUnitsCopy}; diff --git a/src/constants.json b/src/constants.json index 4cf0aac447d..e64828d4474 100644 --- a/src/constants.json +++ b/src/constants.json @@ -61,6 +61,7 @@ "hb_deal" ], "S2S" : { - "DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/auction" + "DEFAULT_ENDPOINT" : "https://prebid.adnxs.com/pbs/v1/auction", + "SRC" : "s2s" } } diff --git a/test/spec/core/adapterManager_spec.js b/test/spec/core/adapterManager_spec.js new file mode 100644 index 00000000000..79f20534174 --- /dev/null +++ b/test/spec/core/adapterManager_spec.js @@ -0,0 +1,55 @@ +import { expect } from 'chai'; +import AdapterManager from 'src/adaptermanager'; +import { getAdUnits } from 'test/fixtures/fixtures'; +import CONSTANTS from 'src/constants.json'; + +const CONFIG = { + enabled: true, + endpoint: CONSTANTS.S2S.DEFAULT_ENDPOINT, + timeout: 1000, + maxBids: 1, + adapter: 'prebidServer', + bidders: ['appnexus'] +}; +var prebidServerAdapterMock = { + bidder: 'prebidServer', + callBids: sinon.stub(), + setConfig: sinon.stub() +}; + +describe('adapterManager tests', () => { + describe('S2S tests', () => { + beforeEach(() => { + AdapterManager.setS2SConfig(CONFIG); + AdapterManager.bidderRegistry['prebidServer'] = prebidServerAdapterMock; + prebidServerAdapterMock.callBids.reset(); + }); + + it('invokes callBids on the S2S adapter', () => { + AdapterManager.callBids({adUnits: getAdUnits()}); + sinon.assert.calledOnce(prebidServerAdapterMock.callBids); + }); + + it('invokes callBids with only s2s bids', () => { + const adUnits = getAdUnits(); + // adUnit without appnexus bidder + adUnits.push({ + 'code': '123', + 'sizes': [300, 250], + 'bids': [ + { + 'bidder': 'adequant', + 'params': { + 'publisher_id': '1234567', + 'bidfloor': 0.01 + } + } + ] + }); + AdapterManager.callBids({adUnits: adUnits}); + const requestObj = prebidServerAdapterMock.callBids.firstCall.args[0]; + expect(requestObj.ad_units.length).to.equal(2); + sinon.assert.calledOnce(prebidServerAdapterMock.callBids); + }); + }); // end s2s tests +});