diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index 840ba8a82aa..53b13ecf944 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -6,7 +6,6 @@ import { isEmpty, isFn, isInteger, - isPlainObject, logError } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -176,7 +175,7 @@ export const spec = { * Makes server requests from the list of BidRequests. * * @param {BidRequest[]} validBidRequests an array of bids - * @param {BidderRequest} bidderRequest bidder request object + * @param {BidRequest} bidderRequest bidder request object * @return {ServerRequest[]} Info describing the request to the server. */ buildRequests: function (validBidRequests, bidderRequest) { @@ -332,18 +331,22 @@ export const spec = { * @param {string} mediaType Bid media type * @return {number} Floor price */ - getBidFloor: function (bid, currency, mediaType) { - if (!isFn(bid.getFloor)) { - return DEFAULT_FLOOR; + getBidFloor: (bid, currency, mediaType) => { + const floors = []; + + if (isFn(bid.getFloor)) { + (deepAccess(bid, `mediaTypes.${mediaType}.${mediaType === BANNER ? 'sizes' : 'playerSize'}`) || []).forEach(size => { + const floor = bid.getFloor({ + currency: currency || 'USD', + mediaType, + size + }).floor; + + floors.push(!isNaN(floor) ? floor : DEFAULT_FLOOR); + }); } - const floor = bid.getFloor({ - currency: currency || 'USD', - mediaType, - size: '*' - }); - - return isPlainObject(floor) && !isNaN(floor.floor) ? floor.floor : DEFAULT_FLOOR; + return floors.length ? Math.min(...floors) : DEFAULT_FLOOR; }, /** diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 08b9f616551..3ee00a99bd9 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1311,17 +1311,6 @@ describe('Smart bid adapter tests', function () { expect(bidRequest.bidfloor).to.deep.equal(DEFAULT_PARAMS[0].params.bidfloor); }); - it('should return floor from module', function() { - const moduleFloor = 1.5; - const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); - bidRequest.getFloor = function () { - return { floor: moduleFloor }; - }; - - const floor = spec.getBidFloor(bidRequest, 'EUR'); - expect(floor).to.deep.equal(moduleFloor); - }); - it('should return default floor when module not activated', function() { const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); @@ -1425,6 +1414,95 @@ describe('Smart bid adapter tests', function () { expect(bannerRequest).to.not.equal(null).and.to.not.be.undefined; expect(bannerRequest).to.have.property('bidfloor').and.to.equal(1.93); }); + + describe('#getBidFloor', () => { + let bid; + beforeEach(() => { + bid = { + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600] + ] + } + }, + getFloor: (data) => { + if (data.currency === 'USD') { + if (data.mediaType === BANNER) { + if (data.size[0] === 300 && data.size[1] === 250) { + return { floor: 1.2 }; + } else if (data.size[0] === 300 && data.size[1] === 600) { + return { floor: 1.4 }; + } else if (data.size[0] === 30 && data.size[1] === 60) { + return 'string'; + } else { + return { floor: 1.0 }; + } + } else if (data.mediaType === VIDEO) { + if (data.size[0] === 640 && data.size[1] === 480) { + return { floor: 2.3 }; + } else { + return { floor: 2.1 }; + } + } else { + return {}; + } + } else { + return undefined; + } + } + }; + }); + + it('should return lowest floor from specified ones', () => { + expect(spec.getBidFloor(bid, 'USD', BANNER)).to.deep.eq(1.2); + }); + + it('should return default floor for media type whatever size', () => { + bid.mediaTypes.banner.sizes.push([300, 400]); + expect(spec.getBidFloor(bid, 'USD', BANNER)).to.deep.eq(1.0); + }); + + it('should return default floor', () => { + expect(spec.getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(0); + }); + + it('should return floor when currency not passed', () => { + expect(spec.getBidFloor(bid, undefined, BANNER)).to.deep.eq(1.2); + }); + + it('should return DEFAULT_FLOOR in case of not a number value from floor module', () => { + bid.mediaTypes.banner.sizes.push([30, 60]); + expect(spec.getBidFloor(bid, 'USD', BANNER)).to.deep.eq(0); + }); + + it('should return proper video floor', () => { + bid.mediaTypes = { + video: { + playerSize: [ + [640, 480] + ] + } + }; + expect(spec.getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(2.3); + }); + + it('should return default video floor', () => { + bid.mediaTypes = { + video: { + playerSize: [ + [640, 490] + ] + } + }; + expect(spec.getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(2.1); + }); + + it('should return DEFAULT_FLOOR for not supported media type', () => { + expect(spec.getBidFloor(bid, 'USD', 'test')).to.deep.eq(0); + }); + }); }); describe('Verify bid requests with multiple mediaTypes', function () {