From cda0a482c46761ea6019e5df631ffcfe0d1bf038 Mon Sep 17 00:00:00 2001 From: ym-dlabuzov <81709888+ym-dlabuzov@users.noreply.github.com> Date: Fri, 9 Apr 2021 22:25:52 +0300 Subject: [PATCH] Yieldmo Bid Adapter: add support for the floors module (#6541) --- modules/yieldmoBidAdapter.js | 17 +++++-- test/spec/modules/yieldmoBidAdapter_spec.js | 52 ++++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index a4bd58140b9..4981534412f 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -167,8 +167,9 @@ function addPlacement(request) { if (request.params.placementId) { placementInfo.ym_placement_id = request.params.placementId; } - if (request.params.bidFloor) { - placementInfo.bidFloor = request.params.bidFloor; + const bidfloor = getBidFloor(request, BANNER); + if (bidfloor) { + placementInfo.bidFloor = bidfloor; } } return JSON.stringify(placementInfo); @@ -288,7 +289,7 @@ function openRtbImpression(bidRequest) { const imp = { id: bidRequest.bidId, tagid: bidRequest.adUnitCode, - bidfloor: bidRequest.params.bidfloor || 0, + bidfloor: getBidFloor(bidRequest, VIDEO), ext: { placement_id: bidRequest.params.placementId }, @@ -312,6 +313,16 @@ function openRtbImpression(bidRequest) { return imp; } +function getBidFloor(bidRequest, mediaType) { + let floorInfo = {}; + + if (typeof bidRequest.getFloor === 'function') { + floorInfo = bidRequest.getFloor({ currency: CURRENCY, mediaType, size: '*' }); + } + + return floorInfo.floor || bidRequest.params.bidfloor || 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/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index c736f0e5be4..17d63e41266 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 () { @@ -256,15 +258,63 @@ describe('YieldmoAdapter', function () { const data = buildAndGetData([mockBannerBid({schain})]); expect(data.schain).equal(JSON.stringify(schain)); }); + + it('should process floors module if available', function () { + const placementsData = JSON.parse(buildAndGetPlacementInfo([ + mockBannerBid({...mockGetFloor(3.99)}), + mockBannerBid({...mockGetFloor(1.23)}, { bidFloor: 1.1 }), + ])); + expect(placementsData[0].bidFloor).to.equal(3.99); + expect(placementsData[1].bidFloor).to.equal(1.23); + }); + + it('should use bidFloor if no floors module is available', function() { + const placementsData = JSON.parse(buildAndGetPlacementInfo([ + mockBannerBid({}, { bidFloor: 1.2 }), + mockBannerBid({}, { bidFloor: 0.7 }), + ])); + expect(placementsData[0].bidFloor).to.equal(1.2); + expect(placementsData[1].bidFloor).to.equal(0.7); + }); + + it('should not write 0 bidfloor value by default', function() { + const placementsData = JSON.parse(buildAndGetPlacementInfo([mockBannerBid()])); + expect(placementsData[0].bidfloor).to.undefined; + }); }); 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); + }); }); });