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

Grid Bid Adapter: parse timeout and bidfloor to integer and float values #10461

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
10 changes: 5 additions & 5 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const spec = {
let {bidderRequestId, gdprConsent, uspConsent, timeout, refererInfo, gppConsent} = bidderRequest || {};

const referer = refererInfo ? encodeURIComponent(refererInfo.page) : '';
const tmax = timeout;
const tmax = parseInt(timeout) || null;
const imp = [];
const bidsMap = {};
const requests = [];
Expand Down Expand Up @@ -133,7 +133,7 @@ export const spec = {
};
if (ortb2Imp) {
if (ortb2Imp.instl) {
impObj.instl = ortb2Imp.instl;
impObj.instl = parseInt(ortb2Imp.instl) || null;
}

if (ortb2Imp.ext) {
Expand Down Expand Up @@ -485,7 +485,7 @@ export const spec = {
*/
function _getFloor (mediaTypes, bid) {
const curMediaType = mediaTypes.video ? 'video' : 'banner';
let floor = bid.params.bidFloor || bid.params.floorcpm || 0;
let floor = parseFloat(bid.params.bidFloor || bid.params.floorcpm || 0) || null;

if (typeof bid.getFloor === 'function') {
const floorInfo = bid.getFloor({
Expand Down Expand Up @@ -595,8 +595,8 @@ function createVideoRequest(videoParams, mediaType, bidSizes) {

if (!videoData.w || !videoData.h) return;

const minDur = mind || durationRangeSec[0] || videoData.minduration;
const maxDur = maxd || durationRangeSec[1] || videoData.maxduration;
const minDur = mind || durationRangeSec[0] || parseInt(videoData.minduration) || null;
const maxDur = maxd || durationRangeSec[1] || parseInt(videoData.maxduration) || null;

if (minDur) {
videoData.minduration = minDur;
Expand Down
18 changes: 18 additions & 0 deletions test/spec/modules/gridBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,15 @@ describe('TheMediaGrid Adapter', function () {
getDataFromLocalStorageStub.restore();
})

it('tmax should be set as integer', function() {
let [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, timeout: '10'});
let payload = parseRequest(request.data);
expect(payload.tmax).to.equal(10);
[request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, timeout: 'ddqwdwdq'});
payload = parseRequest(request.data);
expect(payload.tmax).to.equal(null);
})

describe('floorModule', function () {
const floorTestData = {
'currency': 'USD',
Expand Down Expand Up @@ -975,6 +984,15 @@ describe('TheMediaGrid Adapter', function () {
const payload = parseRequest(request.data);
expect(payload.imp[0].bidfloor).to.equal(bidfloor);
});
it('should return the bidfloor string value if it is greater than getFloor.floor', function () {
const bidfloor = '1.80';
const bidRequestsWithFloor = { ...bidRequest };
bidRequestsWithFloor.params = Object.assign({bidFloor: bidfloor}, bidRequestsWithFloor.params);
const [request] = spec.buildRequests([bidRequestsWithFloor], bidderRequest);
expect(request.data).to.be.an('string');
const payload = parseRequest(request.data);
expect(payload.imp[0].bidfloor).to.equal(1.80);
});
});
});

Expand Down