Skip to content

Commit

Permalink
Medianet bid adapter: floor module support (#6713)
Browse files Browse the repository at this point in the history
* Medianet floor module support

* removing backslash from wildcard
  • Loading branch information
c3p-0 authored May 19, 2021
1 parent a5b5083 commit c346322
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,39 @@ function slotParams(bidRequest) {
} else {
params.ext.visibility = SLOT_VISIBILITY.NOT_DETERMINED;
}
const floorInfo = getBidFloorByType(bidRequest);
if (floorInfo && floorInfo.length > 0) {
params.bidfloors = floorInfo;
}

return params;
}

function getBidFloorByType(bidRequest) {
let floorInfo = [];
if (typeof bidRequest.getFloor === 'function') {
[BANNER, VIDEO, NATIVE].forEach(mediaType => {
if (bidRequest.mediaTypes.hasOwnProperty(mediaType)) {
if (mediaType == BANNER) {
bidRequest.mediaTypes.banner.sizes.forEach(
size => {
setFloorInfo(bidRequest, mediaType, size, floorInfo)
}
)
} else {
setFloorInfo(bidRequest, mediaType, '*', floorInfo)
}
}
});
}
return floorInfo;
}
function setFloorInfo(bidRequest, mediaType, size, floorInfo) {
let floor = bidRequest.getFloor({currency: 'USD', mediaType: mediaType, size: size});
if (size.length > 1) floor.size = size;
floor.mediaType = mediaType;
floorInfo.push(floor);
}
function getMinSize(sizes) {
return sizes.reduce((min, size) => size.h * size.w < min.h * min.w ? size : min);
}
Expand Down
41 changes: 41 additions & 0 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,4 +1446,45 @@ describe('Media.net bid adapter', function () {
let bids = spec.interpretResponse(SERVER_VIDEO_OUTSTREAM_RESPONSE_VALID_BID, []);
expect(bids[0].context).to.equal('outstream');
});
describe('buildRequests floor tests', function () {
let floor;
let getFloor = function(req) {
return floor[req.mediaType];
};
beforeEach(function () {
floor = {
'banner': {
'currency': 'USD',
'floor': 1
}
};
$$PREBID_GLOBAL$$.medianetGlobals = {};

let documentStub = sandbox.stub(document, 'getElementById');
let boundingRect = {
top: 50,
left: 50,
bottom: 100,
right: 100
};
documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({
getBoundingClientRect: () => boundingRect
});
documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({
getBoundingClientRect: () => boundingRect
});
let windowSizeStub = sandbox.stub(spec, 'getWindowSize');
windowSizeStub.returns({
w: 1000,
h: 1000
});
VALID_BID_REQUEST[0].getFloor = getFloor;
});

it('should build valid payload with floor', function () {
let requestObj = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA);
requestObj = JSON.parse(requestObj.data);
expect(requestObj.imp[0].hasOwnProperty('bidfloors')).to.equal(true);
});
});
});

0 comments on commit c346322

Please sign in to comment.