From a7c070920e148bc214fe209367de2896b0dd5b09 Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Thu, 27 Jul 2017 17:34:07 +0100 Subject: [PATCH 1/7] Added PolluxNetwork Bid Adapter Added module, test spec and integration example for Pollux Network Bid Adapter --- integrationExamples/pollux/zone_728x90.html | 105 ++++++++++++++++++++ modules/polluxBidAdapter.js | 105 ++++++++++++++++++++ test/spec/modules/polluxBidAdapter_spec.js | 39 ++++++++ 3 files changed, 249 insertions(+) create mode 100644 integrationExamples/pollux/zone_728x90.html create mode 100644 modules/polluxBidAdapter.js create mode 100644 test/spec/modules/polluxBidAdapter_spec.js diff --git a/integrationExamples/pollux/zone_728x90.html b/integrationExamples/pollux/zone_728x90.html new file mode 100644 index 00000000000..023cd033319 --- /dev/null +++ b/integrationExamples/pollux/zone_728x90.html @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + test + + + +
+ +
+ + \ No newline at end of file diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js new file mode 100644 index 00000000000..2e67ce11234 --- /dev/null +++ b/modules/polluxBidAdapter.js @@ -0,0 +1,105 @@ +import bidfactory from 'src/bidfactory'; +import bidmanager from 'src/bidmanager'; +import * as utils from 'src/utils'; +import adloader from 'src/adloader'; +import adaptermanager from 'src/adaptermanager'; +import { STATUS } from 'src/constants'; + +// get parameters +var getParameterByName = function (name) { + var regexS = '[\\?&]' + name + '=([^&#]*)'; + var regex = new RegExp(regexS); + var results = regex.exec(window.location.search); + if (results === null) { + return ''; + } + return decodeURIComponent(results[1].replace(/\+/g, ' ')); +}; +// Prebid adapter for Pollux header bidding client +function polluxBidAdapter() { + function _callBids(params) { + var bids, bidderUrl = (window.location.protocol) + '//adn.polluxnetwork.com/prebid'; + bids = params.bids || []; + for (var i = 0; i < bids.length; i++) { + var request_obj = {}; + var bid = bids[i]; + // check params + if (bid.params.zone) { + var domain = getParameterByName('domain'); + var tracker2 = getParameterByName('tracker2'); + if (domain) { + request_obj.domain = domain; + } else { + request_obj.domain = window.location.host; + } + if (tracker2) { + request_obj.tracker2 = tracker2; + } + request_obj.zone = bid.params.zone; + } else { + utils.logError('required param "zone" is missing', 'polluxHandler'); + continue; + } + var parsedSizes = utils.parseSizesInput(bid.sizes); + var parsedSizesLength = parsedSizes.length; + if (parsedSizesLength > 0) { + // first value should be "size" + request_obj.size = parsedSizes[0]; + if (parsedSizesLength > 1) { + // any subsequent values should be "promo_sizes" + var promo_sizes = []; + for (var j = 1; j < parsedSizesLength; j++) { + promo_sizes.push(parsedSizes[j]); + } + request_obj.promo_sizes = promo_sizes.join(','); + } + } + // detect urls + request_obj.callback_id = bid.bidId; + // set a different url bidder + if (bid.bidderUrl) { + bidderUrl = bid.bidderUrl; + } + var prebidUrl = bidderUrl + '?' + utils.parseQueryStringParameters(request_obj); + utils.logMessage('Pollux request built: ' + prebidUrl); + adloader.loadScript(prebidUrl, null, true); + } + } + + // expose the callback to global object + $$PREBID_GLOBAL$$.polluxHandler = function (response) { + // pollux handler + var bidObject = {}; + var callback_id = response.callback_id; + var placementCode = ''; + var bidObj = utils.getBidRequest(callback_id); + if (bidObj) { + placementCode = bidObj.placementCode; + } + if (bidObj && response.cpm > 0 && !!response.ad) { + bidObject = bidfactory.createBid(STATUS.GOOD); + bidObject.bidderCode = bidObj.bidder; + bidObject.mediaType = response.mediaType; + bidObject.cpm = parseFloat(response.cpm); + if (response.ad_type === 'url') { + bidObject.adUrl = response.ad; + } else { + bidObject.ad = response.ad; + } + bidObject.width = response.width; + bidObject.height = response.height; + } else { + bidObject = bidfactory.createBid(STATUS.NO_BID); + bidObject.bidderCode = 'pollux'; + utils.logMessage('No prebid response from polluxHandler for placement code ' + placementCode); + } + bidmanager.addBidResponse(placementCode, bidObject); + }; + // Export the `callBids` function, so that Prebid.js can execute + // this function when the page asks to send out bid requests. + return { + callBids: _callBids + }; +}; +adaptermanager.registerBidAdapter(new polluxBidAdapter(), 'pollux'); +module.exports = polluxBidAdapter; diff --git a/test/spec/modules/polluxBidAdapter_spec.js b/test/spec/modules/polluxBidAdapter_spec.js new file mode 100644 index 00000000000..51a8ede2d6c --- /dev/null +++ b/test/spec/modules/polluxBidAdapter_spec.js @@ -0,0 +1,39 @@ +import {expect} from 'chai'; +import Adapter from '../../../modules/polluxBidAdapter'; +import bidManager from '../../../src/bidmanager'; +import adLoader from '../../../src/adloader'; + +describe('Pollux Adapter', () => { + let adapter; + + const REQUEST = { + 'bidderCode': 'pollux', + 'requestId': 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6', + 'bidderRequestId': '7101db09af0db2', + 'bids': [ + { + 'bidder': 'pollux', + 'bidderUrl': '//adn-dev.polluxnetwork.com/prebid', + 'params': { + 'zone': '123' + }, + 'code': 'div-gpt-ad-1460505661639-0', + 'sizes': [[728, 90]], + 'bidId': '84ab500420319d', + 'bidderRequestId': '7101db09af0db2', + 'requestId': 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6' + } + ], + 'start': 1469479810130 + }; + + sinon.stub(bidManager, 'addBidResponse'); + const adLoaderStub = sinon.stub(adLoader, 'loadScript'); + + describe('callBids', () => { + adapter = new Adapter(); + adapter.callBids(REQUEST); + expect(adLoaderStub.getCall(0).args[0]).to.contain('zone=123'); + expect(adLoaderStub.getCall(0).args[0]).to.contain('domain='); + }); +}); From a6000c562abe463568fee3b4a7287eeca3e1b8af Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Fri, 28 Jul 2017 09:56:34 +0100 Subject: [PATCH 2/7] Update Pollux domain Update Pollux default domain on prebid adapter --- modules/polluxBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js index 2e67ce11234..2972bd597dd 100644 --- a/modules/polluxBidAdapter.js +++ b/modules/polluxBidAdapter.js @@ -18,7 +18,7 @@ var getParameterByName = function (name) { // Prebid adapter for Pollux header bidding client function polluxBidAdapter() { function _callBids(params) { - var bids, bidderUrl = (window.location.protocol) + '//adn.polluxnetwork.com/prebid'; + var bids, bidderUrl = (window.location.protocol) + '//adn.plxnt.com/prebid'; bids = params.bids || []; for (var i = 0; i < bids.length; i++) { var request_obj = {}; From 52e1dc83ffb0ccd8ac809dd1ac1d7d32749fc022 Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Fri, 28 Jul 2017 11:54:44 +0100 Subject: [PATCH 3/7] Export getParameterByName method On Utils.js make getParameterByName method public --- modules/polluxBidAdapter.js | 14 ++------------ src/utils.js | 1 + 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js index 2972bd597dd..bbc70122693 100644 --- a/modules/polluxBidAdapter.js +++ b/modules/polluxBidAdapter.js @@ -5,16 +5,6 @@ import adloader from 'src/adloader'; import adaptermanager from 'src/adaptermanager'; import { STATUS } from 'src/constants'; -// get parameters -var getParameterByName = function (name) { - var regexS = '[\\?&]' + name + '=([^&#]*)'; - var regex = new RegExp(regexS); - var results = regex.exec(window.location.search); - if (results === null) { - return ''; - } - return decodeURIComponent(results[1].replace(/\+/g, ' ')); -}; // Prebid adapter for Pollux header bidding client function polluxBidAdapter() { function _callBids(params) { @@ -25,8 +15,8 @@ function polluxBidAdapter() { var bid = bids[i]; // check params if (bid.params.zone) { - var domain = getParameterByName('domain'); - var tracker2 = getParameterByName('tracker2'); + var domain = utils.getParameterByName('domain'); + var tracker2 = utils.getParameterByName('tracker2'); if (domain) { request_obj.domain = domain; } else { diff --git a/src/utils.js b/src/utils.js index 14f9c58f3dd..8ed3115cd06 100644 --- a/src/utils.js +++ b/src/utils.js @@ -266,6 +266,7 @@ var getParameterByName = function (name) { return decodeURIComponent(results[1].replace(/\+/g, ' ')); }; +exports.getParameterByName = getParameterByName; /** * This function validates paramaters. From f745fe1147433983aba725e0b176ce57d3d125af Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Fri, 4 Aug 2017 13:37:41 +0100 Subject: [PATCH 4/7] Executed changes requested by @jaiminpanchal27 on 2017-08-01 Moved zone_728x90.html to integrationExamples/gpt/pollux_zone_728x90.html; Added bidRequest as second parameter to bidfactory.createBid() on Pollux Bid Adapter; Added more test cases to increase test coverage (at least 85%); Review Ref: - https://github.com/prebid/Prebid.js/pull/1431#pullrequestreview-53608436 --- .../pollux_zone_728x90.html} | 7 +- modules/polluxBidAdapter.js | 4 +- test/spec/modules/polluxBidAdapter_spec.js | 243 +++++++++++++++--- 3 files changed, 212 insertions(+), 42 deletions(-) rename integrationExamples/{pollux/zone_728x90.html => gpt/pollux_zone_728x90.html} (95%) diff --git a/integrationExamples/pollux/zone_728x90.html b/integrationExamples/gpt/pollux_zone_728x90.html similarity index 95% rename from integrationExamples/pollux/zone_728x90.html rename to integrationExamples/gpt/pollux_zone_728x90.html index 023cd033319..ecede9b5db2 100644 --- a/integrationExamples/pollux/zone_728x90.html +++ b/integrationExamples/gpt/pollux_zone_728x90.html @@ -11,16 +11,15 @@ sizes: [[728, 90]], bids: [ { - bidder: 'appnexus', + bidder: 'pollux', params: { - placementId: '4799418' + zone: '276' } }, { bidder: 'pollux', - bidderUrl: '//adn.plxnt.com/prebid', params: { - zone: '276' + zone: '1806' } } ] diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js index bbc70122693..ebf83380298 100644 --- a/modules/polluxBidAdapter.js +++ b/modules/polluxBidAdapter.js @@ -67,7 +67,7 @@ function polluxBidAdapter() { placementCode = bidObj.placementCode; } if (bidObj && response.cpm > 0 && !!response.ad) { - bidObject = bidfactory.createBid(STATUS.GOOD); + bidObject = bidfactory.createBid(STATUS.GOOD, bidObj); bidObject.bidderCode = bidObj.bidder; bidObject.mediaType = response.mediaType; bidObject.cpm = parseFloat(response.cpm); @@ -79,7 +79,7 @@ function polluxBidAdapter() { bidObject.width = response.width; bidObject.height = response.height; } else { - bidObject = bidfactory.createBid(STATUS.NO_BID); + bidObject = bidfactory.createBid(STATUS.NO_BID, bidObj); bidObject.bidderCode = 'pollux'; utils.logMessage('No prebid response from polluxHandler for placement code ' + placementCode); } diff --git a/test/spec/modules/polluxBidAdapter_spec.js b/test/spec/modules/polluxBidAdapter_spec.js index 51a8ede2d6c..1ac7c79e181 100644 --- a/test/spec/modules/polluxBidAdapter_spec.js +++ b/test/spec/modules/polluxBidAdapter_spec.js @@ -1,39 +1,210 @@ -import {expect} from 'chai'; -import Adapter from '../../../modules/polluxBidAdapter'; -import bidManager from '../../../src/bidmanager'; -import adLoader from '../../../src/adloader'; - -describe('Pollux Adapter', () => { - let adapter; - - const REQUEST = { - 'bidderCode': 'pollux', - 'requestId': 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6', - 'bidderRequestId': '7101db09af0db2', - 'bids': [ - { - 'bidder': 'pollux', - 'bidderUrl': '//adn-dev.polluxnetwork.com/prebid', - 'params': { - 'zone': '123' - }, - 'code': 'div-gpt-ad-1460505661639-0', - 'sizes': [[728, 90]], - 'bidId': '84ab500420319d', - 'bidderRequestId': '7101db09af0db2', - 'requestId': 'd3e07445-ab06-44c8-a9dd-5ef9af06d2a6' +describe('Pollux Bid Adapter tests', function () { + var expect = require('chai').expect; + var urlParse = require('url-parse'); + var querystringify = require('querystringify'); + var adapter = require('modules/polluxBidAdapter'); + var adLoader = require('src/adloader'); + var bidmanager = require('src/bidmanager'); + + var stubLoadScript; + + beforeEach(function () { + stubLoadScript = sinon.stub(adLoader, 'loadScript'); + }); + + afterEach(function () { + stubLoadScript.restore(); + }); + + describe('creation of bid url', function () { + if (typeof ($$PREBID_GLOBAL$$._bidsReceived) === 'undefined') { + $$PREBID_GLOBAL$$._bidsReceived = []; + } + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = []; + } + + it('bid request for single placement', function () { + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + bidId: '21fe992ca48d55', + bidder: 'pollux', + sizes: [[300, 250]], + params: { zone: '1806' } + }] + }; + + adapter().callBids(params); + + var bidUrl = stubLoadScript.getCall(0).args[0]; + + sinon.assert.calledOnce(stubLoadScript); + + var parsedBidUrl = urlParse(bidUrl); + var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); + + expect(parsedBidUrlQueryString).to.have.property('zone').and.to.equal('1806'); + expect(parsedBidUrlQueryString).to.have.property('domain').and.to.have.length.above(1); + }); + }); + + describe('handling bid response', function () { + it('should return complete bid response adUrl', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + sizes: [[300, 250]], + bidId: '21fe992ca48d55', + bidder: 'pollux', + params: { zone: '1806' } + }] + }; + + var response = { + cpm: 0.5, + width: 300, + height: 250, + callback_id: '21fe992ca48d55', + ad: 'some.ad.url', + ad_type: 'url', + zone: 1806 + }; + + adapter().callBids(params); + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = 'div-gpt-ad-1460505661639-0'; + unit.sizes = [[300, 250]]; + adUnits.push(unit); + + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = [params]; + } else { + $$PREBID_GLOBAL$$._bidsRequested.push(params); } - ], - 'start': 1469479810130 - }; - - sinon.stub(bidManager, 'addBidResponse'); - const adLoaderStub = sinon.stub(adLoader, 'loadScript'); - - describe('callBids', () => { - adapter = new Adapter(); - adapter.callBids(REQUEST); - expect(adLoaderStub.getCall(0).args[0]).to.contain('zone=123'); - expect(adLoaderStub.getCall(0).args[0]).to.contain('domain='); + + $$PREBID_GLOBAL$$.adUnits = adUnits; + + $$PREBID_GLOBAL$$.polluxHandler(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal('div-gpt-ad-1460505661639-0'); + expect(bidObject1.bidderCode).to.equal('pollux'); + expect(bidObject1.cpm).to.equal(0.5); + expect(bidObject1.width).to.equal(300); + expect(bidObject1.height).to.equal(250); + expect(bidObject1.adUrl).to.have.length.above(1); + + stubAddBidResponse.restore(); + }); + + it('should return complete bid response ad (html)', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + sizes: [[300, 250]], + bidId: '21fe992ca48d55', + bidder: 'pollux', + params: { zone: '1806' } + }] + }; + + var response = { + cpm: 0.5, + width: 300, + height: 250, + callback_id: '21fe992ca48d55', + ad: '', + ad_type: 'html', + zone: 1806 + }; + + adapter().callBids(params); + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = 'div-gpt-ad-1460505661639-0'; + unit.sizes = [[300, 250]]; + adUnits.push(unit); + + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = [params]; + } else { + $$PREBID_GLOBAL$$._bidsRequested.push(params); + } + + $$PREBID_GLOBAL$$.adUnits = adUnits; + + $$PREBID_GLOBAL$$.polluxHandler(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal('div-gpt-ad-1460505661639-0'); + expect(bidObject1.bidderCode).to.equal('pollux'); + expect(bidObject1.cpm).to.equal(0.5); + expect(bidObject1.width).to.equal(300); + expect(bidObject1.height).to.equal(250); + expect(bidObject1.ad).to.have.length.above(1); + + stubAddBidResponse.restore(); + }); + + it('should return no bid response', function() { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bids: [{ + placementCode: 'div-gpt-ad-1460505661639-0', + sizes: [[300, 250]], + bidId: '21fe992ca48d55', + bidder: 'pollux', + params: { zone: '276' } + }] + }; + + var response = { + cpm: null, + width: null, + height: null, + callback_id: null, + ad: null, + zone: null + }; + + adapter().callBids(params); + + var adUnits = []; + var unit = {}; + unit.bids = params.bids; + unit.code = 'div-gpt-ad-1460505661639-0'; + unit.sizes = [[300, 250]]; + adUnits.push(unit); + + if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { + $$PREBID_GLOBAL$$._bidsRequested = [params]; + } else { + $$PREBID_GLOBAL$$._bidsRequested.push(params); + } + + $$PREBID_GLOBAL$$.adUnits = adUnits; + + $$PREBID_GLOBAL$$.polluxHandler(response); + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal(''); + expect(bidObject1.bidderCode).to.equal('pollux'); + + stubAddBidResponse.restore(); + }); }); }); From 33c5edeb651378098dccb5a186609a869e78ec92 Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Fri, 4 Aug 2017 17:33:09 +0100 Subject: [PATCH 5/7] Fixed Eslint errors on commit f745fe1 --- modules/polluxBidAdapter.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js index ebf83380298..60ee958fae3 100644 --- a/modules/polluxBidAdapter.js +++ b/modules/polluxBidAdapter.js @@ -6,10 +6,10 @@ import adaptermanager from 'src/adaptermanager'; import { STATUS } from 'src/constants'; // Prebid adapter for Pollux header bidding client -function polluxBidAdapter() { +function PolluxBidAdapter() { function _callBids(params) { - var bids, bidderUrl = (window.location.protocol) + '//adn.plxnt.com/prebid'; - bids = params.bids || []; + var bidderUrl = (window.location.protocol) + '//adn.plxnt.com/prebid'; + var bids = params.bids || []; for (var i = 0; i < bids.length; i++) { var request_obj = {}; var bid = bids[i]; @@ -91,5 +91,5 @@ function polluxBidAdapter() { callBids: _callBids }; }; -adaptermanager.registerBidAdapter(new polluxBidAdapter(), 'pollux'); -module.exports = polluxBidAdapter; +adaptermanager.registerBidAdapter(new PolluxBidAdapter(), 'pollux'); +module.exports = PolluxBidAdapter; From 34131a670a5f117d29c0fbd8db52ad515555a9b6 Mon Sep 17 00:00:00 2001 From: hdjvieira Date: Thu, 10 Aug 2017 12:12:56 +0100 Subject: [PATCH 6/7] Executed changes requested on PR#1431 review #54993573 - Removed $$PREBID_GLOBAL$$ public vars in unit test; - Moved stubs creation and its restoration to beforeEach and afterEach hooks in unit test; - Exposed polluxHandler method on polluxBidAdapter. --- modules/polluxBidAdapter.js | 6 +- test/spec/modules/polluxBidAdapter_spec.js | 100 +++++++-------------- 2 files changed, 35 insertions(+), 71 deletions(-) diff --git a/modules/polluxBidAdapter.js b/modules/polluxBidAdapter.js index 60ee958fae3..54c2122ec36 100644 --- a/modules/polluxBidAdapter.js +++ b/modules/polluxBidAdapter.js @@ -57,7 +57,7 @@ function PolluxBidAdapter() { } // expose the callback to global object - $$PREBID_GLOBAL$$.polluxHandler = function (response) { + function _polluxHandler (response) { // pollux handler var bidObject = {}; var callback_id = response.callback_id; @@ -85,10 +85,12 @@ function PolluxBidAdapter() { } bidmanager.addBidResponse(placementCode, bidObject); }; + $$PREBID_GLOBAL$$.polluxHandler = _polluxHandler; // Export the `callBids` function, so that Prebid.js can execute // this function when the page asks to send out bid requests. return { - callBids: _callBids + callBids: _callBids, + polluxHandler: _polluxHandler }; }; adaptermanager.registerBidAdapter(new PolluxBidAdapter(), 'pollux'); diff --git a/test/spec/modules/polluxBidAdapter_spec.js b/test/spec/modules/polluxBidAdapter_spec.js index 1ac7c79e181..1bcfe28124d 100644 --- a/test/spec/modules/polluxBidAdapter_spec.js +++ b/test/spec/modules/polluxBidAdapter_spec.js @@ -2,30 +2,37 @@ describe('Pollux Bid Adapter tests', function () { var expect = require('chai').expect; var urlParse = require('url-parse'); var querystringify = require('querystringify'); - var adapter = require('modules/polluxBidAdapter'); + var Adapter = require('modules/polluxBidAdapter'); var adLoader = require('src/adloader'); var bidmanager = require('src/bidmanager'); + var utils = require('src/utils'); var stubLoadScript; + var stubAddBidResponse; + var polluxAdapter; + + // mock golbal _bidsRequested var + var bidsRequested = []; + utils.getBidRequest = function (id) { + return bidsRequested.map(bidSet => bidSet.bids.find(bid => bid.bidId === id)).find(bid => bid); + }; beforeEach(function () { + polluxAdapter = new Adapter(); + bidsRequested = []; stubLoadScript = sinon.stub(adLoader, 'loadScript'); + stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); }); afterEach(function () { stubLoadScript.restore(); + stubAddBidResponse.restore(); }); describe('creation of bid url', function () { - if (typeof ($$PREBID_GLOBAL$$._bidsReceived) === 'undefined') { - $$PREBID_GLOBAL$$._bidsReceived = []; - } - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = []; - } - it('bid request for single placement', function () { var params = { + bidderCode: 'pollux', bids: [{ placementCode: 'div-gpt-ad-1460505661639-0', bidId: '21fe992ca48d55', @@ -35,7 +42,7 @@ describe('Pollux Bid Adapter tests', function () { }] }; - adapter().callBids(params); + polluxAdapter.callBids(params); var bidUrl = stubLoadScript.getCall(0).args[0]; @@ -51,9 +58,8 @@ describe('Pollux Bid Adapter tests', function () { describe('handling bid response', function () { it('should return complete bid response adUrl', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - var params = { + bidderCode: 'pollux', bids: [{ placementCode: 'div-gpt-ad-1460505661639-0', sizes: [[300, 250]], @@ -73,23 +79,11 @@ describe('Pollux Bid Adapter tests', function () { zone: 1806 }; - adapter().callBids(params); - var adUnits = []; - var unit = {}; - unit.bids = params.bids; - unit.code = 'div-gpt-ad-1460505661639-0'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); - - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } + polluxAdapter.callBids(params); + bidsRequested.push(params); + polluxAdapter.polluxHandler(response); - $$PREBID_GLOBAL$$.adUnits = adUnits; - - $$PREBID_GLOBAL$$.polluxHandler(response); + sinon.assert.calledOnce(stubAddBidResponse); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -100,14 +94,11 @@ describe('Pollux Bid Adapter tests', function () { expect(bidObject1.width).to.equal(300); expect(bidObject1.height).to.equal(250); expect(bidObject1.adUrl).to.have.length.above(1); - - stubAddBidResponse.restore(); }); it('should return complete bid response ad (html)', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - var params = { + bidderCode: 'pollux', bids: [{ placementCode: 'div-gpt-ad-1460505661639-0', sizes: [[300, 250]], @@ -127,23 +118,11 @@ describe('Pollux Bid Adapter tests', function () { zone: 1806 }; - adapter().callBids(params); - var adUnits = []; - var unit = {}; - unit.bids = params.bids; - unit.code = 'div-gpt-ad-1460505661639-0'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + polluxAdapter.callBids(params); + bidsRequested.push(params); + polluxAdapter.polluxHandler(response); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } - - $$PREBID_GLOBAL$$.adUnits = adUnits; - - $$PREBID_GLOBAL$$.polluxHandler(response); + sinon.assert.calledOnce(stubAddBidResponse); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -154,14 +133,11 @@ describe('Pollux Bid Adapter tests', function () { expect(bidObject1.width).to.equal(300); expect(bidObject1.height).to.equal(250); expect(bidObject1.ad).to.have.length.above(1); - - stubAddBidResponse.restore(); }); it('should return no bid response', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - var params = { + bidderCode: 'pollux', bids: [{ placementCode: 'div-gpt-ad-1460505661639-0', sizes: [[300, 250]], @@ -180,31 +156,17 @@ describe('Pollux Bid Adapter tests', function () { zone: null }; - adapter().callBids(params); + polluxAdapter.callBids(params); + bidsRequested.push(params); + polluxAdapter.polluxHandler(response); - var adUnits = []; - var unit = {}; - unit.bids = params.bids; - unit.code = 'div-gpt-ad-1460505661639-0'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + sinon.assert.calledOnce(stubAddBidResponse); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } - - $$PREBID_GLOBAL$$.adUnits = adUnits; - - $$PREBID_GLOBAL$$.polluxHandler(response); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; expect(bidPlacementCode1).to.equal(''); expect(bidObject1.bidderCode).to.equal('pollux'); - - stubAddBidResponse.restore(); }); }); }); From 1d3ef09e176dbcc16ffaffc9db067a11940261fb Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Tue, 15 Aug 2017 09:53:27 -0700 Subject: [PATCH 7/7] Remove redundant export This line was added in #1409, removing this then I'll merge --- src/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index e03da246747..2b438ff46f2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -264,7 +264,6 @@ var getParameterByName = function (name) { return decodeURIComponent(results[1].replace(/\+/g, ' ')); }; -exports.getParameterByName = getParameterByName; exports.getParameterByName = getParameterByName;