From 3d6899a3176ff6c4bcd9fdbc711ac5371074f12d Mon Sep 17 00:00:00 2001 From: nkloeber <100145701+nkloeber@users.noreply.github.com> Date: Fri, 18 Nov 2022 17:42:37 +0100 Subject: [PATCH] Update Floor format to floor={adslotId}:{floorPriceInCents}[, ...] and fix the size which is submitted to the Price Floors Module (#9186) --- modules/yieldlabBidAdapter.js | 14 ++-- test/spec/modules/yieldlabBidAdapter_spec.js | 69 ++++++++++++++------ 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/modules/yieldlabBidAdapter.js b/modules/yieldlabBidAdapter.js index e6758e78022..88e1494d416 100644 --- a/modules/yieldlabBidAdapter.js +++ b/modules/yieldlabBidAdapter.js @@ -41,6 +41,7 @@ export const spec = { const adslotIds = [] const adslotSizes = []; + const adslotFloors = []; const timestamp = Date.now() const query = { ts: timestamp, @@ -77,7 +78,7 @@ export const spec = { } const floor = getBidFloor(bid, sizes) if (floor) { - query.floor = floor; + adslotFloors.push(bid.params.adslotId + ':' + floor); } }) @@ -99,6 +100,11 @@ export const spec = { if (adslotSizes.length > 0) { query.sizes = adslotSizes.join(',') } + + if (adslotFloors.length > 0) { + query.floor = adslotFloors.join(',') + } + const queryString = createQueryString(query) return { @@ -463,7 +469,7 @@ function extractSizes(bid) { * * @param {Object} bid * @param {string[]} sizes - * @returns The floor CPM of a matched rule based on the rule selection process (mediaType, size and currency), + * @returns The floor CPM in cents of a matched rule based on the rule selection process (mediaType, size and currency), * using the getFloor() inputs. Multi sizes and unsupported media types will default to '*' */ function getBidFloor(bid, sizes) { @@ -475,10 +481,10 @@ function getBidFloor(bid, sizes) { const floor = bid.getFloor({ currency: CURRENCY_CODE, mediaType: mediaType !== undefined && spec.supportedMediaTypes.includes(mediaType) ? mediaType : '*', - size: sizes.length !== 1 ? '*' : extractSizes(sizes) + size: sizes.length !== 1 ? '*' : sizes[0].split(DIMENSION_SIGN) }); if (floor.currency === CURRENCY_CODE) { - return floor.floor; + return (floor.floor * 100).toFixed(0); } return undefined; } diff --git a/test/spec/modules/yieldlabBidAdapter_spec.js b/test/spec/modules/yieldlabBidAdapter_spec.js index 9155884106c..5df0e93d34e 100644 --- a/test/spec/modules/yieldlabBidAdapter_spec.js +++ b/test/spec/modules/yieldlabBidAdapter_spec.js @@ -658,36 +658,65 @@ describe('yieldlabBidAdapter', () => { }); describe('getBidFloor', function () { - let bidRequest, getFloor; - - it('should add valid bid floor', () => { - getFloor = () => { - return { - currency: 'EUR', - floor: 1.33 - }; - }; + let bidRequest, bidRequest2, currency, floor; + const getFloor = () => { + return { + currency: currency, + floor: floor + } + } + + it('should add valid bid floor in the format floor={adslotId}:{floorPriceInCents}[, ...]', () => { + bidRequest = Object.assign(DEFAULT_REQUEST(), { + getFloor: () => { + return { + currency: 'EUR', + floor: 1.33 + } + }}); + bidRequest2 = Object.assign(DEFAULT_REQUEST(), { + params: { + adslotId: 2222 + }, + getFloor: () => { + return { + currency: 'EUR', + floor: 2.99 + } + } + }); + const result = spec.buildRequests([bidRequest, bidRequest2], REQPARAMS) + expect(result).to.have.nested.property('queryParams.floor', '1111:133,2222:299') + }); + + it('should round the floor price up', () => { + currency = 'EUR'; + floor = 0.745; bidRequest = Object.assign(DEFAULT_REQUEST(), {getFloor}) const result = spec.buildRequests([bidRequest], REQPARAMS) - expect(result).to.have.nested.property('queryParams.floor', 1.33) + expect(result).to.have.nested.property('queryParams.floor', '1111:75') }); - it('should not add empty bid floor', () => { - getFloor = () => { - return {}; - }; + it('should round the floor price down', () => { + currency = 'EUR'; + floor = 0.034; bidRequest = Object.assign(DEFAULT_REQUEST(), {getFloor}) const result = spec.buildRequests([bidRequest], REQPARAMS) + expect(result).to.have.nested.property('queryParams.floor', '1111:3') + }); + + it('should not add empty bid floor', () => { + bidRequest = Object.assign(DEFAULT_REQUEST(), { + getFloor: () => { + return {}; + }}) + const result = spec.buildRequests([bidRequest], REQPARAMS) expect(result).not.to.have.nested.property('queryParams.floor') }); it('should not add bid floor when currency is not matching', () => { - getFloor = (currency, mediaType, size) => { - return { - currency: 'USD', - floor: 1.33 - }; - }; + currency = 'USD'; + floor = 1.33; bidRequest = Object.assign(DEFAULT_REQUEST(), {getFloor}) const result = spec.buildRequests([bidRequest], REQPARAMS) expect(result).not.to.have.nested.property('queryParams.floor')