Skip to content

Commit

Permalink
get min floor
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofequativ committed Oct 21, 2024
1 parent 3fac9a9 commit e65525d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 23 deletions.
27 changes: 15 additions & 12 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
isEmpty,
isFn,
isInteger,
isPlainObject,
logError
} from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
},

/**
Expand Down
92 changes: 81 additions & 11 deletions test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit e65525d

Please sign in to comment.