Skip to content

Commit

Permalink
Grid Bid Adapter: parse timeout and bidfloor to integer and float val…
Browse files Browse the repository at this point in the history
…ues (#10461)

Co-authored-by: v.raybaud <[email protected]>
  • Loading branch information
vraybaud and v.raybaud committed Sep 12, 2023
1 parent 779146a commit 4f8cf68
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
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

0 comments on commit 4f8cf68

Please sign in to comment.