Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vidoomy Adapter: Support Bidfloor Module #9784

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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