diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js index 5638fa24e31..925c062a8cb 100644 --- a/modules/emx_digitalBidAdapter.js +++ b/modules/emx_digitalBidAdapter.js @@ -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(); @@ -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) { diff --git a/test/spec/modules/emx_digitalBidAdapter_spec.js b/test/spec/modules/emx_digitalBidAdapter_spec.js index dd34582e22d..85256c20bd9 100644 --- a/test/spec/modules/emx_digitalBidAdapter_spec.js +++ b/test/spec/modules/emx_digitalBidAdapter_spec.js @@ -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], @@ -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); });