Skip to content

Commit

Permalink
EMX Digital Bid Adapter: floor module and advertiserDomain support (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
EMXDigital authored and idettman committed May 21, 2021
1 parent 5a848d8 commit 9515506
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
28 changes: 27 additions & 1 deletion modules/emx_digitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const spec = {

utils._each(validBidRequests, function (bid) {
let tagid = utils.getBidIdParameter('tagid', bid.params);
let bidfloor = parseFloat(utils.getBidIdParameter('bidfloor', bid.params)) || 0;
let bidfloor = parseFloat(getBidFloor(bid)) || 0;
let isVideo = !!bid.mediaTypes.video;
let data = {
id: bid.bidId,
Expand Down Expand Up @@ -287,6 +287,14 @@ export const spec = {
bidResponse = emxAdapter.formatVideoResponse(bidResponse, Object.assign({}, emxBid), bidRequest);
}
bidResponse.mediaType = (isVideo ? VIDEO : BANNER);

// support for adomain in prebid 5.0
if (emxBid.adomain && emxBid.adomain.length) {
bidResponse.meta = {
advertiserDomains: emxBid.adomain
};
}

emxBidResponses.push(bidResponse);
});
}
Expand All @@ -312,4 +320,22 @@ export const spec = {
return syncs;
}
};

// support floors module in prebid 5.0
function getBidFloor(bid) {
if (!utils.isFn(bid.getFloor)) {
return parseFloat(utils.getBidIdParameter('bidfloor', bid.params));
}

let floor = bid.getFloor({
currency: DEFAULT_CUR,
mediaType: '*',
size: '*'
});
if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') {
return floor.floor;
}
return null;
}

registerBidder(spec);
52 changes: 45 additions & 7 deletions test/spec/modules/emx_digitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,38 @@ describe('emx_digital Adapter', function () {
expect(queryParams[1]).to.match(new RegExp('^ts=\d*', 'g'));
});

it('builds with bid floor', function () {
const bidRequestWithBidFloor = utils.deepClone(bidderRequest.bids);
bidRequestWithBidFloor[0].params.bidfloor = 1;
const requestWithFloor = spec.buildRequests(bidRequestWithBidFloor, bidderRequest);
it('builds bidfloor value from bid param when getFloor function does not exist', function () {
const bidRequestWithFloor = utils.deepClone(bidderRequest.bids);
bidRequestWithFloor[0].params.bidfloor = 1;
const requestWithFloor = spec.buildRequests(bidRequestWithFloor, bidderRequest);
const data = JSON.parse(requestWithFloor.data);
expect(data.imp[0].bidfloor).to.equal(bidRequestWithBidFloor[0].params.bidfloor);
expect(data.imp[0].bidfloor).to.equal(bidRequestWithFloor[0].params.bidfloor);
});

it('builds bidfloor value from getFloor function when it exists', function () {
const floorResponse = { currency: 'USD', floor: 3 };
const bidRequestWithGetFloor = utils.deepClone(bidderRequest.bids);
bidRequestWithGetFloor[0].getFloor = () => floorResponse;
const requestWithGetFloor = spec.buildRequests(bidRequestWithGetFloor, bidderRequest);
const data = JSON.parse(requestWithGetFloor.data);
expect(data.imp[0].bidfloor).to.equal(3);
});

it('builds bidfloor value from getFloor when both floor and getFloor function exists', function () {
const floorResponse = { currency: 'USD', floor: 3 };
const bidRequestWithBothFloors = utils.deepClone(bidderRequest.bids);
bidRequestWithBothFloors[0].params.bidfloor = 1;
bidRequestWithBothFloors[0].getFloor = () => floorResponse;
const requestWithBothFloors = spec.buildRequests(bidRequestWithBothFloors, bidderRequest);
const data = JSON.parse(requestWithBothFloors.data);
expect(data.imp[0].bidfloor).to.equal(3);
});

it('empty bidfloor value when floor and getFloor is not defined', function () {
const bidRequestWithoutFloor = utils.deepClone(bidderRequest.bids);
const requestWithoutFloor = spec.buildRequests(bidRequestWithoutFloor, bidderRequest);
const data = JSON.parse(requestWithoutFloor.data);
expect(data.imp[0].bidfloor).to.not.exist;
});

it('builds request properly', function () {
Expand Down Expand Up @@ -470,7 +496,8 @@ describe('emx_digital Adapter', function () {
'id': '987654321cba',
'price': 0.5,
'ttl': 300,
'w': 300
'w': 300,
'adomain': ['example.com']
}],
'seat': '1356'
}, {
Expand Down Expand Up @@ -498,7 +525,10 @@ describe('emx_digital Adapter', function () {
'netRevneue': true,
'mediaType': 'banner',
'ad': '<!-- Creative -->',
'ttl': 300
'ttl': 300,
'meta': {
'advertiserDomains': ['example.com']
}
}, {
'requestId': '12819a18-56e1-4256-b836-b69a10202668',
'cpm': 0.7,
Expand Down Expand Up @@ -630,6 +660,14 @@ describe('emx_digital Adapter', function () {
body: badAdmServerResponse
}));
});

it('returns valid advertiser domain', function () {
const bidResponse = utils.deepClone(serverResponse);
let result = spec.interpretResponse({body: bidResponse});
expect(result[0].meta.advertiserDomains).to.deep.equal(expectedResponse[0].meta.advertiserDomains);
// case where adomains are not in request
expect(result[1].meta).to.not.exist;
});
});

describe('getUserSyncs', function () {
Expand Down

0 comments on commit 9515506

Please sign in to comment.