From c3463221febad83379da612a3088599e4d8e595c Mon Sep 17 00:00:00 2001 From: Rahul Shandilya <67756716+c3p-0@users.noreply.github.com> Date: Wed, 19 May 2021 18:53:34 +0530 Subject: [PATCH] Medianet bid adapter: floor module support (#6713) * Medianet floor module support * removing backslash from wildcard --- modules/medianetBidAdapter.js | 29 ++++++++++++++ test/spec/modules/medianetBidAdapter_spec.js | 41 ++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/modules/medianetBidAdapter.js b/modules/medianetBidAdapter.js index a2dc8bdfd03..1a4269a8a1d 100644 --- a/modules/medianetBidAdapter.js +++ b/modules/medianetBidAdapter.js @@ -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); } diff --git a/test/spec/modules/medianetBidAdapter_spec.js b/test/spec/modules/medianetBidAdapter_spec.js index 1eeb167601e..adb9663ba7c 100644 --- a/test/spec/modules/medianetBidAdapter_spec.js +++ b/test/spec/modules/medianetBidAdapter_spec.js @@ -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); + }); + }); });