Skip to content

Commit

Permalink
Adf adapter: price floors module support (#7427)
Browse files Browse the repository at this point in the history
  • Loading branch information
braizhas authored Sep 16, 2021
1 parent da820a0 commit d4ea363
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/adfBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ export const spec = {
const imp = validBidRequests.map((bid, id) => {
bid.netRevenue = pt;

const floorInfo = bid.getFloor ? bid.getFloor({
currency: currency || 'USD'
}) : {};
const bidfloor = floorInfo.floor;
const bidfloorcur = floorInfo.currency;

const imp = {
id: id + 1,
tagid: bid.params.mid
tagid: bid.params.mid,
bidfloor,
bidfloorcur
};

const assets = utils._map(bid.nativeParams, (bidParams, key) => {
Expand Down
55 changes: 55 additions & 0 deletions test/spec/modules/adfBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,61 @@ describe('Adf adapter', function () {
}
});

describe('price floors', function () {
it('should not add if floors module not configured', function () {
const validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }];
let imp = getRequestImps(validBidRequests)[0];

assert.equal(imp.bidfloor, undefined);
assert.equal(imp.bidfloorcur, undefined);
});

it('should not add if floor price not defined', function () {
const validBidRequests = [ getBidWithFloor() ];
let imp = getRequestImps(validBidRequests)[0];

assert.equal(imp.bidfloor, undefined);
assert.equal(imp.bidfloorcur, 'USD');
});

it('should request floor price in adserver currency', function () {
config.setConfig({ currency: { adServerCurrency: 'DKK' } });
const validBidRequests = [ getBidWithFloor() ];
let imp = getRequestImps(validBidRequests)[0];

assert.equal(imp.bidfloor, undefined);
assert.equal(imp.bidfloorcur, 'DKK');
});

it('should add correct floor values', function () {
const expectedFloors = [ 1, 1.3, 0.5 ];
const validBidRequests = expectedFloors.map(getBidWithFloor);
let imps = getRequestImps(validBidRequests);

expectedFloors.forEach((floor, index) => {
assert.equal(imps[index].bidfloor, floor);
assert.equal(imps[index].bidfloorcur, 'USD');
});
});

function getBidWithFloor(floor) {
return {
params: { mid: 1 },
mediaTypes: { video: {} },
getFloor: ({ currency }) => {
return {
currency: currency,
floor
}
}
};
}

function getRequestImps(validBidRequests) {
return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp;
}
});

describe('multiple media types', function () {
it('should use single media type for bidding', function () {
let validBidRequests = [{
Expand Down

0 comments on commit d4ea363

Please sign in to comment.