From 442922f80eb6384f9668d4503f595c0520c6b722 Mon Sep 17 00:00:00 2001 From: Dan Bogdan <43830380+EMXDigital@users.noreply.github.com> Date: Tue, 4 Dec 2018 14:16:58 -0500 Subject: [PATCH] adding additional bid request validity checks. updating how we grab sizes array (#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 --- modules/emx_digitalBidAdapter.js | 29 +++++++-- .../modules/emx_digitalBidAdapter_spec.js | 63 ++++++++++++++++++- 2 files changed, 85 insertions(+), 7 deletions(-) diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js index 78f8f2d7ad7..bd905835212 100644 --- a/modules/emx_digitalBidAdapter.js +++ b/modules/emx_digitalBidAdapter.js @@ -156,12 +156,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(); @@ -174,22 +187,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); });