Skip to content

Commit

Permalink
Match bid ids
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlane committed Feb 12, 2018
1 parent 5a02b24 commit a8b090e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,22 @@ const LEGACY_PROTOCOL = {
*/
const OPEN_RTB_PROTOCOL = {

bidMap: {},

buildRequest(s2sBidRequest, adUnits) {
let imps = [];

// transform ad unit into array of OpenRTB impression objects
adUnits.forEach(adUnit => {
let banner;

adUnit.bids.forEach(bid => {
// OpenRTB response contains the adunit code and bidder name. These are
// combined to create a unique key for each bid since an id isn't returned
const key = `${adUnit.code}${bid.bidder}`;
this.bidMap[key] = bid;
});

const bannerParams = utils.deepAccess(adUnit, 'mediaTypes.banner');
if (bannerParams && bannerParams.sizes) {
// get banner sizes in form [{ w: <int>, h: <int> }, ...]
Expand Down Expand Up @@ -412,9 +421,14 @@ const OPEN_RTB_PROTOCOL = {
// a seatbid object contains a `bid` array and a `seat` string
response.seatbid.forEach(seatbid => {
(seatbid.bid || []).forEach(bid => {
const bidRequest = utils.getBidRequest(
this.bidMap[`${bid.impid}${seatbid.seat}`],
bidRequests
);

const cpm = bid.price;
const status = cpm !== 0 ? STATUS.GOOD : STATUS.NO_BID;
let bidObject = bidfactory.createBid(status);
let bidObject = bidfactory.createBid(status, bidRequest);

bidObject.source = TYPE;
bidObject.bidderCode = seatbid.seat;
Expand Down
3 changes: 2 additions & 1 deletion test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,9 @@ describe('S2S Adapter', () => {

sinon.assert.calledOnce(addBidResponse);
const response = addBidResponse.firstCall.args[1];
expect(response).to.have.property('bidderCode', 'appnexus');
expect(response).to.have.property('statusMessage', 'Bid available');
expect(response).to.have.property('bidderCode', 'appnexus');
expect(response).to.have.property('adId', '123');
expect(response).to.have.property('cpm', 0.5);
});
});
Expand Down

0 comments on commit a8b090e

Please sign in to comment.