From 876de32d166ee9e2b0b4822886b77971487910f3 Mon Sep 17 00:00:00 2001 From: Dan Bogdan <43830380+EMXDigital@users.noreply.github.com> Date: Thu, 11 Oct 2018 14:49:31 -0400 Subject: [PATCH 1/4] Submitting EMX Digital Prebid Adapter Submitting EMX Digital Prebid Adapter code --- modules/emx_digitalBidAdapter.js | 106 +++++++++++++++++++++++++++++++ modules/emx_digitalBidAdapter.md | 67 +++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 modules/emx_digitalBidAdapter.js create mode 100644 modules/emx_digitalBidAdapter.md diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js new file mode 100644 index 00000000000..d2c34b1f499 --- /dev/null +++ b/modules/emx_digitalBidAdapter.js @@ -0,0 +1,106 @@ +import * as utils from 'src/utils'; +import { + registerBidder +} from 'src/adapters/bidderFactory'; +import { + BANNER +} from 'src/mediaTypes'; +import { + config +} from 'src/config'; + +const BIDDER_CODE = 'emx_digital'; +const ENDPOINT = 'hb.emxdgt.com'; +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + isBidRequestValid: function (bid) { + return !!(bid.params.tagid); + }, + buildRequests: function (validBidRequests, bidRequests) { + const {host, href, protocol} = utils.getTopWindowLocation(); + var emxData = {}; + var emxImps = []; + var auctionId = bidRequests.auctionId; + var timeout = config.getConfig('bidderTimeout'); + var timestamp = Date.now(); + var url = location.protocol + "//" + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp ); + + utils._each(validBidRequests, function (bid) { + let tagId = String(utils.getBidIdParameter('tagid', bid.params)); + let bidFloor = utils.getBidIdParameter('bidfloor', bid.params) || 0; + let emxBid = { + id: bid.bidId, + tid: bid.transactionId, + tagid: tagId, + secure: protocol === 'https:' ? 1 : 0, + banner: { + format: bid.sizes.map(function (size) { + return { + w: size[0], + h: size[1] + }; + }), + w: bid.sizes[0][0], + h: bid.sizes[0][1] + } + } + bidFloor > 0 ? emxBid.bidfloor = bidFloor : null; + emxImps.push(emxBid); + }); + emxData = { + id: auctionId, + imp: emxImps, + site: { + domain: host, + page: href + } + }; + if (bidRequests.gdprConsent) { + emxData.regs = { + ext: { + gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0 + } + }; + emxData.user = { + ext: { + consent: bidRequests.gdprConsent.consentString + } + }; + } + return { + method: 'POST', + url: url, + data: JSON.stringify(emxData), + options: { + withCredentials: true + } + }; + }, + interpretResponse: function (serverResponse) { + var emxBidResponses = []; + var response = serverResponse.body || {}; + if (response.seatbid && response.seatbid.length > 0 && response.seatbid[0].bid) { + response.seatbid.forEach(function (emxBid) { + emxBid = emxBid.bid[0]; + emxBidResponses.push({ + requestId: emxBid.id, + cpm: emxBid.price, + width: emxBid.w, + height: emxBid.h, + creativeId: emxBid.crid || emxBid.id, + dealId: emxBid.dealid || null, + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: decodeURIComponent(emxBid.adm), + ttl: emxBid.ttl + }); + }); + } + return emxBidResponses; + }, + getUserSyncs: function (syncOptions) { + } +}; +registerBidder(spec); \ No newline at end of file diff --git a/modules/emx_digitalBidAdapter.md b/modules/emx_digitalBidAdapter.md new file mode 100644 index 00000000000..b538f790a5a --- /dev/null +++ b/modules/emx_digitalBidAdapter.md @@ -0,0 +1,67 @@ +# Overview + +``` +Module Name: EMX Digital Adapter +Module Type: Bidder Adapter +Maintainer: git@emxdigital.com +``` + +# Description + +The EMX Digital adapter provides publishers with access to the EMX Marketplace. The adapter is GDPR compliant. Please note that the adapter supports Banner media type only. + +Note: The EMX Digital adapter requires approval and implementation guidelines from the EMX team, including existing publishers that work with EMX Digital. Please reach out to your account manager or prebid@emxdigital.com for more information. + +The bidder code should be ```emx_digital``` +The params used by the bidder are : +```tagid``` - string (mandatory) +```bidfloor``` - string (optional) + +# Test Parameters +``` +var adUnits = [{ + code: 'banner-div', + mediaTypes: { + banner: { + sizes: [[300, 600], [300, 250], [320, 90]], + } + }, + bids: [ + { + bidder: 'emx_digital', + params: { + tagid: 'test1', + } + }] +}, { + code: 'banner-div-2', + mediaTypes: { + banner: { + sizes: [[300, 300]], + } + }, + bids: [ + { + bidder: 'emx_digital', + params: { + tagid: 'test2', + bidfloor: '0.25' + } + }] +}, { + code: 'banner-div-3', + mediaTypes: { + banner: { + sizes: [[300, 600], [300, 250]], + } + }, + bids: [ + { + bidder: 'emx_digital', + params: { + tagid: 'test3', + bidfloor: '0.25' + } + }] +}]; +``` From 78caa11080b2646dd72e7f03e5f5818245dfe264 Mon Sep 17 00:00:00 2001 From: Dan Bogdan Date: Fri, 12 Oct 2018 15:36:15 -0400 Subject: [PATCH 2/4] fixing lint errors. updating our md --- modules/emx_digitalBidAdapter.js | 180 ++++++++++++++++--------------- modules/emx_digitalBidAdapter.md | 35 +----- 2 files changed, 94 insertions(+), 121 deletions(-) diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js index d2c34b1f499..a71bc0d5eff 100644 --- a/modules/emx_digitalBidAdapter.js +++ b/modules/emx_digitalBidAdapter.js @@ -1,106 +1,108 @@ import * as utils from 'src/utils'; import { - registerBidder + registerBidder } from 'src/adapters/bidderFactory'; import { - BANNER + BANNER } from 'src/mediaTypes'; import { - config + config } from 'src/config'; const BIDDER_CODE = 'emx_digital'; const ENDPOINT = 'hb.emxdgt.com'; export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - isBidRequestValid: function (bid) { - return !!(bid.params.tagid); - }, - buildRequests: function (validBidRequests, bidRequests) { - const {host, href, protocol} = utils.getTopWindowLocation(); - var emxData = {}; - var emxImps = []; - var auctionId = bidRequests.auctionId; - var timeout = config.getConfig('bidderTimeout'); - var timestamp = Date.now(); - var url = location.protocol + "//" + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp ); + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + isBidRequestValid: function (bid) { + return !!(bid.params.tagid); + }, + buildRequests: function (validBidRequests, bidRequests) { + const {host, href, protocol} = utils.getTopWindowLocation(); + var emxData = {}; + var emxImps = []; + var auctionId = bidRequests.auctionId; + var timeout = config.getConfig('bidderTimeout'); + var timestamp = Date.now(); + var url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp); - utils._each(validBidRequests, function (bid) { - let tagId = String(utils.getBidIdParameter('tagid', bid.params)); - let bidFloor = utils.getBidIdParameter('bidfloor', bid.params) || 0; - let emxBid = { - id: bid.bidId, - tid: bid.transactionId, - tagid: tagId, - secure: protocol === 'https:' ? 1 : 0, - banner: { - format: bid.sizes.map(function (size) { - return { - w: size[0], - h: size[1] - }; - }), - w: bid.sizes[0][0], - h: bid.sizes[0][1] - } - } - bidFloor > 0 ? emxBid.bidfloor = bidFloor : null; - emxImps.push(emxBid); - }); - emxData = { - id: auctionId, - imp: emxImps, - site: { - domain: host, - page: href - } - }; - if (bidRequests.gdprConsent) { - emxData.regs = { - ext: { - gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0 - } - }; - emxData.user = { - ext: { - consent: bidRequests.gdprConsent.consentString - } + utils._each(validBidRequests, function (bid) { + let tagId = String(utils.getBidIdParameter('tagid', bid.params)); + let bidFloor = utils.getBidIdParameter('bidfloor', bid.params) || 0; + let emxBid = { + id: bid.bidId, + tid: bid.transactionId, + tagid: tagId, + secure: protocol === 'https:' ? 1 : 0, + banner: { + format: bid.sizes.map(function (size) { + return { + w: size[0], + h: size[1] }; + }), + w: bid.sizes[0][0], + h: bid.sizes[0][1] + } + } + if (bidFloor > 0) { + emxBid.bidfloor = bidFloor + } + emxImps.push(emxBid); + }); + emxData = { + id: auctionId, + imp: emxImps, + site: { + domain: host, + page: href + } + }; + if (bidRequests.gdprConsent) { + emxData.regs = { + ext: { + gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0 } - return { - method: 'POST', - url: url, - data: JSON.stringify(emxData), - options: { - withCredentials: true - } - }; - }, - interpretResponse: function (serverResponse) { - var emxBidResponses = []; - var response = serverResponse.body || {}; - if (response.seatbid && response.seatbid.length > 0 && response.seatbid[0].bid) { - response.seatbid.forEach(function (emxBid) { - emxBid = emxBid.bid[0]; - emxBidResponses.push({ - requestId: emxBid.id, - cpm: emxBid.price, - width: emxBid.w, - height: emxBid.h, - creativeId: emxBid.crid || emxBid.id, - dealId: emxBid.dealid || null, - currency: 'USD', - netRevenue: true, - mediaType: BANNER, - ad: decodeURIComponent(emxBid.adm), - ttl: emxBid.ttl - }); - }); + }; + emxData.user = { + ext: { + consent: bidRequests.gdprConsent.consentString } - return emxBidResponses; - }, - getUserSyncs: function (syncOptions) { + }; + } + return { + method: 'POST', + url: url, + data: JSON.stringify(emxData), + options: { + withCredentials: true + } + }; + }, + interpretResponse: function (serverResponse) { + var emxBidResponses = []; + var response = serverResponse.body || {}; + if (response.seatbid && response.seatbid.length > 0 && response.seatbid[0].bid) { + response.seatbid.forEach(function (emxBid) { + emxBid = emxBid.bid[0]; + emxBidResponses.push({ + requestId: emxBid.id, + cpm: emxBid.price, + width: emxBid.w, + height: emxBid.h, + creativeId: emxBid.crid || emxBid.id, + dealId: emxBid.dealid || null, + currency: 'USD', + netRevenue: true, + mediaType: BANNER, + ad: decodeURIComponent(emxBid.adm), + ttl: emxBid.ttl + }); + }); } + return emxBidResponses; + }, + getUserSyncs: function (syncOptions) { + } }; -registerBidder(spec); \ No newline at end of file +registerBidder(spec); diff --git a/modules/emx_digitalBidAdapter.md b/modules/emx_digitalBidAdapter.md index b538f790a5a..c9435e2f1d1 100644 --- a/modules/emx_digitalBidAdapter.md +++ b/modules/emx_digitalBidAdapter.md @@ -23,44 +23,15 @@ var adUnits = [{ code: 'banner-div', mediaTypes: { banner: { - sizes: [[300, 600], [300, 250], [320, 90]], + sizes: [ + [300, 250], [300, 600] } }, bids: [ { bidder: 'emx_digital', params: { - tagid: 'test1', - } - }] -}, { - code: 'banner-div-2', - mediaTypes: { - banner: { - sizes: [[300, 300]], - } - }, - bids: [ - { - bidder: 'emx_digital', - params: { - tagid: 'test2', - bidfloor: '0.25' - } - }] -}, { - code: 'banner-div-3', - mediaTypes: { - banner: { - sizes: [[300, 600], [300, 250]], - } - }, - bids: [ - { - bidder: 'emx_digital', - params: { - tagid: 'test3', - bidfloor: '0.25' + tagid: '25251', } }] }]; From cd767e3aedd992904f767211f3d3a728d55b0e65 Mon Sep 17 00:00:00 2001 From: Daniel Bogdan Date: Wed, 17 Oct 2018 17:07:12 -0400 Subject: [PATCH 3/4] updating to const/let variables. adding test spec. --- modules/emx_digitalBidAdapter.js | 20 +- .../modules/emx_digitalBidAdapter_spec.js | 339 ++++++++++++++++++ 2 files changed, 349 insertions(+), 10 deletions(-) create mode 100644 test/spec/modules/emx_digitalBidAdapter_spec.js diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js index a71bc0d5eff..c25c20f2eda 100644 --- a/modules/emx_digitalBidAdapter.js +++ b/modules/emx_digitalBidAdapter.js @@ -19,12 +19,12 @@ export const spec = { }, buildRequests: function (validBidRequests, bidRequests) { const {host, href, protocol} = utils.getTopWindowLocation(); - var emxData = {}; - var emxImps = []; - var auctionId = bidRequests.auctionId; - var timeout = config.getConfig('bidderTimeout'); - var timestamp = Date.now(); - var url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp); + let emxData = {}; + let emxImps = []; + const auctionId = bidRequests.auctionId; + const timeout = config.getConfig('bidderTimeout'); + const timestamp = Date.now(); + const url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp); utils._each(validBidRequests, function (bid) { let tagId = String(utils.getBidIdParameter('tagid', bid.params)); @@ -64,6 +64,8 @@ export const spec = { gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0 } }; + } + if (bidRequests.gdprConsent && bidRequests.gdprConsent.gdprApplies) { emxData.user = { ext: { consent: bidRequests.gdprConsent.consentString @@ -80,8 +82,8 @@ export const spec = { }; }, interpretResponse: function (serverResponse) { - var emxBidResponses = []; - var response = serverResponse.body || {}; + let emxBidResponses = []; + let response = serverResponse.body || {}; if (response.seatbid && response.seatbid.length > 0 && response.seatbid[0].bid) { response.seatbid.forEach(function (emxBid) { emxBid = emxBid.bid[0]; @@ -101,8 +103,6 @@ export const spec = { }); } return emxBidResponses; - }, - getUserSyncs: function (syncOptions) { } }; registerBidder(spec); diff --git a/test/spec/modules/emx_digitalBidAdapter_spec.js b/test/spec/modules/emx_digitalBidAdapter_spec.js new file mode 100644 index 00000000000..944d87d1f96 --- /dev/null +++ b/test/spec/modules/emx_digitalBidAdapter_spec.js @@ -0,0 +1,339 @@ +import { expect } from 'chai'; +import { spec } from 'modules/emx_digitalBidAdapter'; +import * as utils from 'src/utils'; +import { newBidder } from 'src/adapters/bidderFactory'; + +describe('emx_digital Adapter', function () { + const adapter = newBidder(spec); + + describe('required function', function () { + it('exists and is a function', function () { + expect(adapter.callBids).to.exist.and.to.be.a('function'); + }); + }); + + describe('isBidRequestValid', function () { + let bid = { + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': '1d1a01234a475' + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should contain tagid param', function () { + expect(spec.isBidRequestValid({ + params: {} + })).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + tagid: '' + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + tagid: '123' + } + })).to.equal(true); + }); + }); + + describe('buildRequests', function () { + const bidRequests = [{ + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' + },{ + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' + }]; + let bidderRequest = { + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + }; + bidderRequest.bids = bidRequests + + let request = spec.buildRequests(bidRequests, bidderRequest); + + it('sends bid request to ENDPOINT via POST', function () { + expect(request.method).to.equal('POST'); + }); + + it('contains the correct options', function () { + expect(request.options.withCredentials).to.equal(true); + }); + + it('sends contains a properly formatted endpoint url', function () { + const url = request.url.split('?'); + const queryParams = url[1].split('&'); + expect(queryParams[0]).to.match(new RegExp('^t=\d*', 'g')); + expect(queryParams[1]).to.match(new RegExp('^ts=\d*', 'g')); + }); + + it('builds request properly', function () { + const data = JSON.parse(request.data); + + expect(Array.isArray(data.imp)).to.equal(true); + expect(data.id).to.equal(bidderRequest.auctionId); + expect(data.imp.length).to.equal(2); + expect(data.imp[0].id).to.equal('30b31c2501de1e'); + expect(data.imp[0].tid).to.equal('d7b773de-ceaa-484d-89ca-d9f51b8d61ec'); + expect(data.imp[0].tagid).to.equal('25251'); + expect(data.imp[0].secure).to.equal(0); + }); + + it('builds with bid floor', function() { + const bidRequestWithBidFloor = utils.deepClone(bidRequests); + bidRequestWithBidFloor[0].params.bidfloor = 1; + const requestWithFloor = spec.buildRequests(bidRequestWithBidFloor, bidderRequest); + const data = JSON.parse(requestWithFloor.data); + expect(data.imp[0].bidfloor).to.equal(bidRequestWithBidFloor[0].params.bidfloor); + }) + + it('properly sends site information and protocol', function () { + let mock = sinon.stub(utils, 'getTopWindowLocation').callsFake(() => { + return { + protocol: 'https:', + host: 'example.com', + href: 'https://example.com/index.html' + }; + }); + + let request; + + request = spec.buildRequests(bidRequests, bidderRequest); + request = JSON.parse(request.data); + expect(request.site.domain).to.equal('example.com'); + expect(request.site.page).to.equal('https://example.com/index.html'); + expect(request.imp[0].secure).to.equal(1); + + mock.restore(); + }) + + it('builds correctly formatted request banner object', function () { + let request; + + let bidRequestWithBanner = utils.deepClone(bidRequests); + + request = spec.buildRequests(bidRequestWithBanner, bidderRequest); + const data = JSON.parse(request.data); + expect(data.imp[0].banner.w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][0]); + expect(data.imp[0].banner.h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][1]); + expect(data.imp[0].banner.format[0].w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][0]); + expect(data.imp[0].banner.format[0].h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][1]); + expect(data.imp[0].banner.format[1].w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[1][0]); + expect(data.imp[0].banner.format[1].h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[1][1]); + }) + + it('shouldn\'t contain a user obj without GDPR information', function () { + let request = spec.buildRequests(bidRequests, bidderRequest) + request = JSON.parse(request.data) + expect(request).to.not.have.property('user'); + }); + + it('should have the right gdpr info when enabled', function () { + let consentString = 'OIJSZsOAFsABAB8EMXZZZZZ+A=='; + let bidderRequest = { + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true + } + }; + bidderRequest.bids = bidRequests + let request = spec.buildRequests(bidRequests, bidderRequest); + + request = JSON.parse(request.data) + expect(request.regs.ext).to.have.property('gdpr', 1); + expect(request.user.ext).to.have.property('consent', 'OIJSZsOAFsABAB8EMXZZZZZ+A=='); + }); + + it('should\'t contain consent string if gdpr isn\'t applied', function () { + let bidderRequest = { + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + 'gdprConsent': { + 'gdprApplies': false + } + }; + bidderRequest.bids = bidRequests + let request = spec.buildRequests(bidRequests, bidderRequest); + + request = JSON.parse(request.data) + expect(request.regs.ext).to.have.property('gdpr', 0); + expect(request).to.not.have.property('user'); + }); + }); + + describe('interpretResponse', function () { + const serverResponse = { + 'id': '12819a18-56e1-4256-b836-b69a10202668', + 'seatbid': [{ + 'bid': [{ + 'adid': '123456abcde', + 'adm': '', + 'crid': '3434abab34', + 'h': 250, + 'id': '987654321cba', + 'price': 0.5, + 'ttl': 300, + 'w': 300 + }], + 'seat': '1356' + },{ + 'bid': [{ + 'adid': '123456abcdf', + 'adm': '', + 'crid': '3434abab35', + 'h': 600, + 'id': '987654321cba', + 'price': 0.5, + 'ttl': 300, + 'w': 300 + }] + }] + }; + + const expectedResponse = [{ + 'requestId': '12819a18-56e1-4256-b836-b69a10202668', + 'cpm': 0.5, + 'width': 300, + 'height': 250, + 'creativeId': '3434abab34', + 'dealId': null, + 'currency': 'USD', + 'netRevneue': true, + 'mediaType': 'banner', + 'ad': '', + 'ttl': 300 + },{ + 'requestId': '12819a18-56e1-4256-b836-b69a10202668', + 'cpm': 0.7, + 'width': 300, + 'height': 600, + 'creativeId': '3434abab35', + 'dealId': null, + 'currency': 'USD', + 'netRevneue': true, + 'mediaType': 'banner', + 'ad': '', + 'ttl': 300 + }]; + + it('should properly format bid response', function () { + let result = spec.interpretResponse({ + body: serverResponse + }); + expect(Object.keys(result[0]).length).to.equal(Object.keys(expectedResponse[0]).length); + expect(Object.keys(result[0]).requestId).to.equal(Object.keys(expectedResponse[0]).requestId); + expect(Object.keys(result[0]).bidderCode).to.equal(Object.keys(expectedResponse[0]).bidderCode); + expect(Object.keys(result[0]).cpm).to.equal(Object.keys(expectedResponse[0]).cpm); + expect(Object.keys(result[0]).creativeId).to.equal(Object.keys(expectedResponse[0]).creativeId); + expect(Object.keys(result[0]).width).to.equal(Object.keys(expectedResponse[0]).width); + expect(Object.keys(result[0]).height).to.equal(Object.keys(expectedResponse[0]).height); + expect(Object.keys(result[0]).ttl).to.equal(Object.keys(expectedResponse[0]).ttl); + expect(Object.keys(result[0]).adId).to.equal(Object.keys(expectedResponse[0]).adId); + expect(Object.keys(result[0]).currency).to.equal(Object.keys(expectedResponse[0]).currency); + expect(Object.keys(result[0]).netRevenue).to.equal(Object.keys(expectedResponse[0]).netRevenue); + expect(Object.keys(result[0]).ad).to.equal(Object.keys(expectedResponse[0]).ad); + }); + + it('should return multiple bids', function () { + let result = spec.interpretResponse({ + body: serverResponse + }); + expect(Array.isArray(result.seatbid)) + + const ad0 = result[0]; + const ad1 = result[1]; + expect(ad0.ad).to.equal(serverResponse.seatbid[0].bid[0].adm); + expect(ad0.cpm).to.equal(serverResponse.seatbid[0].bid[0].price); + expect(ad0.creativeId).to.equal(serverResponse.seatbid[0].bid[0].crid); + expect(ad0.currency).to.equal('USD'); + expect(ad0.height).to.equal(serverResponse.seatbid[0].bid[0].h); + expect(ad0.mediaType).to.equal('banner'); + expect(ad0.netRevenue).to.equal(true); + expect(ad0.requestId).to.equal(serverResponse.seatbid[0].bid[0].id); + expect(ad0.ttl).to.equal(300); + expect(ad0.width).to.equal(serverResponse.seatbid[0].bid[0].w); + + expect(ad1.ad).to.equal(serverResponse.seatbid[1].bid[0].adm); + expect(ad1.cpm).to.equal(serverResponse.seatbid[1].bid[0].price); + expect(ad1.creativeId).to.equal(serverResponse.seatbid[1].bid[0].crid); + expect(ad1.currency).to.equal('USD'); + expect(ad1.height).to.equal(serverResponse.seatbid[1].bid[0].h); + expect(ad1.mediaType).to.equal('banner'); + expect(ad1.netRevenue).to.equal(true); + expect(ad1.requestId).to.equal(serverResponse.seatbid[1].bid[0].id); + expect(ad1.ttl).to.equal(300); + expect(ad1.width).to.equal(serverResponse.seatbid[1].bid[0].w); + + }); + + it('handles nobid responses', function () { + let serverResponse = { + 'bids': [] + }; + + let result = spec.interpretResponse({ + body: serverResponse + }); + expect(result.length).to.equal(0); + }); + }); +}); From bf262ed7c662ebfd0cedfcf5476b72e1b2522054 Mon Sep 17 00:00:00 2001 From: Dan Bogdan Date: Thu, 18 Oct 2018 16:23:17 -0400 Subject: [PATCH 4/4] fixed linting on test spec js --- .../modules/emx_digitalBidAdapter_spec.js | 131 +++++++++--------- 1 file changed, 65 insertions(+), 66 deletions(-) diff --git a/test/spec/modules/emx_digitalBidAdapter_spec.js b/test/spec/modules/emx_digitalBidAdapter_spec.js index 944d87d1f96..dd34582e22d 100644 --- a/test/spec/modules/emx_digitalBidAdapter_spec.js +++ b/test/spec/modules/emx_digitalBidAdapter_spec.js @@ -51,55 +51,55 @@ describe('emx_digital Adapter', function () { describe('buildRequests', function () { const bidRequests = [{ - 'bidder': 'emx_digital', - 'params': { - 'tagid': '25251' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250], - [300, 600] - ] - } - }, - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' - },{ - 'bidder': 'emx_digital', - 'params': { - 'tagid': '25251' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250], - [300, 600] - ] - } - }, + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'mediaTypes': { + 'banner': { 'sizes': [ [300, 250], [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' - }]; + ] + } + }, + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' + }, { + 'bidder': 'emx_digital', + 'params': { + 'tagid': '25251' + }, + 'adUnitCode': 'adunit-code', + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + 'sizes': [ + [300, 250], + [300, 600] + ], + 'bidId': '30b31c2501de1e', + 'bidderRequestId': '22edbae3120bf6', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec' + }]; let bidderRequest = { - 'bidderCode': 'emx_digital', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'bidderRequestId': '22edbae3120bf6', - 'timeout': 1500, + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, }; bidderRequest.bids = bidRequests @@ -184,14 +184,14 @@ describe('emx_digital Adapter', function () { it('should have the right gdpr info when enabled', function () { let consentString = 'OIJSZsOAFsABAB8EMXZZZZZ+A=='; let bidderRequest = { - 'bidderCode': 'emx_digital', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'bidderRequestId': '22edbae3120bf6', - 'timeout': 1500, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true - } + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true + } }; bidderRequest.bids = bidRequests let request = spec.buildRequests(bidRequests, bidderRequest); @@ -203,17 +203,17 @@ describe('emx_digital Adapter', function () { it('should\'t contain consent string if gdpr isn\'t applied', function () { let bidderRequest = { - 'bidderCode': 'emx_digital', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'bidderRequestId': '22edbae3120bf6', - 'timeout': 1500, - 'gdprConsent': { - 'gdprApplies': false - } + 'bidderCode': 'emx_digital', + 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', + 'bidderRequestId': '22edbae3120bf6', + 'timeout': 1500, + 'gdprConsent': { + 'gdprApplies': false + } }; bidderRequest.bids = bidRequests let request = spec.buildRequests(bidRequests, bidderRequest); - + request = JSON.parse(request.data) expect(request.regs.ext).to.have.property('gdpr', 0); expect(request).to.not.have.property('user'); @@ -235,7 +235,7 @@ describe('emx_digital Adapter', function () { 'w': 300 }], 'seat': '1356' - },{ + }, { 'bid': [{ 'adid': '123456abcdf', 'adm': '', @@ -261,7 +261,7 @@ describe('emx_digital Adapter', function () { 'mediaType': 'banner', 'ad': '', 'ttl': 300 - },{ + }, { 'requestId': '12819a18-56e1-4256-b836-b69a10202668', 'cpm': 0.7, 'width': 300, @@ -298,7 +298,7 @@ describe('emx_digital Adapter', function () { body: serverResponse }); expect(Array.isArray(result.seatbid)) - + const ad0 = result[0]; const ad1 = result[1]; expect(ad0.ad).to.equal(serverResponse.seatbid[0].bid[0].adm); @@ -311,7 +311,7 @@ describe('emx_digital Adapter', function () { expect(ad0.requestId).to.equal(serverResponse.seatbid[0].bid[0].id); expect(ad0.ttl).to.equal(300); expect(ad0.width).to.equal(serverResponse.seatbid[0].bid[0].w); - + expect(ad1.ad).to.equal(serverResponse.seatbid[1].bid[0].adm); expect(ad1.cpm).to.equal(serverResponse.seatbid[1].bid[0].price); expect(ad1.creativeId).to.equal(serverResponse.seatbid[1].bid[0].crid); @@ -322,7 +322,6 @@ describe('emx_digital Adapter', function () { expect(ad1.requestId).to.equal(serverResponse.seatbid[1].bid[0].id); expect(ad1.ttl).to.equal(300); expect(ad1.width).to.equal(serverResponse.seatbid[1].bid[0].w); - }); it('handles nobid responses', function () {