Skip to content

Commit 297d875

Browse files
committed
Use currencyUtils bid floor tool instead of custom logic.
1 parent 91dcfa3 commit 297d875

File tree

2 files changed

+11
-74
lines changed

2 files changed

+11
-74
lines changed

modules/fanBidAdapter.js

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
22
import { registerBidder } from '../src/adapters/bidderFactory.js';
33
import { BANNER, VIDEO } from '../src/mediaTypes.js';
4-
import { deepAccess, deepSetValue, isFn, isNumber, isPlainObject, logInfo, logWarn, logError, triggerPixel } from '../src/utils.js';
4+
import { deepAccess, deepSetValue, isNumber, logInfo, logWarn, logError, triggerPixel } from '../src/utils.js';
5+
import { getBidFloor } from '../libraries/currencyUtils/floor.js';
56
import { getStorageManager } from '../src/storageManager.js';
67
import { Renderer } from '../src/Renderer.js';
78
import { getGptSlotInfoForAdUnitCode } from '../libraries/gptUtils/gptUtils.js';
@@ -37,14 +38,13 @@ const converter = ortbConverter({
3738

3839
// There is no default floor. bidfloor is set only
3940
// if the priceFloors module is activated and returns a valid floor.
40-
const floor = getMinFloor(bidRequest);
41+
const floor = getBidFloor(bidRequest);
4142
if (isNumber(floor)) {
4243
imp.bidfloor = floor;
4344
}
4445

45-
// Add floor price
46-
if (bidRequest.params.bidFloor) {
47-
imp.bidfloor = parseFloat(bidRequest.params.bidFloor);
46+
// Add floor currency
47+
if (bidRequest.params.bidFloorCur) {
4848
imp.bidfloorcur = bidRequest.params.bidFloorCur || DEFAULT_CURRENCY;
4949
}
5050

@@ -304,58 +304,6 @@ export const spec = {
304304
},
305305
};
306306

307-
/**
308-
* Returns floor from priceFloors module or MediaKey default value.
309-
*
310-
* @param {*} bid a Prebid.js bid (request) object
311-
* @param {string} mediaType the mediaType or the wildcard '*'
312-
* @param {string|Array} size the size array or the wildcard '*'
313-
* @returns {number|boolean}
314-
*/
315-
function getFloor(bid, mediaType, size = '*') {
316-
if (!isFn(bid.getFloor)) {
317-
return false;
318-
}
319-
320-
if (spec.supportedMediaTypes.indexOf(mediaType) === -1) {
321-
logWarn(
322-
`${BIDDER_CODE}: Unable to detect floor price for unsupported mediaType ${mediaType}. No floor will be used.`
323-
);
324-
325-
return false;
326-
}
327-
328-
const floor = bid.getFloor({
329-
currency: DEFAULT_CURRENCY,
330-
mediaType,
331-
size,
332-
});
333-
334-
return isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === DEFAULT_CURRENCY
335-
? floor.floor
336-
: false;
337-
}
338-
339-
function getMinFloor(bid) {
340-
const floors = [];
341-
342-
for (let mediaType in bid.mediaTypes) {
343-
const floor = getFloor(bid, mediaType);
344-
345-
if (isNumber(floor)) {
346-
floors.push(floor);
347-
}
348-
}
349-
350-
if (!floors.length) {
351-
return false;
352-
}
353-
354-
return floors.reduce((a, b) => {
355-
return Math.min(a, b);
356-
});
357-
}
358-
359307
/**
360308
* Build sync URL with privacy parameters
361309
*/

test/spec/modules/fanBidAdapter_spec.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,21 @@ describe('freedomadnetworkAdapter', function() {
160160
const videoBid = validBidRequestVideo;
161161
const reqVideo = spec.buildRequests([videoBid], bidderRequest)[0];
162162
const impVideo = reqVideo.data.imp[0];
163-
expect(impVideo.bidfloor).to.equal(parseFloat(videoBid.params.bidFloor));
163+
expect(impVideo.bidfloor).to.equal(0);
164164
expect(impVideo.bidfloorcur).to.equal(videoBid.params.bidFloorCur);
165165
});
166166

167167
describe('PriceFloors module support', function () {
168-
it('should not set `imp[]bidfloor` property when priceFloors module is not available', function () {
168+
it('should get default bid floor', function () {
169169
const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner));
170170
const requests = spec.buildRequests([bidTest], bidderRequest);
171171

172172
const data = requests[0].data;
173173
expect(data.imp[0].banner).to.exist;
174-
expect(data.imp[0].bidfloor).to.not.exist;
174+
expect(data.imp[0].bidfloor).to.equal(0);
175175
});
176176

177-
it('should not set `imp[]bidfloor` property when priceFloors module returns false', function () {
177+
it('should not add bid floor if getFloor fails', function () {
178178
const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner));
179179
bidTest.getFloor = () => {
180180
return false;
@@ -187,29 +187,18 @@ describe('freedomadnetworkAdapter', function() {
187187
expect(data.imp[0].bidfloor).to.not.exist;
188188
});
189189

190-
it('should get the highest floorPrice found when bid have several mediaTypes', function () {
191-
const getFloorTest = (options) => {
192-
switch (options.mediaType) {
193-
case BANNER:
194-
return { floor: 1, currency: DEFAULT_CURRENCY };
195-
default:
196-
return false;
197-
}
198-
};
199-
190+
it('should get the floor when bid have several mediaTypes', function () {
200191
const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner));
201192

202193
bidTest.mediaTypes.video = {
203194
playerSize: [600, 480],
204195
};
205196

206-
bidTest.getFloor = getFloorTest;
207-
208197
const requests = spec.buildRequests([bidTest], bidderRequest);
209198

210199
const data = requests[0].data;
211200
expect(data.imp[0].banner).to.exist;
212-
expect(data.imp[0].bidfloor).to.equal(1);
201+
expect(data.imp[0].bidfloor).to.equal(0);
213202
});
214203
});
215204
});

0 commit comments

Comments
 (0)