From 52696534eb3824e5a70b388f08c795737265fd84 Mon Sep 17 00:00:00 2001 From: Nisar Thadathil Date: Tue, 11 Apr 2023 15:05:10 +0530 Subject: [PATCH] vidoomy adapter: added bidfloor module (#9784) --- modules/vidoomyBidAdapter.js | 23 +++++++++++++- test/spec/modules/vidoomyBidAdapter_spec.js | 35 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/modules/vidoomyBidAdapter.js b/modules/vidoomyBidAdapter.js index 08c7d1b31ac..29128998fd1 100644 --- a/modules/vidoomyBidAdapter.js +++ b/modules/vidoomyBidAdapter.js @@ -74,6 +74,26 @@ function serializeSupplyChainObj(schainObj) { return serializedSchain; } +/** + * Gets highest floor between getFloor.floor and params.bidfloor + * @param {Object} bid + * @param {Object} mediaType + * @param {Array} sizes + * @param {Number} bidfloor + * @returns {Number} floor + */ +function getBidFloor(bid, mediaType, sizes, bidfloor) { + let floor = bidfloor; + var size = sizes && sizes.length > 0 ? sizes[0] : '*'; + if (typeof bid.getFloor === 'function') { + const floorInfo = bid.getFloor({currency: 'USD', mediaType, size}); + if (typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) { + floor = Math.max(bidfloor, parseFloat(floorInfo.floor)); + } + } + return floor; +} + const isBidResponseValid = bid => { if (!bid || !bid.requestId || !bid.cpm || !bid.ttl || !bid.currency) { return false; @@ -106,6 +126,7 @@ const buildRequests = (validBidRequests, bidderRequest) => { const videoContext = deepAccess(bid, 'mediaTypes.video.context'); const bidfloor = deepAccess(bid, `params.bidfloor`, 0); + const floor = getBidFloor(bid, adType, sizes, bidfloor); const queryParams = { id: bid.params.id, @@ -120,7 +141,7 @@ const buildRequests = (validBidRequests, bidderRequest) => { pid: bid.params.pid, requestId: bid.bidId, schain: serializeSupplyChainObj(bid.schain) || '', - bidfloor, + bidfloor: floor, d: getDomainWithoutSubdomain(hostname), // 'vidoomy.com', // TODO: does the fallback make sense here? sp: encodeURIComponent(bidderRequest.refererInfo.page || bidderRequest.refererInfo.topmostLocation), diff --git a/test/spec/modules/vidoomyBidAdapter_spec.js b/test/spec/modules/vidoomyBidAdapter_spec.js index 8a3e61ca43a..607fdf4b5b8 100644 --- a/test/spec/modules/vidoomyBidAdapter_spec.js +++ b/test/spec/modules/vidoomyBidAdapter_spec.js @@ -161,6 +161,41 @@ describe('vidoomyBidAdapter', function() { expect(request[0].data).to.include.any.keys('schain'); expect(request[0].data.schain).to.eq(serializedForm); }); + + it('should set the bidfloor if getFloor module is undefined but static bidfloor is present', function () { + const request = { ...bidRequests[0], params: { bidfloor: 2.5 } } + const req = spec.buildRequests([request], bidderRequest)[0]; + expect(req.data).to.include.any.keys('bidfloor'); + expect(req.data.bidfloor).to.equal(2.5); + }); + + describe('floorModule', function () { + const getFloordata = { + 'currency': 'USD', + 'floor': 1.60 + }; + bidRequests[0].getFloor = _ => { + return getFloordata; + }; + it('should return getFloor.floor if present', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data.bidfloor).to.equal(getFloordata.floor); + }); + it('should return the getFloor.floor if it is greater than static bidfloor', function () { + const bidfloor = 1.40; + const request = { ...bidRequests[0] }; + request.params.bidfloor = bidfloor; + const bidRequest = spec.buildRequests([request], bidderRequest)[0]; + expect(bidRequest.data.bidfloor).to.equal(getFloordata.floor); + }); + it('should return the static bidfloor if it is greater than getFloor.floor', function () { + const bidfloor = 1.90; + const request = { ...bidRequests[0] }; + request.params.bidfloor = bidfloor; + const bidRequest = spec.buildRequests([request], bidderRequest)[0]; + expect(bidRequest.data.bidfloor).to.equal(bidfloor); + }); + }); }); describe('interpretResponse', function () {