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

adding additional bid request validity checks. updating how we grab sizes array #3317

Merged
merged 17 commits into from
Dec 4, 2018
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
29 changes: 23 additions & 6 deletions modules/emx_digitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ import {

const BIDDER_CODE = 'emx_digital';
const ENDPOINT = 'hb.emxdgt.com';

let emxAdapter = {};

emxAdapter.validateSizes = function(sizes) {
if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') {
return false;
}
return sizes.every(size => utils.isArray(size) && size.length === 2);
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
return !!bid.params.tagid && typeof bid.params.tagid === 'string' &&
(typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'string');
return !!bid.params.tagid &&
typeof bid.params.tagid === 'string' &&
(typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'string') &&
bid.bidder === BIDDER_CODE &&
(emxAdapter.validateSizes(bid.mediaTypes.banner.sizes) || emxAdapter.validateSizes(bid.sizes));
},
buildRequests: function (validBidRequests, bidRequests) {
const {host, href, protocol} = utils.getTopWindowLocation();
Expand All @@ -29,22 +42,26 @@ export const spec = {
const networkProtocol = protocol.indexOf('https') > -1 ? 1 : 0;

utils._each(validBidRequests, function (bid) {
let tagId = String(utils.getBidIdParameter('tagid', bid.params));
let tagId = utils.getBidIdParameter('tagid', bid.params);
let bidFloor = parseFloat(utils.getBidIdParameter('bidfloor', bid.params)) || 0;
let sizes = bid.mediaTypes.banner.sizes;
if (!emxAdapter.validateSizes(sizes)) {
sizes = bid.sizes
}
let emxBid = {
id: bid.bidId,
tid: bid.transactionId,
tagid: tagId,
secure: networkProtocol,
banner: {
format: bid.sizes.map(function (size) {
format: sizes.map(function (size) {
return {
w: size[0],
h: size[1]
};
}),
w: bid.sizes[0][0],
h: bid.sizes[0][1]
w: sizes[0][0],
h: sizes[0][1]
}
}
if (bidFloor > 0) {
Expand Down
63 changes: 62 additions & 1 deletion test/spec/modules/emx_digitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe('emx_digital Adapter', function () {
'params': {
'tagid': '25251'
},
'mediaTypes': {
'banner': {
'sizes': [
[300, 250],
[300, 600]
]
}
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250],
Expand All @@ -34,16 +42,69 @@ describe('emx_digital Adapter', function () {

it('should contain tagid param', function () {
expect(spec.isBidRequestValid({
params: {}
bidder: 'emx_digital',
params: {},
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600]
]
}
}
})).to.equal(false);
expect(spec.isBidRequestValid({
bidder: 'emx_digital',
params: {
tagid: ''
},
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600]
]
}
}
})).to.equal(false);
expect(spec.isBidRequestValid({
bidder: 'emx_digital',
params: {
tagid: '123'
},
mediaTypes: {
banner: {
sizes: [
]
}
}
})).to.equal(false);
expect(spec.isBidRequestValid({
bidder: 'emxdigital',
params: {
tagid: '123'
},
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600]
]
}
}
})).to.equal(false);
expect(spec.isBidRequestValid({
bidder: 'emx_digital',
params: {
tagid: '123'
},
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600]
]
}
}
})).to.equal(true);
});
Expand Down