From 771b74ca2cf74db2845b223742a7e329d2882c63 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Fri, 14 Oct 2016 14:04:22 -0700 Subject: [PATCH 1/9] Adding AdButler Adapter --- adapters.json | 1 + src/adapters/adbutler.js | 146 ++++++++++ test/spec/adapters/adbutler_spec.js | 396 ++++++++++++++++++++++++++++ 3 files changed, 543 insertions(+) create mode 100644 src/adapters/adbutler.js create mode 100644 test/spec/adapters/adbutler_spec.js diff --git a/adapters.json b/adapters.json index 7f4ded12c11..d60d8fa45c2 100644 --- a/adapters.json +++ b/adapters.json @@ -1,6 +1,7 @@ [ "aardvark", "adblade", + "adbutler", "adequant", "adform", "admedia", diff --git a/src/adapters/adbutler.js b/src/adapters/adbutler.js new file mode 100644 index 00000000000..7407fe680d2 --- /dev/null +++ b/src/adapters/adbutler.js @@ -0,0 +1,146 @@ +/** + * @overview AdButler Prebid.js adapter. + * @author dkharton + */ + +'use strict'; + +var utils = require('../utils.js'); +var adloader = require('../adloader.js'); +var bidmanager = require('../bidmanager.js'); +var bidfactory = require('../bidfactory.js'); + +var AdButlerAdapter = function AdButlerAdapter() { + + function _callBids(params) { + + var bids = params.bids || [], + callbackData = {}, + zoneCount = {}, + pageID = Math.floor(Math.random() * 10e6); + + //Build and send bid requests + for (var i = 0; i < bids.length; i++) { + var bid = bids[i], + zoneID = utils.getBidIdParamater('zoneID', bid.params), + callbackID; + + if(!(zoneID in zoneCount)){ + zoneCount[zoneID] = 0; + } + + //build callbackID to get placementCode later + callbackID = zoneID + '_' +zoneCount[zoneID]; + + callbackData[callbackID] = {}; + + callbackData[callbackID].placementCode = bid.placementCode; + callbackData[callbackID].sizes = bid.sizes; + callbackData[callbackID].maxCPM = utils.getBidIdParamater('maxCPM', bid.params); + callbackData[callbackID].minCPM = utils.getBidIdParamater('minCPM', bid.params); + + var adRequest = buildRequest(bid,zoneCount[zoneID],pageID); + zoneCount[zoneID]++; + + adloader.loadScript(adRequest); + } + + //Define callback function for bid responses + $$PREBID_GLOBAL$$.adbutlerCB = function(aBResponseObject){ + + var bidResponse = {}, + callbackID = aBResponseObject.zone_id+'_'+aBResponseObject.place, + width = parseInt(aBResponseObject.width), + height = parseInt(aBResponseObject.height), + isCorrectSize = false, + isCorrectCPM = true, + CPM,minCPM,maxCPM; + + //Ensure that response ad matches one of the placement sizes. + utils._each(callbackData[callbackID].sizes,function(size){ + if(width === size[0] && height === size[1]){ + isCorrectSize = true; + } + }); + + if (aBResponseObject.status === 'SUCCESS' && isCorrectSize) { + + CPM = aBResponseObject.cpm; + minCPM = callbackData[callbackID].minCPM; + maxCPM = callbackData[callbackID].maxCPM; + + //Ensure response CPM is within the given bounds + if(minCPM !== '' && CPM < parseFloat(minCPM)){ + isCorrectCPM = false; + } + if(maxCPM !== '' && CPM > parseFloat(maxCPM)){ + isCorrectCPM = false; + } + + if(isCorrectCPM){ + + bidResponse = bidfactory.createBid(1); + bidResponse.bidderCode = 'adbutler'; + bidResponse.cpm = CPM; + bidResponse.width = width; + bidResponse.height = height; + bidResponse.ad = aBResponseObject.ad_code; + bidResponse.ad += addTrackingPixels(aBResponseObject.tracking_pixels); + + } else { + bidResponse = bidfactory.createBid(2); + bidResponse.bidderCode = 'adbutler'; + } + + } else { + bidResponse = bidfactory.createBid(2); + bidResponse.bidderCode = 'adbutler'; + } + + bidmanager.addBidResponse(callbackData[callbackID].placementCode, bidResponse); + + }; + } + + function buildRequest(bid,adIndex,pageID){ + var accountID = utils.getBidIdParamater('accountID', bid.params); + var zoneID = utils.getBidIdParamater('zoneID', bid.params); + var keyword = utils.getBidIdParamater('keyword', bid.params); + + var requestURI = location.protocol + '//servedbyadbutler.com/adserve/;type=hbr;'; + requestURI += 'ID='+encodeURIComponent(accountID)+';'; + requestURI += 'setID='+encodeURIComponent(zoneID)+';'; + requestURI += 'pid='+encodeURIComponent(pageID)+';'; + requestURI += 'place='+encodeURIComponent(adIndex)+';'; + + //append the keyword for targeting if one was passed in + if(keyword !== ''){ + requestURI +='kw='+encodeURIComponent(keyword)+';'; + } + requestURI += 'jsonpfunc=$$PREBID_GLOBAL$$.adbutlerCB;'; + requestURI += 'click=CLICK_MACRO_PLACEHOLDER'; + + return requestURI; + } + + function addTrackingPixels(trackingPixels){ + var trackingPixelMarkup = ''; + utils._each(trackingPixels,function(pixelURL){ + + var trackingPixel = ''; + + trackingPixelMarkup += trackingPixel; + }); + return trackingPixelMarkup; + } + + // Export the callBids function, so that prebid.js can execute this function + // when the page asks to send out bid requests. + return { + callBids: _callBids + }; +}; + +module.exports = AdButlerAdapter; diff --git a/test/spec/adapters/adbutler_spec.js b/test/spec/adapters/adbutler_spec.js new file mode 100644 index 00000000000..0b176cd015d --- /dev/null +++ b/test/spec/adapters/adbutler_spec.js @@ -0,0 +1,396 @@ +describe('adbutler adapter tests', function () { + + var expect = require('chai').expect; + var adapter = require('src/adapters/adbutler'); + var adLoader = require('src/adloader'); + var bidmanager = require('src/bidmanager'); + + window.pbjs = window.pbjs || {}; + if (typeof(pbjs)==="undefined"){ + var pbjs = window.pbjs; + } + + describe('creation of bid url', function () { + + var spyLoadScript; + + beforeEach(function () { + spyLoadScript = sinon.spy(adLoader, 'loadScript'); + }); + + afterEach(function () { + spyLoadScript.restore(); + }); + + if (typeof(pbjs._bidsReceived) === "undefined") { + pbjs._bidsReceived = []; + } + if (typeof(pbjs._bidsRequested) === "undefined") { + pbjs._bidsRequested = []; + } + if (typeof(pbjs._adsReceived) === "undefined") { + pbjs._adsReceived = []; + } + + it('should be called', function () { + + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + adapter().callBids(params); + + sinon.assert.called(spyLoadScript); + + }); + + it('should populate the keyword',function(){ + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253', + keyword: 'fish' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + adapter().callBids(params); + + var requestURI = spyLoadScript.getCall(0).args[0]; + + expect(requestURI).to.have.string(';kw=fish;'); + }) + }); + describe('bid responses',function(){ + + it('should return complete bid response',function(){ + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253', + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "SUCCESS", + account_id: 167283, + zone_id: 210253, + cpm: 1.5, + width: 300, + height: 250, + place: 0 + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal('/123456/header-bid-tag-1'); + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.bidderCode).to.equal('adbutler'); + expect(bidObject1.cpm).to.equal(1.5); + expect(bidObject1.width).to.equal(300); + expect(bidObject1.height).to.equal(250); + + stubAddBidResponse.restore(); + }); + + it('should return empty bid response', function(){ + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210085', + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "NO_ELIGIBLE_ADS", + zone_id: 210085, + width: 728, + height: 90, + place: 0 + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + + expect(bidPlacementCode1).to.equal('/123456/header-bid-tag-1'); + expect(bidObject1.getStatusCode()).to.equal(2); + expect(bidObject1.bidderCode).to.equal('adbutler'); + + stubAddBidResponse.restore(); + }); + + it('should return empty bid response on incorrect size',function(){ + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210085', + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "SUCCESS", + account_id: 167283, + zone_id: 210085, + cpm: 1.5, + width: 728, + height: 90, + place: 0 + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + expect(bidObject1.getStatusCode()).to.equal(2); + + stubAddBidResponse.restore(); + }); + + it('should return empty bid response with CPM too low',function(){ + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253', + minCPM: '5.00' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "SUCCESS", + account_id: 167283, + zone_id: 210253, + cpm: 1.5, + width: 300, + height: 250, + place: 0 + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + expect(bidObject1.getStatusCode()).to.equal(2); + + stubAddBidResponse.restore(); + }); + + it('should return empty bid response with CPM too high',function(){ + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253', + maxCPM: '1.00' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "SUCCESS", + account_id: 167283, + zone_id: 210253, + cpm: 1.5, + width: 300, + height: 250, + place: 0 + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + expect(bidObject1.getStatusCode()).to.equal(2); + + stubAddBidResponse.restore(); + }); + + }); + + describe('ad code',function(){ + + it('should be populated',function(){ + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "SUCCESS", + account_id: 167283, + zone_id: 210253, + cpm: 1.5, + width: 300, + height: 250, + place: 0, + ad_code: '' + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.ad).to.have.length.above(1); + + stubAddBidResponse.restore(); + }); + + it('should contain tracking pixels',function(){ + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210253' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + + ] + }; + + var response = { + status: "SUCCESS", + account_id: 167283, + zone_id: 210253, + cpm: 1.5, + width: 300, + height: 250, + place: 0, + ad_code: '', + tracking_pixels: [ + "http://tracking.pixel.com/params=info" + ] + }; + + adapter().callBids(params); + pbjs.adbutlerCB(response); + + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.ad).to.have.string('http://tracking.pixel.com/params=info'); + + stubAddBidResponse.restore(); + }); + + }); +}); \ No newline at end of file From 45919de31dbb8328e9e94297c6b1b6a27f7a0c83 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Wed, 19 Oct 2016 15:24:05 -0700 Subject: [PATCH 2/9] Prevent AdButler TypeError Only attempt to build a bid response if we have the information of which bid to respond to. --- src/adapters/adbutler.js | 88 ++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/adapters/adbutler.js b/src/adapters/adbutler.js index 7407fe680d2..61053f14874 100644 --- a/src/adapters/adbutler.js +++ b/src/adapters/adbutler.js @@ -33,11 +33,7 @@ var AdButlerAdapter = function AdButlerAdapter() { callbackID = zoneID + '_' +zoneCount[zoneID]; callbackData[callbackID] = {}; - - callbackData[callbackID].placementCode = bid.placementCode; - callbackData[callbackID].sizes = bid.sizes; - callbackData[callbackID].maxCPM = utils.getBidIdParamater('maxCPM', bid.params); - callbackData[callbackID].minCPM = utils.getBidIdParamater('minCPM', bid.params); + callbackData[callbackID].bidId = bid.bidId; var adRequest = buildRequest(bid,zoneCount[zoneID],pageID); zoneCount[zoneID]++; @@ -54,51 +50,57 @@ var AdButlerAdapter = function AdButlerAdapter() { height = parseInt(aBResponseObject.height), isCorrectSize = false, isCorrectCPM = true, - CPM,minCPM,maxCPM; - - //Ensure that response ad matches one of the placement sizes. - utils._each(callbackData[callbackID].sizes,function(size){ - if(width === size[0] && height === size[1]){ - isCorrectSize = true; - } - }); - - if (aBResponseObject.status === 'SUCCESS' && isCorrectSize) { + CPM,minCPM,maxCPM, + bidObj = utils.getBidRequest(callbackData[callbackID].bidId); - CPM = aBResponseObject.cpm; - minCPM = callbackData[callbackID].minCPM; - maxCPM = callbackData[callbackID].maxCPM; + if (bidObj) { - //Ensure response CPM is within the given bounds - if(minCPM !== '' && CPM < parseFloat(minCPM)){ - isCorrectCPM = false; - } - if(maxCPM !== '' && CPM > parseFloat(maxCPM)){ - isCorrectCPM = false; - } - - if(isCorrectCPM){ - - bidResponse = bidfactory.createBid(1); - bidResponse.bidderCode = 'adbutler'; - bidResponse.cpm = CPM; - bidResponse.width = width; - bidResponse.height = height; - bidResponse.ad = aBResponseObject.ad_code; - bidResponse.ad += addTrackingPixels(aBResponseObject.tracking_pixels); - + if(aBResponseObject.status === 'SUCCESS'){ + CPM = aBResponseObject.cpm; + minCPM = utils.getBidIdParamater('minCPM',bidObj.params); + maxCPM = utils.getBidIdParamater('maxCPM',bidObj.params); + + //Ensure response CPM is within the given bounds + if(minCPM !== '' && CPM < parseFloat(minCPM)){ + isCorrectCPM = false; + } + if(maxCPM !== '' && CPM > parseFloat(maxCPM)){ + isCorrectCPM = false; + } + + //Ensure that response ad matches one of the placement sizes. + utils._each(bidObj.sizes,function(size){ + if(width === size[0] && height === size[1]){ + isCorrectSize = true; + } + }); + + if(isCorrectCPM && isCorrectSize){ + + bidResponse = bidfactory.createBid(1); + bidResponse.bidderCode = 'adbutler'; + bidResponse.cpm = CPM; + bidResponse.width = width; + bidResponse.height = height; + bidResponse.ad = aBResponseObject.ad_code; + bidResponse.ad += addTrackingPixels(aBResponseObject.tracking_pixels); + + } else { + + bidResponse = bidfactory.createBid(2); + bidResponse.bidderCode = 'adbutler'; + + } } else { + bidResponse = bidfactory.createBid(2); bidResponse.bidderCode = 'adbutler'; - } + + } + + bidmanager.addBidResponse(bidObj.placementCode, bidResponse); - } else { - bidResponse = bidfactory.createBid(2); - bidResponse.bidderCode = 'adbutler'; } - - bidmanager.addBidResponse(callbackData[callbackID].placementCode, bidResponse); - }; } From 5e72aac390a0ec5597b0fe188320feb3672cc6f0 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Wed, 19 Oct 2016 15:25:59 -0700 Subject: [PATCH 3/9] Refactor AdButler Testing Now stubbing adLoader instead of spying. Additional changes to ensure all tests still passed. --- test/spec/adapters/adbutler_spec.js | 171 ++++++++++++++++++++++++---- 1 file changed, 146 insertions(+), 25 deletions(-) diff --git a/test/spec/adapters/adbutler_spec.js b/test/spec/adapters/adbutler_spec.js index 0b176cd015d..465ef89bfe6 100644 --- a/test/spec/adapters/adbutler_spec.js +++ b/test/spec/adapters/adbutler_spec.js @@ -12,14 +12,14 @@ describe('adbutler adapter tests', function () { describe('creation of bid url', function () { - var spyLoadScript; + var stubLoadScript; beforeEach(function () { - spyLoadScript = sinon.spy(adLoader, 'loadScript'); + stubLoadScript = sinon.stub(adLoader, 'loadScript'); }); afterEach(function () { - spyLoadScript.restore(); + stubLoadScript.restore(); }); if (typeof(pbjs._bidsReceived) === "undefined") { @@ -43,7 +43,7 @@ describe('adbutler adapter tests', function () { bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253' + zoneID: '210093' }, requestId: '10b327aa396609', placementCode: '/123456/header-bid-tag-1' @@ -54,7 +54,7 @@ describe('adbutler adapter tests', function () { adapter().callBids(params); - sinon.assert.called(spyLoadScript); + sinon.assert.called(stubLoadScript); }); @@ -68,7 +68,7 @@ describe('adbutler adapter tests', function () { bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253', + zoneID: '210093', keyword: 'fish' }, requestId: '10b327aa396609', @@ -80,7 +80,7 @@ describe('adbutler adapter tests', function () { adapter().callBids(params); - var requestURI = spyLoadScript.getCall(0).args[0]; + var requestURI = stubLoadScript.getCall(0).args[0]; expect(requestURI).to.have.string(';kw=fish;'); }) @@ -92,14 +92,15 @@ describe('adbutler adapter tests', function () { var params = { bidderCode: 'adbutler', + bidder: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c94018cdbf2f68-1', sizes: [[300, 250]], bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253', + zoneID: '210093', }, requestId: '10b327aa396609', placementCode: '/123456/header-bid-tag-1' @@ -111,7 +112,7 @@ describe('adbutler adapter tests', function () { var response = { status: "SUCCESS", account_id: 167283, - zone_id: 210253, + zone_id: 210093, cpm: 1.5, width: 300, height: 250, @@ -119,8 +120,26 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); - pbjs.adbutlerCB(response); + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + + + pbjs.adbutlerCB(response); + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -141,7 +160,7 @@ describe('adbutler adapter tests', function () { bidderCode: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c9408cdbf2f68-2', sizes: [[300, 250]], bidder: 'adbutler', params: { @@ -164,6 +183,23 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + pbjs.adbutlerCB(response); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; @@ -183,7 +219,7 @@ describe('adbutler adapter tests', function () { bidderCode: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c9408cdbf2f68-3', sizes: [[300, 250]], bidder: 'adbutler', params: { @@ -208,6 +244,23 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + pbjs.adbutlerCB(response); var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -223,12 +276,12 @@ describe('adbutler adapter tests', function () { bidderCode: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c9408cdbf2f68-4', sizes: [[300, 250]], bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253', + zoneID: '210093', minCPM: '5.00' }, requestId: '10b327aa396609', @@ -241,7 +294,7 @@ describe('adbutler adapter tests', function () { var response = { status: "SUCCESS", account_id: 167283, - zone_id: 210253, + zone_id: 210093, cpm: 1.5, width: 300, height: 250, @@ -249,6 +302,23 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + pbjs.adbutlerCB(response); var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -265,12 +335,12 @@ describe('adbutler adapter tests', function () { bidderCode: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c9408cdbf2f68-5', sizes: [[300, 250]], bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253', + zoneID: '210093', maxCPM: '1.00' }, requestId: '10b327aa396609', @@ -283,7 +353,7 @@ describe('adbutler adapter tests', function () { var response = { status: "SUCCESS", account_id: 167283, - zone_id: 210253, + zone_id: 210093, cpm: 1.5, width: 300, height: 250, @@ -291,6 +361,23 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + pbjs.adbutlerCB(response); var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -311,12 +398,12 @@ describe('adbutler adapter tests', function () { bidderCode: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c9408cdbf2f68-6', sizes: [[300, 250]], bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253' + zoneID: '210093' }, requestId: '10b327aa396609', placementCode: '/123456/header-bid-tag-1' @@ -328,7 +415,7 @@ describe('adbutler adapter tests', function () { var response = { status: "SUCCESS", account_id: 167283, - zone_id: 210253, + zone_id: 210093, cpm: 1.5, width: 300, height: 250, @@ -337,6 +424,23 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + pbjs.adbutlerCB(response); var bidObject1 = stubAddBidResponse.getCall(0).args[1]; @@ -354,12 +458,12 @@ describe('adbutler adapter tests', function () { bidderCode: 'adbutler', bids: [ { - bidId: '3c9408cdbf2f68', + bidId: '3c9408cdbf2f68-7', sizes: [[300, 250]], bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210253' + zoneID: '210093' }, requestId: '10b327aa396609', placementCode: '/123456/header-bid-tag-1' @@ -371,7 +475,7 @@ describe('adbutler adapter tests', function () { var response = { status: "SUCCESS", account_id: 167283, - zone_id: 210253, + zone_id: 210093, cpm: 1.5, width: 300, height: 250, @@ -383,6 +487,23 @@ describe('adbutler adapter tests', function () { }; adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + unit.sizes=[[300,250]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + pbjs.adbutlerCB(response); var bidObject1 = stubAddBidResponse.getCall(0).args[1]; From 10ab7215ce86d88511674ff7b72bac7acb81a576 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Mon, 24 Oct 2016 12:51:07 -0700 Subject: [PATCH 4/9] Prevent AdButler TypeErrors Prevent AdButler TypeErrors and pass bid request object into the bid response. --- src/adapters/adbutler.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adapters/adbutler.js b/src/adapters/adbutler.js index 61053f14874..d2510a53ee4 100644 --- a/src/adapters/adbutler.js +++ b/src/adapters/adbutler.js @@ -51,7 +51,7 @@ var AdButlerAdapter = function AdButlerAdapter() { isCorrectSize = false, isCorrectCPM = true, CPM,minCPM,maxCPM, - bidObj = utils.getBidRequest(callbackData[callbackID].bidId); + bidObj = callbackData[callbackID] ? utils.getBidRequest(callbackData[callbackID].bidId) : null; if (bidObj) { @@ -77,7 +77,7 @@ var AdButlerAdapter = function AdButlerAdapter() { if(isCorrectCPM && isCorrectSize){ - bidResponse = bidfactory.createBid(1); + bidResponse = bidfactory.createBid(1,bidObj); bidResponse.bidderCode = 'adbutler'; bidResponse.cpm = CPM; bidResponse.width = width; @@ -87,13 +87,13 @@ var AdButlerAdapter = function AdButlerAdapter() { } else { - bidResponse = bidfactory.createBid(2); + bidResponse = bidfactory.createBid(2,bidObj); bidResponse.bidderCode = 'adbutler'; } } else { - bidResponse = bidfactory.createBid(2); + bidResponse = bidfactory.createBid(2,bidObj); bidResponse.bidderCode = 'adbutler'; } From 1d4480a1ad8022617321e8faebd6a0f67f1376c8 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Mon, 27 Mar 2017 10:27:32 -0700 Subject: [PATCH 5/9] Add optional domain parameter. Add optional domain parameter to AdButler adapter. --- src/adapters/adbutler.js | 15 ++++++++++----- test/spec/adapters/adbutler_spec.js | 28 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/adapters/adbutler.js b/src/adapters/adbutler.js index 00f8d4db1a2..a0005e89e4f 100644 --- a/src/adapters/adbutler.js +++ b/src/adapters/adbutler.js @@ -105,11 +105,16 @@ var AdButlerAdapter = function AdButlerAdapter() { } function buildRequest(bid,adIndex,pageID){ - var accountID = utils.getBidIdParameter('accountID', bid.params); - var zoneID = utils.getBidIdParameter('zoneID', bid.params); - var keyword = utils.getBidIdParameter('keyword', bid.params); - - var requestURI = location.protocol + '//servedbyadbutler.com/adserve/;type=hbr;'; + var accountID = utils.getBidIdParameter('accountID', bid.params), + zoneID = utils.getBidIdParameter('zoneID', bid.params), + keyword = utils.getBidIdParameter('keyword', bid.params), + domain = utils.getBidIdParameter('domain', bid.params); + + if(typeof domain === 'undefined' || domain.length === 0){ + domain = 'servedbyadbutler.com'; + } + + var requestURI = location.protocol + '//' + domain + '/adserve/;type=hbr;'; requestURI += 'ID='+encodeURIComponent(accountID)+';'; requestURI += 'setID='+encodeURIComponent(zoneID)+';'; requestURI += 'pid='+encodeURIComponent(pageID)+';'; diff --git a/test/spec/adapters/adbutler_spec.js b/test/spec/adapters/adbutler_spec.js index 465ef89bfe6..172c2205210 100644 --- a/test/spec/adapters/adbutler_spec.js +++ b/test/spec/adapters/adbutler_spec.js @@ -83,7 +83,33 @@ describe('adbutler adapter tests', function () { var requestURI = stubLoadScript.getCall(0).args[0]; expect(requestURI).to.have.string(';kw=fish;'); - }) + }); + + it('should use custom domain string',function(){ + var params = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '107878', + zoneID: '86133', + domain: 'servedbyadbutler.com.dan.test' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + ] + }; + + adapter().callBids(params); + + var requestURI = stubLoadScript.getCall(0).args[0]; + + expect(requestURI).to.have.string('.dan.test'); + }); }); describe('bid responses',function(){ From 09804e4a9752d57d9a4c6c7698038f681de82e64 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Fri, 6 Oct 2017 13:23:43 -0700 Subject: [PATCH 6/9] Update AdButler adapter to Prebid 1.0 --- modules/adbutlerBidAdapter.js | 229 +++---- test/spec/modules/adbutlerBidAdapter_spec.js | 668 +++++++------------ 2 files changed, 330 insertions(+), 567 deletions(-) diff --git a/modules/adbutlerBidAdapter.js b/modules/adbutlerBidAdapter.js index d6492a72e1c..b6ce25f5c03 100644 --- a/modules/adbutlerBidAdapter.js +++ b/modules/adbutlerBidAdapter.js @@ -1,130 +1,122 @@ -/** - * @overview AdButler Prebid.js adapter. - * @author dkharton - */ - 'use strict'; -var utils = require('src/utils.js'); -var adloader = require('src/adloader.js'); -var bidmanager = require('src/bidmanager.js'); -var bidfactory = require('src/bidfactory.js'); -var adaptermanager = require('src/adaptermanager'); - -var AdButlerAdapter = function AdButlerAdapter() { - function _callBids(params) { - var bids = params.bids || []; - var callbackData = {}; - var zoneCount = {}; - var pageID = Math.floor(Math.random() * 10e6); - - // Build and send bid requests - for (var i = 0; i < bids.length; i++) { - var bid = bids[i]; - var zoneID = utils.getBidIdParameter('zoneID', bid.params); - var callbackID; - - if (!(zoneID in zoneCount)) { - zoneCount[zoneID] = 0; +import * as utils from 'src/utils'; +import {config} from 'src/config'; +import {registerBidder} from 'src/adapters/bidderFactory'; + +const BIDDER_CODE = 'adbutler'; + +export const spec = { + code: BIDDER_CODE, + pageID: Math.floor(Math.random() * 10e6), + zoneCounters: {}, + + isBidRequestValid: function (bid) { + return !!(bid.params.accountID && bid.params.zoneID); + }, + + buildRequests: function (validBidRequests) { + var i; + var zoneID; + var bidRequest; + var accountID; + var keyword; + var domain; + var requestURI; + var serverRequests = []; + + for (i = 0; i < validBidRequests.length; i++) { + bidRequest = validBidRequests[i]; + zoneID = utils.getBidIdParameter('zoneID', bidRequest.params); + accountID = utils.getBidIdParameter('accountID', bidRequest.params); + keyword = utils.getBidIdParameter('keyword', bidRequest.params); + domain = utils.getBidIdParameter('domain', bidRequest.params); + + if (!(zoneID in spec.zoneCounters)) { + spec.zoneCounters[zoneID] = 0; } - // build callbackID to get placementCode later - callbackID = zoneID + '_' + zoneCount[zoneID]; + if (typeof domain === 'undefined' || domain.length === 0) { + domain = 'servedbyadbutler.com'; + } - callbackData[callbackID] = {}; - callbackData[callbackID].bidId = bid.bidId; + requestURI = location.protocol + '//' + domain + '/adserve/;type=hbr;'; + requestURI += 'ID=' + encodeURIComponent(accountID) + ';'; + requestURI += 'setID=' + encodeURIComponent(zoneID) + ';'; + requestURI += 'pid=' + encodeURIComponent(spec.pageID) + ';'; + requestURI += 'place=' + encodeURIComponent(spec.zoneCounters[zoneID]) + ';'; - var adRequest = buildRequest(bid, zoneCount[zoneID], pageID); - zoneCount[zoneID]++; + // append the keyword for targeting if one was passed in + if (keyword !== '') { + requestURI += 'kw=' + encodeURIComponent(keyword) + ';'; + } - adloader.loadScript(adRequest); + spec.zoneCounters[zoneID]++; + serverRequests.push({ + method: 'GET', + url: requestURI, + data: {}, + bidRequest: bidRequest + }); } + return serverRequests; + }, + + interpretResponse: function (serverResponse, bidRequest) { + var bidObj = bidRequest.bidRequest; + var bidResponses = []; + var bidResponse = {}; + var isCorrectSize = false; + var isCorrectCPM = true; + var CPM; + var minCPM; + var maxCPM; + var width; + var height; + + if (serverResponse && serverResponse.status === 'SUCCESS' && bidObj) { + CPM = serverResponse.cpm; + minCPM = utils.getBidIdParameter('minCPM', bidObj.params); + maxCPM = utils.getBidIdParameter('maxCPM', bidObj.params); + width = parseInt(serverResponse.width); + height = parseInt(serverResponse.height); + + // Ensure response CPM is within the given bounds + if (minCPM !== '' && CPM < parseFloat(minCPM)) { + isCorrectCPM = false; + } + if (maxCPM !== '' && CPM > parseFloat(maxCPM)) { + isCorrectCPM = false; + } - // Define callback function for bid responses - $$PREBID_GLOBAL$$.adbutlerCB = function(aBResponseObject) { - var bidResponse = {}; - var callbackID = aBResponseObject.zone_id + '_' + aBResponseObject.place; - var width = parseInt(aBResponseObject.width); - var height = parseInt(aBResponseObject.height); - var isCorrectSize = false; - var isCorrectCPM = true; - var CPM; - var minCPM; - var maxCPM; - var bidObj = callbackData[callbackID] ? utils.getBidRequest(callbackData[callbackID].bidId) : null; - - if (bidObj) { - if (aBResponseObject.status === 'SUCCESS') { - CPM = aBResponseObject.cpm; - minCPM = utils.getBidIdParameter('minCPM', bidObj.params); - maxCPM = utils.getBidIdParameter('maxCPM', bidObj.params); - - // Ensure response CPM is within the given bounds - if (minCPM !== '' && CPM < parseFloat(minCPM)) { - isCorrectCPM = false; - } - if (maxCPM !== '' && CPM > parseFloat(maxCPM)) { - isCorrectCPM = false; - } - - // Ensure that response ad matches one of the placement sizes. - utils._each(bidObj.sizes, function(size) { - if (width === size[0] && height === size[1]) { - isCorrectSize = true; - } - }); - - if (isCorrectCPM && isCorrectSize) { - bidResponse = bidfactory.createBid(1, bidObj); - bidResponse.bidderCode = 'adbutler'; - bidResponse.cpm = CPM; - bidResponse.width = width; - bidResponse.height = height; - bidResponse.ad = aBResponseObject.ad_code; - bidResponse.ad += addTrackingPixels(aBResponseObject.tracking_pixels); - } else { - bidResponse = bidfactory.createBid(2, bidObj); - bidResponse.bidderCode = 'adbutler'; - } - } else { - bidResponse = bidfactory.createBid(2, bidObj); - bidResponse.bidderCode = 'adbutler'; + // Ensure that response ad matches one of the placement sizes. + utils._each(bidObj.sizes, function (size) { + if (width === size[0] && height === size[1]) { + isCorrectSize = true; } - - bidmanager.addBidResponse(bidObj.placementCode, bidResponse); + }); + if (isCorrectCPM && isCorrectSize) { + bidResponse.requestId = bidObj.bidId; + bidResponse.bidderCode = spec.code; + bidResponse.creativeId = serverResponse.placement_id; + bidResponse.cpm = CPM; + bidResponse.width = width; + bidResponse.height = height; + bidResponse.ad = serverResponse.ad_code; + bidResponse.ad += spec.addTrackingPixels(serverResponse.tracking_pixels); + bidResponse.currency = 'USD'; + bidResponse.netRevenue = true; + bidResponse.ttl = config.getConfig('_bidderTimeout'); + bidResponse.referrer = utils.getTopWindowUrl(); + bidResponses.push(bidResponse); } - }; - } - - function buildRequest(bid, adIndex, pageID) { - var accountID = utils.getBidIdParameter('accountID', bid.params); - var zoneID = utils.getBidIdParameter('zoneID', bid.params); - var keyword = utils.getBidIdParameter('keyword', bid.params); - var domain = utils.getBidIdParameter('domain', bid.params); - - if (typeof domain === 'undefined' || domain.length === 0) { - domain = 'servedbyadbutler.com'; } + return bidResponses; + }, - var requestURI = location.protocol + '//' + domain + '/adserve/;type=hbr;'; - requestURI += 'ID=' + encodeURIComponent(accountID) + ';'; - requestURI += 'setID=' + encodeURIComponent(zoneID) + ';'; - requestURI += 'pid=' + encodeURIComponent(pageID) + ';'; - requestURI += 'place=' + encodeURIComponent(adIndex) + ';'; - - // append the keyword for targeting if one was passed in - if (keyword !== '') { - requestURI += 'kw=' + encodeURIComponent(keyword) + ';'; - } - requestURI += 'jsonpfunc=$$PREBID_GLOBAL$$.adbutlerCB;'; - requestURI += 'click=CLICK_MACRO_PLACEHOLDER'; - - return requestURI; - } - - function addTrackingPixels(trackingPixels) { + addTrackingPixels: function (trackingPixels) { var trackingPixelMarkup = ''; - utils._each(trackingPixels, function(pixelURL) { + utils._each(trackingPixels, function (pixelURL) { var trackingPixel = ''; @@ -133,14 +125,5 @@ var AdButlerAdapter = function AdButlerAdapter() { }); return trackingPixelMarkup; } - - // 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 AdButlerAdapter(), 'adbutler'); - -module.exports = AdButlerAdapter; +registerBidder(spec); diff --git a/test/spec/modules/adbutlerBidAdapter_spec.js b/test/spec/modules/adbutlerBidAdapter_spec.js index d026ac8de98..4aefe047316 100644 --- a/test/spec/modules/adbutlerBidAdapter_spec.js +++ b/test/spec/modules/adbutlerBidAdapter_spec.js @@ -1,516 +1,296 @@ -describe('adbutler adapter tests', function () { - var expect = require('chai').expect; - var adapter = require('modules/adbutlerBidAdapter'); - var adLoader = require('src/adloader'); - var bidmanager = require('src/bidmanager'); +import {expect} from 'chai'; +import adapterManager from 'src/adaptermanager'; +import bidManager from 'src/bidmanager'; +import {spec} from 'modules/adbutlerBidAdapter'; +import {parse as parseQuery} from 'querystring'; +import {newBidder} from 'src/adapters/bidderFactory'; + +var CONSTANTS = require('src/constants.json'); + +describe('AdButler adapter', () => { + let sandbox, + adUnit, + bidderRequest; + + beforeEach(() => { + sandbox = sinon.sandbox.create(); + + sandbox.useFakeServer(); + + adUnit = { + code: '/19968336/header-bid-tag-1', + sizes: [[300, 250], [320, 50]], + bids: [ + { + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210093', + keyword: 'red', + minCPM: '1.00', + maxCPM: '5.00' + } + } + ] + }; + + bidderRequest = { + bidderCode: 'adbutler', + requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', + bidderRequestId: '1c56ad30b9b8ca8', + bids: [ + { + bidder: 'adbutler', + params: { + accountID: "167283", + zoneID: "210093", + keyword: 'red', + minCPM: '1.00', + maxCPM: '5.00' + }, + placementCode: '/19968336/header-bid-tag-1', + sizes: [[300, 250], [300, 600]], + bidId: '23acc48ad47af5', + requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', + bidderRequestId: '1c56ad30b9b8ca8', + transactionId: '92489f71-1bf2-49a0-adf9-000cea934729' + } + ], + start: 1472239426002, + auctionStart: 1472239426000, + timeout: 5000 + }; + }); - describe('creation of bid url', function () { - var stubLoadScript; + afterEach(() => { + sandbox.restore(); + }); - beforeEach(function () { - stubLoadScript = sinon.stub(adLoader, 'loadScript'); - }); + describe('implementation', () => { - afterEach(function () { - stubLoadScript.restore(); - }); + let adapter, + bids, + addBidResponseAction; - if (typeof ($$PREBID_GLOBAL$$._bidsReceived) === 'undefined') { - $$PREBID_GLOBAL$$._bidsReceived = []; - } - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = []; - } - if (typeof ($$PREBID_GLOBAL$$._adsReceived) === 'undefined') { - $$PREBID_GLOBAL$$._adsReceived = []; - } - - it('should be called', function () { - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } - - ] - }; + beforeEach(() => { + adapter = newBidder(spec); + bids = []; - adapter().callBids(params); + sandbox.stub(bidManager, 'addBidResponse', (el, bid) => { + bids.push(bid); + if (typeof addBidResponseAction === 'function') { + addBidResponseAction(); + addBidResponseAction = undefined; + } + }); - sinon.assert.called(stubLoadScript); }); - it('should populate the keyword', function() { - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - keyword: 'fish' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + describe('for requests', () => { - ] - }; + let validateBidsSpy; - adapter().callBids(params); + beforeEach(() => { - var requestURI = stubLoadScript.getCall(0).args[0]; + validateBidsSpy = sandbox.spy(spec, 'isBidRequestValid'); - expect(requestURI).to.have.string(';kw=fish;'); - }); + }); - it('should use custom domain string', function() { - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '107878', - zoneID: '86133', - domain: 'servedbyadbutler.com.dan.test' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } - ] - }; + it('should validate bids', () => { - adapter().callBids(params); + adapter.callBids(bidderRequest); - var requestURI = stubLoadScript.getCall(0).args[0]; + sinon.assert.called(validateBidsSpy); - expect(requestURI).to.have.string('.dan.test'); - }); - }); - describe('bid responses', function() { - it('should return complete bid response', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - - var params = { - bidderCode: 'adbutler', - bidder: 'adbutler', - bids: [ - { - bidId: '3c94018cdbf2f68-1', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + }); - ] - }; - - var response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0 - }; - - adapter().callBids(params); - - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - 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$$.adbutlerCB(response); - - var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; - - expect(bidPlacementCode1).to.equal('/123456/header-bid-tag-1'); - expect(bidObject1.getStatusCode()).to.equal(1); - expect(bidObject1.bidderCode).to.equal('adbutler'); - expect(bidObject1.cpm).to.equal(1.5); - expect(bidObject1.width).to.equal(300); - expect(bidObject1.height).to.equal(250); - - stubAddBidResponse.restore(); - }); + it('should reject invalid bid', () => { - it('should return empty bid response', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68-2', - sizes: [[300, 250]], + let invalidBid = { bidder: 'adbutler', params: { accountID: '167283', - zoneID: '210085', - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } - - ] - }; - - var response = { - status: 'NO_ELIGIBLE_ADS', - zone_id: 210085, - width: 728, - height: 90, - place: 0 - }; - - adapter().callBids(params); - - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + } + }, + isValid = spec.isBidRequestValid(invalidBid); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } + expect(isValid).to.equal(false); - $$PREBID_GLOBAL$$.adUnits = adUnits; + }); - $$PREBID_GLOBAL$$.adbutlerCB(response); + it('should use custom domain string', () => { + var bidderRequest = { + bidderCode: 'adbutler', + bids: [ + { + bidId: '3c9408cdbf2f68', + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '107878', + zoneID: '86133', + domain: 'servedbyadbutler.com.dan.test' + }, + requestId: '10b327aa396609', + placementCode: '/123456/header-bid-tag-1' + } + ] + }; - var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + adapter.callBids(bidderRequest); - expect(bidPlacementCode1).to.equal('/123456/header-bid-tag-1'); - expect(bidObject1.getStatusCode()).to.equal(2); - expect(bidObject1.bidderCode).to.equal('adbutler'); + let requestURL = sandbox.server.requests[0].url; - stubAddBidResponse.restore(); - }); - - it('should return empty bid response on incorrect size', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68-3', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210085', - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + expect(requestURL).to.have.string('.dan.test'); + }); - ] - }; + it('should set default domain', () =>{ - var response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210085, - cpm: 1.5, - width: 728, - height: 90, - place: 0 - }; + adapter.callBids(bidderRequest); - adapter().callBids(params); + let request = sandbox.server.requests[0]; + let [domain] = request.url.split('/adserve/'); - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + expect(domain).to.equal('http://servedbyadbutler.com'); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } + }); - $$PREBID_GLOBAL$$.adUnits = adUnits; + it('should set the keyword parameter', () =>{ + adapter.callBids(bidderRequest); - $$PREBID_GLOBAL$$.adbutlerCB(response); + let requestURL = sandbox.server.requests[0].url; - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; - expect(bidObject1.getStatusCode()).to.equal(2); + expect(requestURL).to.have.string(';kw=red;'); + }); - stubAddBidResponse.restore(); }); - it('should return empty bid response with CPM too low', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68-4', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - minCPM: '5.00' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + describe('bid responses', () =>{ - ] - }; + it('should return complete bid response', () =>{ - var response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0 - }; + let response = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210093, + cpm: 1.5, + width: 300, + height: 250, + place: 0, + ad_code: '', + tracking_pixels: [ + 'http://tracking.pixel.com/params=info' + ] + }; + sandbox.server.respondWith(JSON.stringify(response)); - adapter().callBids(params); + adapter.callBids(bidderRequest); - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + sandbox.server.respond(); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } + expect(bids).to.be.lengthOf(1); - $$PREBID_GLOBAL$$.adUnits = adUnits; + expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); + expect(bids[0].bidderCode).to.equal('adbutler'); + expect(bids[0].cpm).to.equal(1.5); + expect(bids[0].width).to.equal(300); + expect(bids[0].height).to.equal(250); + expect(bids[0].currency).to.equal('USD'); + expect(bids[0].netRevenue).to.equal(true); + expect(bids[0].ad).to.have.length.above(1); + expect(bids[0].ad).to.have.string('http://tracking.pixel.com/params=info'); - $$PREBID_GLOBAL$$.adbutlerCB(response); + }); - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; - expect(bidObject1.getStatusCode()).to.equal(2); - - stubAddBidResponse.restore(); - }); + it('should return empty bid response', () =>{ + let response = { + status: 'NO_ELIGIBLE_ADS', + zone_id: 210083, + width: 300, + height: 250, + place: 0 + }; - it('should return empty bid response with CPM too high', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68-5', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - maxCPM: '1.00' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + sandbox.server.respondWith(JSON.stringify(response)); - ] - }; + adapter.callBids(bidderRequest); - var response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0 - }; + sandbox.server.respond(); - adapter().callBids(params); + expect(bids).to.be.lengthOf(1); + expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(bids[0].bidderCode).to.equal('adbutler'); - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + }); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } + it('should return empty bid response on incorrect size', () => { - $$PREBID_GLOBAL$$.adUnits = adUnits; + let response = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210083, + cpm: 1.5, + width: 728, + height: 90, + place: 0 + }; - $$PREBID_GLOBAL$$.adbutlerCB(response); + sandbox.server.respondWith(JSON.stringify(response)); - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; - expect(bidObject1.getStatusCode()).to.equal(2); + adapter.callBids(bidderRequest); - stubAddBidResponse.restore(); - }); - }); + sandbox.server.respond(); - describe('ad code', function() { - it('should be populated', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + expect(bids).to.be.lengthOf(1); + expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + }); - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68-6', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + it('should return empty bid response with CPM too low', () => { - ] - }; + let response = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210093, + cpm: 0.75, + width: 300, + height: 250, + place: 0 + }; - var response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0, - ad_code: '' - }; + sandbox.server.respondWith(JSON.stringify(response)); - adapter().callBids(params); + adapter.callBids(bidderRequest); - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - unit.sizes = [[300, 250]]; - adUnits.push(unit); + sandbox.server.respond(); - if (typeof ($$PREBID_GLOBAL$$._bidsRequested) === 'undefined') { - $$PREBID_GLOBAL$$._bidsRequested = [params]; - } else { - $$PREBID_GLOBAL$$._bidsRequested.push(params); - } + expect(bids).to.be.lengthOf(1); + expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + }); - $$PREBID_GLOBAL$$.adUnits = adUnits; + it('should return empty bid response with CPM too high', () => { - $$PREBID_GLOBAL$$.adbutlerCB(response); + let response = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210093, + cpm: 7.00, + width: 300, + height: 250, + place: 0 + }; - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; - expect(bidObject1.getStatusCode()).to.equal(1); - expect(bidObject1.ad).to.have.length.above(1); + sandbox.server.respondWith(JSON.stringify(response)); - stubAddBidResponse.restore(); - }); + adapter.callBids(bidderRequest); - it('should contain tracking pixels', function() { - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + sandbox.server.respond(); - var params = { - bidderCode: 'adbutler', - bids: [ - { - bidId: '3c9408cdbf2f68-7', - sizes: [[300, 250]], - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093' - }, - requestId: '10b327aa396609', - placementCode: '/123456/header-bid-tag-1' - } + expect(bids).to.be.lengthOf(1); + expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + }); - ] - }; - - var response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0, - ad_code: '', - tracking_pixels: [ - 'http://tracking.pixel.com/params=info' - ] - }; - - adapter().callBids(params); - - var adUnits = new Array(); - var unit = new Object(); - unit.bids = params.bids; - unit.code = '/123456/header-bid-tag-1'; - 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$$.adbutlerCB(response); - - var bidObject1 = stubAddBidResponse.getCall(0).args[1]; - expect(bidObject1.getStatusCode()).to.equal(1); - expect(bidObject1.ad).to.have.string('http://tracking.pixel.com/params=info'); - - stubAddBidResponse.restore(); }); + }); -}); + +}); \ No newline at end of file From 011727590ea9d03da0bb5efee98b95d582c80870 Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Fri, 6 Oct 2017 13:56:56 -0700 Subject: [PATCH 7/9] Code Style updates based on lint warnings. --- test/spec/modules/adbutlerBidAdapter_spec.js | 38 +++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/test/spec/modules/adbutlerBidAdapter_spec.js b/test/spec/modules/adbutlerBidAdapter_spec.js index 4aefe047316..2e357e45061 100644 --- a/test/spec/modules/adbutlerBidAdapter_spec.js +++ b/test/spec/modules/adbutlerBidAdapter_spec.js @@ -42,8 +42,8 @@ describe('AdButler adapter', () => { { bidder: 'adbutler', params: { - accountID: "167283", - zoneID: "210093", + accountID: '167283', + zoneID: '210093', keyword: 'red', minCPM: '1.00', maxCPM: '5.00' @@ -67,7 +67,6 @@ describe('AdButler adapter', () => { }); describe('implementation', () => { - let adapter, bids, addBidResponseAction; @@ -83,29 +82,22 @@ describe('AdButler adapter', () => { addBidResponseAction = undefined; } }); - }); describe('for requests', () => { - let validateBidsSpy; beforeEach(() => { - validateBidsSpy = sandbox.spy(spec, 'isBidRequestValid'); - }); it('should validate bids', () => { - adapter.callBids(bidderRequest); sinon.assert.called(validateBidsSpy); - }); it('should reject invalid bid', () => { - let invalidBid = { bidder: 'adbutler', params: { @@ -115,7 +107,6 @@ describe('AdButler adapter', () => { isValid = spec.isBidRequestValid(invalidBid); expect(isValid).to.equal(false); - }); it('should use custom domain string', () => { @@ -144,31 +135,26 @@ describe('AdButler adapter', () => { expect(requestURL).to.have.string('.dan.test'); }); - it('should set default domain', () =>{ - + it('should set default domain', () => { adapter.callBids(bidderRequest); let request = sandbox.server.requests[0]; let [domain] = request.url.split('/adserve/'); expect(domain).to.equal('http://servedbyadbutler.com'); - }); - it('should set the keyword parameter', () =>{ + it('should set the keyword parameter', () => { adapter.callBids(bidderRequest); let requestURL = sandbox.server.requests[0].url; expect(requestURL).to.have.string(';kw=red;'); }); - }); - describe('bid responses', () =>{ - - it('should return complete bid response', () =>{ - + describe('bid responses', () => { + it('should return complete bid response', () => { let response = { status: 'SUCCESS', account_id: 167283, @@ -199,10 +185,9 @@ describe('AdButler adapter', () => { expect(bids[0].netRevenue).to.equal(true); expect(bids[0].ad).to.have.length.above(1); expect(bids[0].ad).to.have.string('http://tracking.pixel.com/params=info'); - }); - it('should return empty bid response', () =>{ + it('should return empty bid response', () => { let response = { status: 'NO_ELIGIBLE_ADS', zone_id: 210083, @@ -220,11 +205,9 @@ describe('AdButler adapter', () => { expect(bids).to.be.lengthOf(1); expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); expect(bids[0].bidderCode).to.equal('adbutler'); - }); it('should return empty bid response on incorrect size', () => { - let response = { status: 'SUCCESS', account_id: 167283, @@ -246,7 +229,6 @@ describe('AdButler adapter', () => { }); it('should return empty bid response with CPM too low', () => { - let response = { status: 'SUCCESS', account_id: 167283, @@ -268,7 +250,6 @@ describe('AdButler adapter', () => { }); it('should return empty bid response with CPM too high', () => { - let response = { status: 'SUCCESS', account_id: 167283, @@ -288,9 +269,6 @@ describe('AdButler adapter', () => { expect(bids).to.be.lengthOf(1); expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); }); - }); - }); - -}); \ No newline at end of file +}); From 5af952b039f0cca898495a19571bf8e69c8f667a Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Wed, 11 Oct 2017 17:03:31 -0700 Subject: [PATCH 8/9] Removed mutable global, simplified tests, and added markdown file. --- modules/adbutlerBidAdapter.js | 10 +- modules/adbutlerBidAdapter.md | 31 ++ test/spec/modules/adbutlerBidAdapter_spec.js | 307 ++++++++----------- 3 files changed, 157 insertions(+), 191 deletions(-) create mode 100644 modules/adbutlerBidAdapter.md diff --git a/modules/adbutlerBidAdapter.js b/modules/adbutlerBidAdapter.js index b6ce25f5c03..f633eba98a3 100644 --- a/modules/adbutlerBidAdapter.js +++ b/modules/adbutlerBidAdapter.js @@ -9,7 +9,6 @@ const BIDDER_CODE = 'adbutler'; export const spec = { code: BIDDER_CODE, pageID: Math.floor(Math.random() * 10e6), - zoneCounters: {}, isBidRequestValid: function (bid) { return !!(bid.params.accountID && bid.params.zoneID); @@ -24,6 +23,7 @@ export const spec = { var domain; var requestURI; var serverRequests = []; + var zoneCounters = {}; for (i = 0; i < validBidRequests.length; i++) { bidRequest = validBidRequests[i]; @@ -32,8 +32,8 @@ export const spec = { keyword = utils.getBidIdParameter('keyword', bidRequest.params); domain = utils.getBidIdParameter('domain', bidRequest.params); - if (!(zoneID in spec.zoneCounters)) { - spec.zoneCounters[zoneID] = 0; + if (!(zoneID in zoneCounters)) { + zoneCounters[zoneID] = 0; } if (typeof domain === 'undefined' || domain.length === 0) { @@ -44,14 +44,14 @@ export const spec = { requestURI += 'ID=' + encodeURIComponent(accountID) + ';'; requestURI += 'setID=' + encodeURIComponent(zoneID) + ';'; requestURI += 'pid=' + encodeURIComponent(spec.pageID) + ';'; - requestURI += 'place=' + encodeURIComponent(spec.zoneCounters[zoneID]) + ';'; + requestURI += 'place=' + encodeURIComponent(zoneCounters[zoneID]) + ';'; // append the keyword for targeting if one was passed in if (keyword !== '') { requestURI += 'kw=' + encodeURIComponent(keyword) + ';'; } - spec.zoneCounters[zoneID]++; + zoneCounters[zoneID]++; serverRequests.push({ method: 'GET', url: requestURI, diff --git a/modules/adbutlerBidAdapter.md b/modules/adbutlerBidAdapter.md new file mode 100644 index 00000000000..5905074270a --- /dev/null +++ b/modules/adbutlerBidAdapter.md @@ -0,0 +1,31 @@ +# Overview + +**Module Name**: AdButler Bidder Adapter +**Module Type**: Bidder Adapter +**Maintainer**: dan@sparklit.com + +# Description + +Module that connects to an AdButler zone to fetch bids. + +# Test Parameters +``` + var adUnits = [ + { + code: 'display-div', + sizes: [[300, 250]], // a display size + bids: [ + { + bidder: "adbutler", + params: { + accountID: '167283', + zoneID: '210093', + keyword: 'red', //optional + minCPM: '1.00', //optional + maxCPM: '5.00' //optional + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/test/spec/modules/adbutlerBidAdapter_spec.js b/test/spec/modules/adbutlerBidAdapter_spec.js index 2e357e45061..352358be8d0 100644 --- a/test/spec/modules/adbutlerBidAdapter_spec.js +++ b/test/spec/modules/adbutlerBidAdapter_spec.js @@ -1,100 +1,43 @@ import {expect} from 'chai'; -import adapterManager from 'src/adaptermanager'; -import bidManager from 'src/bidmanager'; import {spec} from 'modules/adbutlerBidAdapter'; -import {parse as parseQuery} from 'querystring'; -import {newBidder} from 'src/adapters/bidderFactory'; - -var CONSTANTS = require('src/constants.json'); describe('AdButler adapter', () => { - let sandbox, - adUnit, - bidderRequest; + let bidRequests; beforeEach(() => { - sandbox = sinon.sandbox.create(); - - sandbox.useFakeServer(); - - adUnit = { - code: '/19968336/header-bid-tag-1', - sizes: [[300, 250], [320, 50]], - bids: [ - { - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - keyword: 'red', - minCPM: '1.00', - maxCPM: '5.00' - } - } - ] - }; - - bidderRequest = { - bidderCode: 'adbutler', - requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - bids: [ - { - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - keyword: 'red', - minCPM: '1.00', - maxCPM: '5.00' - }, - placementCode: '/19968336/header-bid-tag-1', - sizes: [[300, 250], [300, 600]], - bidId: '23acc48ad47af5', - requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729' - } - ], - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000 - }; - }); - - afterEach(() => { - sandbox.restore(); + bidRequests = [ + { + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210093', + keyword: 'red', + minCPM: '1.00', + maxCPM: '5.00' + }, + placementCode: '/19968336/header-bid-tag-1', + sizes: [[300, 250], [300, 600]], + bidId: '23acc48ad47af5', + requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', + bidderRequestId: '1c56ad30b9b8ca8', + transactionId: '92489f71-1bf2-49a0-adf9-000cea934729' + } + ]; }); describe('implementation', () => { - let adapter, - bids, - addBidResponseAction; - - beforeEach(() => { - adapter = newBidder(spec); - bids = []; - - sandbox.stub(bidManager, 'addBidResponse', (el, bid) => { - bids.push(bid); - if (typeof addBidResponseAction === 'function') { - addBidResponseAction(); - addBidResponseAction = undefined; - } - }); - }); - describe('for requests', () => { - let validateBidsSpy; - - beforeEach(() => { - validateBidsSpy = sandbox.spy(spec, 'isBidRequestValid'); - }); - - it('should validate bids', () => { - adapter.callBids(bidderRequest); + it('should accept valid bid', () => { + let validBid = { + bidder: 'adbutler', + params: { + accountID: '167283', + zoneID: '210093' + } + }, + isValid = spec.isBidRequestValid(validBid); - sinon.assert.called(validateBidsSpy); + expect(isValid).to.equal(true); }); it('should reject invalid bid', () => { @@ -110,9 +53,7 @@ describe('AdButler adapter', () => { }); it('should use custom domain string', () => { - var bidderRequest = { - bidderCode: 'adbutler', - bids: [ + let bidRequests = [ { bidId: '3c9408cdbf2f68', sizes: [[300, 250]], @@ -125,58 +66,77 @@ describe('AdButler adapter', () => { requestId: '10b327aa396609', placementCode: '/123456/header-bid-tag-1' } - ] - }; - - adapter.callBids(bidderRequest); - - let requestURL = sandbox.server.requests[0].url; + ], + requests = spec.buildRequests(bidRequests), + requestURL = requests[0].url; expect(requestURL).to.have.string('.dan.test'); }); it('should set default domain', () => { - adapter.callBids(bidderRequest); + let requests = spec.buildRequests(bidRequests), + request = requests[0]; - let request = sandbox.server.requests[0]; let [domain] = request.url.split('/adserve/'); expect(domain).to.equal('http://servedbyadbutler.com'); }); it('should set the keyword parameter', () => { - adapter.callBids(bidderRequest); - - let requestURL = sandbox.server.requests[0].url; + let requests = spec.buildRequests(bidRequests), + requestURL = requests[0].url; expect(requestURL).to.have.string(';kw=red;'); }); + + it('should increment the count for the same zone', () => { + let bidRequests = [ + { + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '107878', + zoneID: '86133', + domain: 'servedbyadbutler.com.dan.test' + } + }, { + sizes: [[300, 250]], + bidder: 'adbutler', + params: { + accountID: '107878', + zoneID: '86133', + domain: 'servedbyadbutler.com.dan.test' + } + }, + ], + requests = spec.buildRequests(bidRequests), + firstRequest = requests[0].url, + secondRequest = requests[1].url; + + expect(firstRequest).to.have.string(';place=0;'); + expect(secondRequest).to.have.string(';place=1;'); + }); }); describe('bid responses', () => { it('should return complete bid response', () => { - let response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0, - ad_code: '', - tracking_pixels: [ - 'http://tracking.pixel.com/params=info' - ] - }; - sandbox.server.respondWith(JSON.stringify(response)); - - adapter.callBids(bidderRequest); - - sandbox.server.respond(); + let serverResponse = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210093, + cpm: 1.5, + width: 300, + height: 250, + place: 0, + ad_code: '', + tracking_pixels: [ + 'http://tracking.pixel.com/params=info' + ] + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); expect(bids).to.be.lengthOf(1); - expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); expect(bids[0].bidderCode).to.equal('adbutler'); expect(bids[0].cpm).to.equal(1.5); expect(bids[0].width).to.equal(300); @@ -188,86 +148,61 @@ describe('AdButler adapter', () => { }); it('should return empty bid response', () => { - let response = { - status: 'NO_ELIGIBLE_ADS', - zone_id: 210083, - width: 300, - height: 250, - place: 0 - }; - - sandbox.server.respondWith(JSON.stringify(response)); - - adapter.callBids(bidderRequest); - - sandbox.server.respond(); + let serverResponse = { + status: 'NO_ELIGIBLE_ADS', + zone_id: 210083, + width: 300, + height: 250, + place: 0 + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - expect(bids).to.be.lengthOf(1); - expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); - expect(bids[0].bidderCode).to.equal('adbutler'); + expect(bids).to.be.lengthOf(0); }); it('should return empty bid response on incorrect size', () => { - let response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210083, - cpm: 1.5, - width: 728, - height: 90, - place: 0 - }; - - sandbox.server.respondWith(JSON.stringify(response)); - - adapter.callBids(bidderRequest); - - sandbox.server.respond(); + let serverResponse = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210083, + cpm: 1.5, + width: 728, + height: 90, + place: 0 + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - expect(bids).to.be.lengthOf(1); - expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(bids).to.be.lengthOf(0); }); it('should return empty bid response with CPM too low', () => { - let response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 0.75, - width: 300, - height: 250, - place: 0 - }; - - sandbox.server.respondWith(JSON.stringify(response)); - - adapter.callBids(bidderRequest); - - sandbox.server.respond(); + let serverResponse = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210093, + cpm: 0.75, + width: 300, + height: 250, + place: 0 + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - expect(bids).to.be.lengthOf(1); - expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(bids).to.be.lengthOf(0); }); it('should return empty bid response with CPM too high', () => { - let response = { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 7.00, - width: 300, - height: 250, - place: 0 - }; - - sandbox.server.respondWith(JSON.stringify(response)); - - adapter.callBids(bidderRequest); - - sandbox.server.respond(); + let serverResponse = { + status: 'SUCCESS', + account_id: 167283, + zone_id: 210093, + cpm: 7.00, + width: 300, + height: 250, + place: 0 + }, + bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - expect(bids).to.be.lengthOf(1); - expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(bids).to.be.lengthOf(0); }); }); }); From 7ef0341223a0ae75cceaf010ce6b831012fae96a Mon Sep 17 00:00:00 2001 From: Dan Harton Date: Tue, 17 Oct 2017 14:56:38 -0700 Subject: [PATCH 9/9] Update c1x adapter tests & remove old adbutler_spec file. --- test/spec/adapters/adbutler_spec.js | 0 test/spec/modules/c1xBidAdapter_spec.js | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) delete mode 100644 test/spec/adapters/adbutler_spec.js diff --git a/test/spec/adapters/adbutler_spec.js b/test/spec/adapters/adbutler_spec.js deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/spec/modules/c1xBidAdapter_spec.js b/test/spec/modules/c1xBidAdapter_spec.js index 3e482dfaae9..e1a48a5b701 100644 --- a/test/spec/modules/c1xBidAdapter_spec.js +++ b/test/spec/modules/c1xBidAdapter_spec.js @@ -177,6 +177,23 @@ describe('c1x adapter tests: ', () => { }); it('should show error when bidder sends invalid bid responses', () => { let responses; + let adUnits = []; + let unit = {}; + let params = getDefaultBidRequest(); + + unit.bids = params.bids; + unit.code = '/123456/header-bid-tag-1'; + 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; + pbjs._c1xResponse(responses); let bidObject = stubAddBidResponse.getCall(0).args[1]; expect(bidObject.statusMessage).to.equal('Bid returned empty or error response');