From a3b43713cf9146412594e42d0f036013f364c949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Tue, 15 Oct 2024 16:21:11 +0200 Subject: [PATCH 1/5] get min floor --- modules/smartadserverBidAdapter.js | 27 +++--- .../modules/smartadserverBidAdapter_spec.js | 92 ++++++++++++++++--- 2 files changed, 96 insertions(+), 23 deletions(-) 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..cbc680fd313 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,87 @@ 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.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 {}; + } + } + }; + }); + + it('should return lowest floor from specified ones', () => { + expect(spec.getBidFloor(bid, 'DKK', 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, 'DKK', BANNER)).to.deep.eq(1.0); + }); + + it('should return default floor', () => { + expect(spec.getBidFloor(bid, 'DKK', VIDEO)).to.deep.eq(0); + }); + + it('should return default floor when currency not passed', () => { + expect(spec.getBidFloor(bid, undefined, BANNER)).to.deep.eq(1.2); + }); + + it('should return handle not number from floor module', () => { + bid.mediaTypes.banner.sizes.push([30, 60]); + expect(spec.getBidFloor(bid, 'DKK', BANNER)).to.deep.eq(0); + }); + + it('should return proper video floor', () => { + bid.mediaTypes = { + video: { + playerSize: [ + [640, 480] + ] + } + }; + expect(spec.getBidFloor(bid, 'DKK', VIDEO)).to.deep.eq(2.3); + }); + + it('should return default video floor', () => { + bid.mediaTypes = { + video: { + playerSize: [ + [640, 490] + ] + } + }; + expect(spec.getBidFloor(bid, 'DKK', VIDEO)).to.deep.eq(2.1); + }); + }); }); describe('Verify bid requests with multiple mediaTypes', function () { From bf54ad020a4375cc9da0b1c324c900be5cfd5850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 16 Oct 2024 12:23:13 +0200 Subject: [PATCH 2/5] fix desc for u.t. --- test/spec/modules/smartadserverBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index cbc680fd313..62c1b0de92c 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1468,7 +1468,7 @@ describe('Smart bid adapter tests', function () { expect(spec.getBidFloor(bid, undefined, BANNER)).to.deep.eq(1.2); }); - it('should return handle not number from floor module', () => { + it('should handle not number returned by floor module', () => { bid.mediaTypes.banner.sizes.push([30, 60]); expect(spec.getBidFloor(bid, 'DKK', BANNER)).to.deep.eq(0); }); From da43c657b444b6690f9039ae9b996035f695f784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 16 Oct 2024 12:25:42 +0200 Subject: [PATCH 3/5] better name for u.t. --- test/spec/modules/smartadserverBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 62c1b0de92c..5800a967c8c 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1468,7 +1468,7 @@ describe('Smart bid adapter tests', function () { expect(spec.getBidFloor(bid, undefined, BANNER)).to.deep.eq(1.2); }); - it('should handle not number returned by floor module', () => { + 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, 'DKK', BANNER)).to.deep.eq(0); }); From e453adabacf86e5f185cb071bc17a3ae747a8c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 16 Oct 2024 12:32:10 +0200 Subject: [PATCH 4/5] add u.t. for not supported media type --- test/spec/modules/smartadserverBidAdapter_spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 5800a967c8c..0a62d5207db 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1494,6 +1494,10 @@ describe('Smart bid adapter tests', function () { }; expect(spec.getBidFloor(bid, 'DKK', 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); + }); }); }); From 6bc6850654be6e3ef0fbc7ee0f35eea70d15588a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Sok=C3=B3=C5=82?= Date: Wed, 16 Oct 2024 12:52:15 +0200 Subject: [PATCH 5/5] improve currency u.t. --- .../modules/smartadserverBidAdapter_spec.js | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 0a62d5207db..3ee00a99bd9 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1428,49 +1428,53 @@ describe('Smart bid adapter tests', function () { } }, getFloor: (data) => { - 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'; + 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 { 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 }; + return {}; } } else { - return {}; + return undefined; } } }; }); it('should return lowest floor from specified ones', () => { - expect(spec.getBidFloor(bid, 'DKK', BANNER)).to.deep.eq(1.2); + 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, 'DKK', BANNER)).to.deep.eq(1.0); + expect(spec.getBidFloor(bid, 'USD', BANNER)).to.deep.eq(1.0); }); it('should return default floor', () => { - expect(spec.getBidFloor(bid, 'DKK', VIDEO)).to.deep.eq(0); + expect(spec.getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(0); }); - it('should return default floor when currency not passed', () => { + 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, 'DKK', BANNER)).to.deep.eq(0); + expect(spec.getBidFloor(bid, 'USD', BANNER)).to.deep.eq(0); }); it('should return proper video floor', () => { @@ -1481,7 +1485,7 @@ describe('Smart bid adapter tests', function () { ] } }; - expect(spec.getBidFloor(bid, 'DKK', VIDEO)).to.deep.eq(2.3); + expect(spec.getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(2.3); }); it('should return default video floor', () => { @@ -1492,7 +1496,7 @@ describe('Smart bid adapter tests', function () { ] } }; - expect(spec.getBidFloor(bid, 'DKK', VIDEO)).to.deep.eq(2.1); + expect(spec.getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(2.1); }); it('should return DEFAULT_FLOOR for not supported media type', () => {