Skip to content

Commit

Permalink
adding additional bid request validity checks. updating how we grab …
Browse files Browse the repository at this point in the history
…sizes array (prebid#3317)

* Submitting EMX Digital Prebid Adapter

Submitting EMX Digital Prebid Adapter code

* fixing lint errors. updating our md

* updating to const/let variables. adding test spec.

* fixed linting on test spec js

* adding emx usersync methods

* updating valid bid request checks and protocol check.

* remove includes replaced with indexOf

* adding more bid valid checks. updating how we grab sizes array

* linting fix

* code typo fixed

* updated our spec
  • Loading branch information
EMXDigital authored and Loic Talon committed Dec 19, 2018
1 parent 7a9859b commit 2ec4b62
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 7 deletions.
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

0 comments on commit 2ec4b62

Please sign in to comment.