From 21cc9c0b6304a87a8986e6a6d760b59d33d7bbcb Mon Sep 17 00:00:00 2001 From: Dmitriy Labuzov Date: Tue, 6 Apr 2021 15:44:37 +0300 Subject: [PATCH] Yieldmo adapter: support for the floors module --- modules/yieldmoBidAdapter.js | 12 ++++++++- package-lock.json | 2 +- test/spec/modules/yieldmoBidAdapter_spec.js | 29 ++++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index c1151617ac4..514c7119ece 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -280,7 +280,7 @@ function openRtbImpression(bidRequest) { const imp = { id: bidRequest.bidId, tagid: bidRequest.adUnitCode, - bidfloor: bidRequest.params.bidfloor || 0, + bidfloor: getBidFloor(bidRequest), ext: { placement_id: bidRequest.params.placementId }, @@ -304,6 +304,16 @@ function openRtbImpression(bidRequest) { return imp; } +function getBidFloor(bidRequest) { + let floorInfo = {}; + + if (typeof bidRequest.getFloor === 'function') { + floorInfo = bidRequest.getFloor({ currency: CURRENCY, mediaType: VIDEO, size: '*' }); + } + + return floorInfo.floor || bidRequest.params.bidfloor || 0; +} + /** * @param {BidRequest} bidRequest bidder request object. * @return [number, number] || null Player's width and height, or undefined otherwise. diff --git a/package-lock.json b/package-lock.json index 330298cbaac..922f08f980d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "4.15.0-pre", + "version": "4.34.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index deabef69093..54540338015 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -78,6 +78,8 @@ describe('YieldmoAdapter', function () { ...params }); + const mockGetFloor = floor => ({getFloor: () => ({ currency: 'USD', floor })}); + describe('isBidRequestValid', function () { describe('Banner:', function () { it('should return true when necessary information is found', function () { @@ -259,12 +261,37 @@ describe('YieldmoAdapter', function () { }); describe('Instream video:', function () { - it('should attempt to send banner bid requests to the endpoint via POST', function () { + it('should attempt to send video bid requests to the endpoint via POST', function () { const requests = build([mockVideoBid()]); expect(requests.length).to.equal(1); expect(requests[0].method).to.equal('POST'); expect(requests[0].url).to.be.equal(VIDEO_ENDPOINT); }); + + it('should process floors module if available', function () { + const requests = build([ + mockVideoBid({...mockGetFloor(3.99)}), + mockVideoBid({...mockGetFloor(1.23)}, { bidfloor: 1.1 }), + ]); + const imps = requests[0].data.imp; + expect(imps[0].bidfloor).to.equal(3.99); + expect(imps[1].bidfloor).to.equal(1.23); + }); + + it('should use bidfloor if no floors module is available', function() { + const requests = build([ + mockVideoBid({}, { bidfloor: 1.2 }), + mockVideoBid({}, { bidfloor: 0.7 }), + ]); + const imps = requests[0].data.imp; + expect(imps[0].bidfloor).to.equal(1.2); + expect(imps[1].bidfloor).to.equal(0.7); + }); + + it('should have 0 bidfloor value by default', function() { + const requests = build([mockVideoBid()]); + expect(requests[0].data.imp[0].bidfloor).to.equal(0); + }); }); });