Skip to content

Commit

Permalink
Improvement/rad 1689 s2s drop empty bid (#1330)
Browse files Browse the repository at this point in the history
* fix sending empty bids + tests

* add unit tests

* Include `src` on bidRequest object.
  • Loading branch information
Matt Kendall authored Jun 30, 2017
1 parent d0b73f4 commit 27fe1c2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
6 changes: 3 additions & 3 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://www.appnexus.com/en/company/platform-privacy-policy#choices" target="_blank">here</a>.`;
const cookiePersistUrl = '//ib.adnxs.com/seg?add=1&redir=';

Expand Down Expand Up @@ -185,6 +185,6 @@ PrebidServer.createNew = function() {
return new PrebidServer();
};

adaptermanager.registerBidAdapter(new PrebidServer, 'prebidServer');
adaptermanager.registerBidAdapter(new PrebidServer(), 'prebidServer');

module.exports = PrebidServer;
13 changes: 10 additions & 3 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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};
Expand Down
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
55 changes: 55 additions & 0 deletions test/spec/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
@@ -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
});

0 comments on commit 27fe1c2

Please sign in to comment.