Skip to content

Commit

Permalink
vidoomy adapter: added bidfloor module (#9784)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisart007 authored Apr 11, 2023
1 parent f270145 commit 5269653
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
23 changes: 22 additions & 1 deletion modules/vidoomyBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
35 changes: 35 additions & 0 deletions test/spec/modules/vidoomyBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 5269653

Please sign in to comment.