Skip to content

Commit

Permalink
Merge pull request #11 from rubicon-project/prebid-1.0-prebidServer-B…
Browse files Browse the repository at this point in the history
…ID_REQUEST-event

s2s requests now firing BID_REQUESTED event
  • Loading branch information
harpere authored Nov 22, 2017
2 parents aba436e + a8c6cbf commit 35dcf5c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ exports.callBids = (adUnits, bidRequests, addBidResponse, doneCb) => {
return allBidders.includes(adapter);
}).join(',')}`);

// fire BID_REQUESTED event for each s2s bidRequest
serverBidRequests.forEach(bidRequest => {
events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest);
});

// make bid requests
s2sAdapter.callBids(
s2sBidRequest,
Expand Down
51 changes: 51 additions & 0 deletions test/spec/unit/core/adapterManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { config } from 'src/config';
import { registerBidder } from 'src/adapters/bidderFactory';
import { setSizeConfig } from 'src/sizeMapping';
var s2sTesting = require('../../../../modules/s2sTesting');
var events = require('../../../../src/events');

const CONFIG = {
enabled: true,
Expand Down Expand Up @@ -90,6 +91,22 @@ describe('adapterManager tests', () => {

sinon.assert.called(utils.logError);
});

it('should emit BID_REQUESTED event', () => {
// function to count BID_REQUESTED events
let cnt = 0;
let count = () => cnt++;
events.on(CONSTANTS.EVENTS.BID_REQUESTED, count);
AdapterManager.bidderRegistry['appnexus'] = appnexusAdapterMock;
let adUnits = getAdUnits();
let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000);
AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {});
expect(cnt).to.equal(1);
sinon.assert.calledOnce(appnexusAdapterMock.callBids);
appnexusAdapterMock.callBids.reset();
delete AdapterManager.bidderRegistry['appnexus'];
events.off(CONSTANTS.EVENTS.BID_REQUESTED, count);
});
});

describe('S2S tests', () => {
Expand Down Expand Up @@ -253,6 +270,40 @@ describe('adapterManager tests', () => {
expect(requestObj.ad_units.length).to.equal(2);
sinon.assert.calledOnce(prebidServerAdapterMock.callBids);
});

describe('BID_REQUESTED event', () => {
// function to count BID_REQUESTED events
let cnt, count = () => cnt++;

beforeEach(() => {
cnt = 0;
events.on(CONSTANTS.EVENTS.BID_REQUESTED, count);
});

afterEach(() => {
events.off(CONSTANTS.EVENTS.BID_REQUESTED, count);
});

it('should fire for s2s requests', () => {
let adUnits = getAdUnits();
let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000);
AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {});
expect(cnt).to.equal(1);
sinon.assert.calledOnce(prebidServerAdapterMock.callBids);
});

it('should fire for simultaneous s2s and client requests', () => {
AdapterManager.bidderRegistry['adequant'] = adequantAdapterMock;
let adUnits = getAdUnits();
let bidRequests = AdapterManager.makeBidRequests(adUnits, 1111, 2222, 1000);
AdapterManager.callBids(adUnits, bidRequests, () => {}, () => {});
expect(cnt).to.equal(2);
sinon.assert.calledOnce(prebidServerAdapterMock.callBids);
sinon.assert.calledOnce(adequantAdapterMock.callBids);
adequantAdapterMock.callBids.reset();
delete AdapterManager.bidderRegistry['adequant'];
});
});
}); // end s2s tests

describe('s2sTesting', () => {
Expand Down

0 comments on commit 35dcf5c

Please sign in to comment.