Skip to content

Commit

Permalink
validated size array and added tests (prebid#2870)
Browse files Browse the repository at this point in the history
  • Loading branch information
brittanyzellman authored and florevallatmrf committed Sep 6, 2018
1 parent 04284d4 commit cd19a8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
20 changes: 6 additions & 14 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const tripleliftAdapterSpec = {

tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid');
tlCall = utils.tryAppendQueryString(tlCall, 'v', '$prebid.version$');
// tlCall = utils.tryAppendQueryString(tlCall, 'fe', _isFlashEnabled().toString());
tlCall = utils.tryAppendQueryString(tlCall, 'referrer', referrer);

if (bidderRequest && bidderRequest.timeout) {
Expand Down Expand Up @@ -93,14 +92,19 @@ function _buildPostBody(bidRequests) {
}

function _sizes(sizeArray) {
return sizeArray.map(function(size) {
let sizes = sizeArray.filter(_isValidSize);
return sizes.map(function(size) {
return {
w: size[0],
h: size[1]
};
});
}

function _isValidSize(size) {
return (size.length === 2 && typeof size[0] === 'number' && typeof size[1] === 'number');
}

function _buildResponseObject(bidderRequest, bid) {
let bidResponse = {};
let width = bid.width || 1;
Expand All @@ -125,16 +129,4 @@ function _buildResponseObject(bidderRequest, bid) {
return bidResponse;
}

// function _isFlashEnabled() {
// let flash;
// try {
// flash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
// } catch (e) {
// flash = navigator.mimeTypes &&
// navigator.mimeTypes['application/x-shockwave-flash'] !== undefined &&
// navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin ? 1 : 0
// }
// return flash ? 1 : 0;
// }

registerBidder(tripleliftAdapterSpec);
8 changes: 7 additions & 1 deletion test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('triplelift adapter', () => {
floor: 1.0,
},
adUnitCode: 'adunit-code',
sizes: [[300, 250], [300, 600]],
sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
Expand All @@ -73,6 +73,12 @@ describe('triplelift adapter', () => {
expect(request).to.exist.and.to.be.a('object');
});

it('should only parse sizes that are of the proper length and format', () => {
const request = tripleliftAdapterSpec.buildRequests(bidRequests);
expect(request.data.imp[0].banner.format).to.have.length(2);
expect(request.data.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]);
});

it('should be a post request and populate the payload', () => {
const request = tripleliftAdapterSpec.buildRequests(bidRequests);
const payload = request.data;
Expand Down

0 comments on commit cd19a8e

Please sign in to comment.