From f5f276bb827d5b81b12b2c62e405bb11768690e5 Mon Sep 17 00:00:00 2001 From: ahmadlob <109217988+ahmadlob@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:54:43 +0200 Subject: [PATCH] Taboola Bid Adapter: Fixing Accepting Bid Floor Mechanism (#9279) * use-convention-for-bidfloor-extraction * use-convention-for-bidfloor-extraction * add-unit-tests --- modules/taboolaBidAdapter.js | 27 ++++++++++---- test/spec/modules/taboolaBidAdapter_spec.js | 39 +++++++++++++++++++++ 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/modules/taboolaBidAdapter.js b/modules/taboolaBidAdapter.js index 9bd42651796..670d28ab64e 100644 --- a/modules/taboolaBidAdapter.js +++ b/modules/taboolaBidAdapter.js @@ -170,15 +170,28 @@ function getSiteProperties({publisherId, bcat = []}, refererInfo) { function getImps(validBidRequests) { return validBidRequests.map((bid, id) => { - const {tagId, bidfloor = null, bidfloorcur = CURRENCY} = bid.params; - - return { + const {tagId} = bid.params; + const imp = { id: id + 1, banner: getBanners(bid), - tagid: tagId, - bidfloor, - bidfloorcur, - }; + tagid: tagId + } + if (typeof bid.getFloor === 'function') { + const floorInfo = bid.getFloor({ + currency: CURRENCY, + mediaType: BANNER, + size: '*' + }); + if (typeof floorInfo === 'object' && floorInfo.currency === CURRENCY && !isNaN(parseFloat(floorInfo.floor))) { + imp.bidfloor = parseFloat(floorInfo.floor); + imp.bidfloorcur = CURRENCY; + } + } else { + const {bidfloor = null, bidfloorcur = CURRENCY} = bid.params; + imp.bidfloor = bidfloor; + imp.bidfloorcur = bidfloorcur; + } + return imp; }); } diff --git a/test/spec/modules/taboolaBidAdapter_spec.js b/test/spec/modules/taboolaBidAdapter_spec.js index c0b16ac40fc..5bde75cd0b6 100644 --- a/test/spec/modules/taboolaBidAdapter_spec.js +++ b/test/spec/modules/taboolaBidAdapter_spec.js @@ -167,6 +167,45 @@ describe('Taboola Adapter', function () { expect(resData.imp[0].bidfloorcur).to.deep.equal('EUR'); }); + it('should pass bid floor', function () { + const bidRequest = { + ...defaultBidRequest, + params: {...commonBidRequest.params}, + getFloor: function() { + return { + currency: 'USD', + floor: 2.7, + } + } + }; + const res = spec.buildRequests([bidRequest], commonBidderRequest); + const resData = JSON.parse(res.data); + expect(resData.imp[0].bidfloor).to.deep.equal(2.7); + expect(resData.imp[0].bidfloorcur).to.deep.equal('USD'); + }); + + it('should pass bid floor even if they is a bid floor param', function () { + const optionalParams = { + bidfloor: 0.25, + bidfloorcur: 'EUR' + }; + + const bidRequest = { + ...defaultBidRequest, + params: {...commonBidRequest.params, ...optionalParams}, + getFloor: function() { + return { + currency: 'USD', + floor: 2.7, + } + } + }; + const res = spec.buildRequests([bidRequest], commonBidderRequest); + const resData = JSON.parse(res.data); + expect(resData.imp[0].bidfloor).to.deep.equal(2.7); + expect(resData.imp[0].bidfloorcur).to.deep.equal('USD'); + }); + it('should pass bidder timeout', function () { const bidderRequest = { ...commonBidderRequest,