Skip to content

Commit

Permalink
Add floors support to eplanning bid adapter (#10395)
Browse files Browse the repository at this point in the history
Co-authored-by: Maxi <mzurita@MacBook-Air-de-Maxi.local>
  • Loading branch information
maximilianozurita and Maxi authored Aug 29, 2023
1 parent e78e4b8 commit ff42caf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
19 changes: 17 additions & 2 deletions modules/eplanningBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ function cleanName(name) {
return name.replace(/_|\.|-|\//g, '').replace(/\)\(|\(|\)|:/g, '_').replace(/^_+|_+$/g, '');
}

function getFloorStr(bid) {
if (typeof bid.getFloor === 'function') {
let bidFloor = bid.getFloor({
currency: DOLLAR_CODE,
mediaType: '*',
size: '*'
});

if (bidFloor.floor) {
return '|' + encodeURIComponent(bidFloor.floor);
}
}
return '';
}

function getSpaces(bidRequests, ml) {
let impType = bidRequests.reduce((previousBits, bid) => (bid.mediaTypes && bid.mediaTypes[VIDEO]) ? (bid.mediaTypes[VIDEO].context == 'outstream' ? (previousBits | 2) : (previousBits | 1)) : previousBits, 0);
// Only one type of auction is supported at a time
Expand All @@ -286,7 +301,7 @@ function getSpaces(bidRequests, ml) {
let sizeVast = firstSize ? firstSize.join('x') : DEFAULT_SIZE_VAST;
name = 'video_' + sizeVast + '_' + i;
es.map[name] = bid.bidId;
return name + ':' + sizeVast + ';1';
return name + ':' + sizeVast + ';1' + getFloorStr(bid);
}

if (ml) {
Expand All @@ -296,7 +311,7 @@ function getSpaces(bidRequests, ml) {
}

es.map[name] = bid.bidId;
return name + ':' + getSize(bid);
return name + ':' + getSize(bid) + getFloorStr(bid);
}).join('+')).join('+');
return es;
}
Expand Down
67 changes: 67 additions & 0 deletions test/spec/modules/eplanningBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,53 @@ describe('E-Planning Adapter', function () {
},
'sizes': [[300, 250], [300, 600]],
};
const validBidSpaceNameWithBidFloor = {
bidder: 'eplanning',
'bidId': BID_ID,
params: {
'ci': CI,
'sn': SN,
},
getFloor: () => ({ currency: 'USD', floor: 1.16 }),
'sizes': [[300, 250], [300, 600]],
};
const validBidSpaceOutstreamWithBidFloor = {
'bidder': 'eplanning',
'bidId': BID_ID,
'params': {
'ci': CI,
'sn': SN,
},
getFloor: () => ({ currency: 'USD', floor: 1.16 }),
'mediaTypes': {
'video': {
'context': 'outstream',
'playerSize': [300, 600],
'mimes': ['video/mp4'],
'protocols': [1, 2, 3, 4, 5, 6],
'playbackmethod': [2],
'skip': 1
}
},
};
const validBidSpaceInstreamWithBidFloor = {
'bidder': 'eplanning',
'bidId': BID_ID,
'params': {
'ci': CI,
'sn': SN,
},
getFloor: () => ({ currency: 'USD', floor: 1.16 }),
'mediaTypes': {
'video': {
'context': 'instream',
'mimes': ['video/mp4'],
'protocols': [1, 2, 3, 4, 5, 6],
'playbackmethod': [2],
'skip': 1
}
},
};
const validBidSpaceOutstream = {
'bidder': 'eplanning',
'bidId': BID_ID,
Expand Down Expand Up @@ -573,6 +620,26 @@ describe('E-Planning Adapter', function () {
expect(e).to.equal(SN + ':300x250,300x600');
});

it('should return e parameter with space name attribute with value according to the adunit sizes and bidFloor', function () {
const e = spec.buildRequests([validBidSpaceNameWithBidFloor], bidderRequest).data.e;
expect(e).to.equal(SN + ':300x250,300x600|' + validBidSpaceNameWithBidFloor.getFloor().floor);
});

it('should return correct e parameter with support vast with one space with size outstream and bidFloor', function () {
const data = spec.buildRequests([validBidSpaceOutstreamWithBidFloor], bidderRequest).data;
expect(data.e).to.equal('video_300x600_0:300x600;1|' + validBidSpaceOutstreamWithBidFloor.getFloor().floor);
expect(data.vctx).to.equal(2);
expect(data.vv).to.equal(3);
});

it('should return correct e parameter with support vast with one space with size instream with bidFloor', function () {
let bidRequests = [validBidSpaceInstreamWithBidFloor];
const data = spec.buildRequests(bidRequests, bidderRequest).data;
expect(data.e).to.equal('video_640x480_0:640x480;1|' + validBidSpaceInstreamWithBidFloor.getFloor().floor);
expect(data.vctx).to.equal(1);
expect(data.vv).to.equal(3);
});

it('should return correct e parameter with more than one adunit', function () {
const NEW_CODE = ADUNIT_CODE + '2';
const CLEAN_NEW_CODE = CLEAN_ADUNIT_CODE + '2';
Expand Down

0 comments on commit ff42caf

Please sign in to comment.