Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yieldlab Bid Adapter : fix floor format #9186

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const spec = {

const adslotIds = []
const adslotSizes = [];
const adslotFloors = [];
const timestamp = Date.now()
const query = {
ts: timestamp,
Expand Down Expand Up @@ -77,7 +78,7 @@ export const spec = {
}
const floor = getBidFloor(bid, sizes)
if (floor) {
query.floor = floor;
adslotFloors.push(bid.params.adslotId + ':' + floor);
}
})

Expand All @@ -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 {
Expand Down Expand Up @@ -452,7 +458,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) {
Expand All @@ -464,10 +470,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;
}
Expand Down
69 changes: 49 additions & 20 deletions test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,36 +533,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')
Expand Down