From 842b3bacf4e3e9843600fbb74cdb695b2d685c3f Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 19 Apr 2017 17:46:40 +0300 Subject: [PATCH 1/3] Added adsupply adapter --- adapters.json | 1 + src/adapters/adsupply.js | 88 ++++++++ test/spec/adapters/adsupply_spec.js | 308 ++++++++++++++++++++++++++++ 3 files changed, 397 insertions(+) create mode 100644 src/adapters/adsupply.js create mode 100644 test/spec/adapters/adsupply_spec.js diff --git a/adapters.json b/adapters.json index bf65a6d033d..2501d543905 100644 --- a/adapters.json +++ b/adapters.json @@ -60,6 +60,7 @@ "admixer", "atomx", "tapsense", + "adsupply", { "appnexus": { "alias": "brealtime" diff --git a/src/adapters/adsupply.js b/src/adapters/adsupply.js new file mode 100644 index 00000000000..68b1fc20b6b --- /dev/null +++ b/src/adapters/adsupply.js @@ -0,0 +1,88 @@ +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader'); +var utils = require('../utils'); +const ADSUPPLY_CODE = 'adsupply'; + +var AdSupplyAdapter = function AdSupplyAdapter() { + function _validateParams(params) { + if (!params || !params.siteId || !params.zoneId || !params.endpointUrl) { + return false; + } + + if (typeof params.zoneId !== "number" || params.zoneId <= 0) { + return false; + } + + return true; + } + + function _getRequestUrl(bid) { + var referrerUrl = encodeURIComponent(window.document.referrer); + var rand = encodeURIComponent(Math.floor(Math.random() * 100000 + 1)); + var time = encodeURIComponent(new Date().getTimezoneOffset()); + return '//' + bid.params.endpointUrl + '/banner.engine?id=' + bid.params.siteId + '&z=' + bid.params.zoneId + '&rand=' + rand + '&ver=async' + '&time=' + time + '&referrerurl=' + referrerUrl + '&abr=false' + '&hbt=1'; + } + + $$PREBID_GLOBAL$$.adSupplyResponseHandler = function (bidId) { + var b367CB268B1094004A3689751E7AC568F = window.b367CB268B1094004A3689751E7AC568F || {}; + + if (!bidId || !b367CB268B1094004A3689751E7AC568F) return; + + var bidRequest = utils.getBidRequest(bidId); + + if (!bidRequest || !bidRequest.params) return; + + var zoneProp = 'b' + bidRequest.params.zoneId; + + if (!bidRequest || !b367CB268B1094004A3689751E7AC568F[zoneProp]) return; + + var media = b367CB268B1094004A3689751E7AC568F[zoneProp].Media; + + if (!media) return; + + if (!media.Tag || !media.Ecpm || typeof media.Ecpm !== "number" || media.Ecpm <= 0) { + var noFillbject = bidfactory.createBid(2, bidRequest); + noFillbject.bidderCode = ADSUPPLY_CODE; + bidmanager.addBidResponse(bidRequest.placementCode, noFillbject); + } else { + var bidObject = bidfactory.createBid(1, bidRequest); + bidObject.bidderCode = ADSUPPLY_CODE; + bidObject.cpm = media.Ecpm; + bidObject.ad = media.Tag; + bidObject.width = media.Width; + bidObject.height = media.Height; + console.log('addBidResponse fill'); + bidmanager.addBidResponse(bidRequest.placementCode, bidObject); + } + }; + + function _makeCallBackHandler(bidId) { + return function () { + $$PREBID_GLOBAL$$.adSupplyResponseHandler(bidId); + }; + } + + function _callBids(params) { + window.b367CB268B1094004A3689751E7AC568F = window.b367CB268B1094004A3689751E7AC568F || {}; + + var bids = params.bids || []; + for (var i = 0; i < bids.length; i++) { + var bid = bids[i]; + if (!_validateParams(bid.params)) continue; + + var zoneProp = 'b' + bid.params.zoneId; + window.b367CB268B1094004A3689751E7AC568F[zoneProp] = window.b367CB268B1094004A3689751E7AC568F[zoneProp] || {}; + window.b367CB268B1094004A3689751E7AC568F[zoneProp].Media = {}; + + var requestUrl = _getRequestUrl(bid); + adloader.loadScript(requestUrl, _makeCallBackHandler(bid.bidId)); + } + } + + return { + callBids: _callBids + }; +}; + +module.exports = AdSupplyAdapter; \ No newline at end of file diff --git a/test/spec/adapters/adsupply_spec.js b/test/spec/adapters/adsupply_spec.js new file mode 100644 index 00000000000..522dfcdc5a5 --- /dev/null +++ b/test/spec/adapters/adsupply_spec.js @@ -0,0 +1,308 @@ +describe('adsupply adapter tests', function () { + + const expect = require('chai').expect; + const assert = require('chai').assert; + const AdSupplyAdapter = require('../../../src/adapters/adsupply'); + const adloader = require('../../../src/adloader'); + const bidmanager = require('../../../src/bidmanager'); + const CONSTANTS = require('../../../src/constants.json'); + let adsupplyAdapter = new AdSupplyAdapter(); + + //before(() => sinon.stub(document.body, 'appendChild')); + //after(() => document.body.appendChild.restore()); + + it('adsupply response handler should exist and be a function', function () { + expect(pbjs.adSupplyResponseHandler).to.exist.and.to.be.a('function'); + }); + + it('two requests are sent to adsupply engine', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }, + { + placementCode: "pc2", + bidder: "adsupply", + bidId: 'bidId2', + params: { + zoneId: 222, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + adsupplyAdapter.callBids(request); + + sinon.assert.calledTwice(stubLoadScript); + + adloader.loadScript.restore(); + }); + + it('zoneId is not a number and not specified', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: '111', + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }, + { + placementCode: "pc2", + bidder: "adsupply", + bidId: 'bidId2', + params: { + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + adsupplyAdapter.callBids(request); + + sinon.assert.notCalled(stubLoadScript); + + adloader.loadScript.restore(); + }); + + it('siteId is empty and not specified', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '', + endpointUrl: 'engine.4dsply.com' + } + }, + { + placementCode: "pc2", + bidder: "adsupply", + bidId: 'bidId2', + params: { + zoneId: 222, + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + adsupplyAdapter.callBids(request); + + sinon.assert.notCalled(stubLoadScript); + + adloader.loadScript.restore(); + }); + + it('endpointUrl is empty and not specified', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: '' + } + }, + { + placementCode: "pc2", + bidder: "adsupply", + bidId: 'bidId2', + params: { + zoneId: 222, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + } + }] + }; + + adsupplyAdapter.callBids(request); + + sinon.assert.notCalled(stubLoadScript); + + adloader.loadScript.restore(); + }); + + it('parameters are missed', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1' + }] + }; + + adsupplyAdapter.callBids(request); + + sinon.assert.notCalled(stubLoadScript); + + adloader.loadScript.restore(); + }); + + it('Parameters added to the reuest url', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + adsupplyAdapter.callBids(request); + + var requestUrl = stubLoadScript.getCall(0).args[0]; + expect(requestUrl).to.contain('111'); + expect(requestUrl).to.contain('0ab16161-a1de-4683-8837-c420bd4387c0'); + expect(requestUrl).to.contain('engine.4dsply.com'); + expect(requestUrl).to.contain('&hbt=1'); + + adloader.loadScript.restore(); + }); + + it('Response handler invalid data', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + window.b367CB268B1094004A3689751E7AC568F = {}; + + // adapter needs to be called, in order for the stub to register. + new AdSupplyAdapter(); + + // bidId is not valid + pbjs.adSupplyResponseHandler(null); + + // bidRequest object is not found + pbjs.adSupplyResponseHandler('bidId1'); + + //Zone property is not found + let bidderRequest = { + bidderCode: 'adsupply', + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + pbjs._bidsRequested.push(bidderRequest); + pbjs.adSupplyResponseHandler('bidId1'); + + //Media is not found + window.b367CB268B1094004A3689751E7AC568F = window.b367CB268B1094004A3689751E7AC568F || {}; + window.b367CB268B1094004A3689751E7AC568F['b111'] = window.b367CB268B1094004A3689751E7AC568F['b111'] || {}; + pbjs.adSupplyResponseHandler('bidId1'); + + sinon.assert.notCalled(stubAddBidResponse); + + pbjs._bidsRequested.pop(); + bidmanager.addBidResponse.restore(); + }); + + it('No Fill response', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + // adapter needs to be called, in order for the stub to register. + new AdSupplyAdapter(); + + //Zone property is not found + let bidderRequest = { + bidderCode: 'adsupply', + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + pbjs._bidsRequested.push(bidderRequest); + + window.b367CB268B1094004A3689751E7AC568F['b111'] = window.b367CB268B1094004A3689751E7AC568F['b111'] || {}; + window.b367CB268B1094004A3689751E7AC568F['b111'].Media = { width: 300 }; + pbjs.adSupplyResponseHandler('bidId1'); + + sinon.assert.calledOnce(stubAddBidResponse); + + let bidPlacementCode = stubAddBidResponse.getCall(0).args[0]; + let bidResponse = stubAddBidResponse.getCall(0).args[1]; + expect(bidPlacementCode).to.equal('pc1'); + expect(bidResponse.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); + expect(bidResponse.bidderCode).to.equal('adsupply'); + + pbjs._bidsRequested.pop(); + bidmanager.addBidResponse.restore(); + }); + + it('Fill response', function () { + let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + // adapter needs to be called, in order for the stub to register. + new AdSupplyAdapter(); + + //Zone property is not found + let bidderRequest = { + bidderCode: 'adsupply', + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + pbjs._bidsRequested.push(bidderRequest); + + window.b367CB268B1094004A3689751E7AC568F['b111'] = window.b367CB268B1094004A3689751E7AC568F['b111'] || {}; + window.b367CB268B1094004A3689751E7AC568F['b111'].Media = { Width: 300, Height: 250, Tag: 'Tag', Ecpm: 0.0012 }; + pbjs.adSupplyResponseHandler('bidId1'); + + sinon.assert.calledOnce(stubAddBidResponse); + + let bidPlacementCode = stubAddBidResponse.getCall(0).args[0]; + let bidResponse = stubAddBidResponse.getCall(0).args[1]; + expect(bidPlacementCode).to.equal('pc1'); + expect(bidResponse.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); + expect(bidResponse.bidderCode).to.equal('adsupply'); + + pbjs._bidsRequested.pop(); + bidmanager.addBidResponse.restore(); + }); +}); From 7a0eb8f136297c6cc4056a1a57c7aa31184e03c4 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 24 Apr 2017 18:07:20 +0300 Subject: [PATCH 2/3] Added client Id --- src/adapters/adsupply.js | 26 ++++++----- test/spec/adapters/adsupply_spec.js | 67 +++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/adapters/adsupply.js b/src/adapters/adsupply.js index 68b1fc20b6b..00d630eff5f 100644 --- a/src/adapters/adsupply.js +++ b/src/adapters/adsupply.js @@ -6,7 +6,7 @@ const ADSUPPLY_CODE = 'adsupply'; var AdSupplyAdapter = function AdSupplyAdapter() { function _validateParams(params) { - if (!params || !params.siteId || !params.zoneId || !params.endpointUrl) { + if (!params || !params.siteId || !params.zoneId || !params.endpointUrl || !params.clientId) { return false; } @@ -21,27 +21,26 @@ var AdSupplyAdapter = function AdSupplyAdapter() { var referrerUrl = encodeURIComponent(window.document.referrer); var rand = encodeURIComponent(Math.floor(Math.random() * 100000 + 1)); var time = encodeURIComponent(new Date().getTimezoneOffset()); - return '//' + bid.params.endpointUrl + '/banner.engine?id=' + bid.params.siteId + '&z=' + bid.params.zoneId + '&rand=' + rand + '&ver=async' + '&time=' + time + '&referrerurl=' + referrerUrl + '&abr=false' + '&hbt=1'; + return '//' + bid.params.endpointUrl + '/banner.engine?id=' + bid.params.siteId + '&z=' + bid.params.zoneId + '&rand=' + rand + '&ver=async' + '&time=' + time + '&referrerurl=' + referrerUrl + '&abr=false' + '&hbt=1&cid=' + encodeURIComponent(bid.params.clientId); } $$PREBID_GLOBAL$$.adSupplyResponseHandler = function (bidId) { - var b367CB268B1094004A3689751E7AC568F = window.b367CB268B1094004A3689751E7AC568F || {}; - - if (!bidId || !b367CB268B1094004A3689751E7AC568F) return; + if (!bidId) return; var bidRequest = utils.getBidRequest(bidId); if (!bidRequest || !bidRequest.params) return; + var clientId = bidRequest.params.clientId; var zoneProp = 'b' + bidRequest.params.zoneId; - if (!bidRequest || !b367CB268B1094004A3689751E7AC568F[zoneProp]) return; + if (!window[clientId] || !window[clientId][zoneProp]) return; - var media = b367CB268B1094004A3689751E7AC568F[zoneProp].Media; + var media = window[clientId][zoneProp].Media; if (!media) return; - if (!media.Tag || !media.Ecpm || typeof media.Ecpm !== "number" || media.Ecpm <= 0) { + if (!media.Url || !media.Ecpm || typeof media.Ecpm !== "number" || media.Ecpm <= 0) { var noFillbject = bidfactory.createBid(2, bidRequest); noFillbject.bidderCode = ADSUPPLY_CODE; bidmanager.addBidResponse(bidRequest.placementCode, noFillbject); @@ -49,10 +48,9 @@ var AdSupplyAdapter = function AdSupplyAdapter() { var bidObject = bidfactory.createBid(1, bidRequest); bidObject.bidderCode = ADSUPPLY_CODE; bidObject.cpm = media.Ecpm; - bidObject.ad = media.Tag; + bidObject.ad = ''; bidObject.width = media.Width; bidObject.height = media.Height; - console.log('addBidResponse fill'); bidmanager.addBidResponse(bidRequest.placementCode, bidObject); } }; @@ -64,16 +62,16 @@ var AdSupplyAdapter = function AdSupplyAdapter() { } function _callBids(params) { - window.b367CB268B1094004A3689751E7AC568F = window.b367CB268B1094004A3689751E7AC568F || {}; - var bids = params.bids || []; for (var i = 0; i < bids.length; i++) { var bid = bids[i]; if (!_validateParams(bid.params)) continue; + var clientId = bid.params.clientId; var zoneProp = 'b' + bid.params.zoneId; - window.b367CB268B1094004A3689751E7AC568F[zoneProp] = window.b367CB268B1094004A3689751E7AC568F[zoneProp] || {}; - window.b367CB268B1094004A3689751E7AC568F[zoneProp].Media = {}; + window[clientId] = window[clientId] || {}; + window.window[clientId][zoneProp] = window.window[clientId][zoneProp] || {}; + window.window[clientId][zoneProp].Media = {}; var requestUrl = _getRequestUrl(bid); adloader.loadScript(requestUrl, _makeCallBackHandler(bid.bidId)); diff --git a/test/spec/adapters/adsupply_spec.js b/test/spec/adapters/adsupply_spec.js index 522dfcdc5a5..7c7858b6cb0 100644 --- a/test/spec/adapters/adsupply_spec.js +++ b/test/spec/adapters/adsupply_spec.js @@ -25,6 +25,7 @@ describe('adsupply adapter tests', function () { bidId: 'bidId1', params: { zoneId: 111, + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' } @@ -34,6 +35,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId2', params: { + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', zoneId: 222, siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' @@ -57,6 +59,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId1', params: { + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', zoneId: '111', siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' @@ -67,6 +70,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId2', params: { + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' } @@ -91,6 +95,7 @@ describe('adsupply adapter tests', function () { params: { zoneId: 111, siteId: '', + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', endpointUrl: 'engine.4dsply.com' } }, @@ -100,6 +105,7 @@ describe('adsupply adapter tests', function () { bidId: 'bidId2', params: { zoneId: 222, + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', endpointUrl: 'engine.4dsply.com' } }] @@ -121,6 +127,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId1', params: { + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', zoneId: 111, siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: '' @@ -131,6 +138,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId2', params: { + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', zoneId: 222, siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', } @@ -144,6 +152,40 @@ describe('adsupply adapter tests', function () { adloader.loadScript.restore(); }); + it('clientId is empty and not specified', function () { + let stubLoadScript = sinon.stub(adloader, 'loadScript'); + + let request = { + bids: [{ + placementCode: "pc1", + bidder: "adsupply", + bidId: 'bidId1', + params: { + clientId: '', + zoneId: 111, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }, + { + placementCode: "pc2", + bidder: "adsupply", + bidId: 'bidId2', + params: { + zoneId: 222, + siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', + endpointUrl: 'engine.4dsply.com' + } + }] + }; + + adsupplyAdapter.callBids(request); + + sinon.assert.notCalled(stubLoadScript); + + adloader.loadScript.restore(); + }); + it('parameters are missed', function () { let stubLoadScript = sinon.stub(adloader, 'loadScript'); @@ -162,7 +204,7 @@ describe('adsupply adapter tests', function () { adloader.loadScript.restore(); }); - it('Parameters added to the reuest url', function () { + it('Parameters added to the request url', function () { let stubLoadScript = sinon.stub(adloader, 'loadScript'); let request = { @@ -172,6 +214,7 @@ describe('adsupply adapter tests', function () { bidId: 'bidId1', params: { zoneId: 111, + clientId: 'g32db6906-55f4-42b1-a7d2-7dfaddce96fd', siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' } @@ -185,13 +228,13 @@ describe('adsupply adapter tests', function () { expect(requestUrl).to.contain('0ab16161-a1de-4683-8837-c420bd4387c0'); expect(requestUrl).to.contain('engine.4dsply.com'); expect(requestUrl).to.contain('&hbt=1'); + expect(requestUrl).to.contain('g32db6906-55f4-42b1-a7d2-7dfaddce96fd'); adloader.loadScript.restore(); }); it('Response handler invalid data', function () { let stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - window.b367CB268B1094004A3689751E7AC568F = {}; // adapter needs to be called, in order for the stub to register. new AdSupplyAdapter(); @@ -202,6 +245,7 @@ describe('adsupply adapter tests', function () { // bidRequest object is not found pbjs.adSupplyResponseHandler('bidId1'); + let clientId = 'g5d384afa-c050-4bac-b202-dab8fb06e381'; //Zone property is not found let bidderRequest = { bidderCode: 'adsupply', @@ -210,6 +254,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId1', params: { + clientId: clientId, zoneId: 111, siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' @@ -220,8 +265,8 @@ describe('adsupply adapter tests', function () { pbjs.adSupplyResponseHandler('bidId1'); //Media is not found - window.b367CB268B1094004A3689751E7AC568F = window.b367CB268B1094004A3689751E7AC568F || {}; - window.b367CB268B1094004A3689751E7AC568F['b111'] = window.b367CB268B1094004A3689751E7AC568F['b111'] || {}; + window[clientId] = window[clientId] || {}; + window[clientId]['b111'] = window[clientId]['b111'] || {}; pbjs.adSupplyResponseHandler('bidId1'); sinon.assert.notCalled(stubAddBidResponse); @@ -235,6 +280,7 @@ describe('adsupply adapter tests', function () { // adapter needs to be called, in order for the stub to register. new AdSupplyAdapter(); + let clientId = 'g5d384afa-c050-4bac-b202-dab8fb06e381'; //Zone property is not found let bidderRequest = { bidderCode: 'adsupply', @@ -243,6 +289,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId1', params: { + clientId: clientId, zoneId: 111, siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' @@ -252,8 +299,9 @@ describe('adsupply adapter tests', function () { pbjs._bidsRequested.push(bidderRequest); - window.b367CB268B1094004A3689751E7AC568F['b111'] = window.b367CB268B1094004A3689751E7AC568F['b111'] || {}; - window.b367CB268B1094004A3689751E7AC568F['b111'].Media = { width: 300 }; + window[clientId] = window[clientId] || {}; + window[clientId]['b111'] = window[clientId]['b111'] || {}; + window[clientId]['b111'].Media = { width: 300 }; pbjs.adSupplyResponseHandler('bidId1'); sinon.assert.calledOnce(stubAddBidResponse); @@ -273,6 +321,7 @@ describe('adsupply adapter tests', function () { // adapter needs to be called, in order for the stub to register. new AdSupplyAdapter(); + let clientId = 'g5d384afa-c050-4bac-b202-dab8fb06e381'; //Zone property is not found let bidderRequest = { bidderCode: 'adsupply', @@ -281,6 +330,7 @@ describe('adsupply adapter tests', function () { bidder: "adsupply", bidId: 'bidId1', params: { + clientId: clientId, zoneId: 111, siteId: '0ab16161-a1de-4683-8837-c420bd4387c0', endpointUrl: 'engine.4dsply.com' @@ -290,8 +340,9 @@ describe('adsupply adapter tests', function () { pbjs._bidsRequested.push(bidderRequest); - window.b367CB268B1094004A3689751E7AC568F['b111'] = window.b367CB268B1094004A3689751E7AC568F['b111'] || {}; - window.b367CB268B1094004A3689751E7AC568F['b111'].Media = { Width: 300, Height: 250, Tag: 'Tag', Ecpm: 0.0012 }; + window[clientId] = window[clientId] || {}; + window[clientId]['b111'] = window[clientId]['b111'] || {}; + window[clientId]['b111'].Media = { Width: 300, Height: 250, Url: '/Redirect.engine', Ecpm: 0.0012 }; pbjs.adSupplyResponseHandler('bidId1'); sinon.assert.calledOnce(stubAddBidResponse); From f7be41a03892e72015ad5c680944a436b5e2fd6e Mon Sep 17 00:00:00 2001 From: mstrukov Date: Tue, 2 May 2017 14:00:36 +0300 Subject: [PATCH 3/3] Fixed code review comments --- src/adapters/adsupply.js | 6 +++--- test/spec/adapters/adsupply_spec.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adapters/adsupply.js b/src/adapters/adsupply.js index 00d630eff5f..d6c3cda6334 100644 --- a/src/adapters/adsupply.js +++ b/src/adapters/adsupply.js @@ -10,7 +10,7 @@ var AdSupplyAdapter = function AdSupplyAdapter() { return false; } - if (typeof params.zoneId !== "number" || params.zoneId <= 0) { + if (typeof params.zoneId !== 'number' || params.zoneId <= 0) { return false; } @@ -40,7 +40,7 @@ var AdSupplyAdapter = function AdSupplyAdapter() { if (!media) return; - if (!media.Url || !media.Ecpm || typeof media.Ecpm !== "number" || media.Ecpm <= 0) { + if (!media.Url || !media.Ecpm || typeof media.Ecpm !== 'number' || media.Ecpm <= 0) { var noFillbject = bidfactory.createBid(2, bidRequest); noFillbject.bidderCode = ADSUPPLY_CODE; bidmanager.addBidResponse(bidRequest.placementCode, noFillbject); @@ -83,4 +83,4 @@ var AdSupplyAdapter = function AdSupplyAdapter() { }; }; -module.exports = AdSupplyAdapter; \ No newline at end of file +module.exports = AdSupplyAdapter; diff --git a/test/spec/adapters/adsupply_spec.js b/test/spec/adapters/adsupply_spec.js index 7c7858b6cb0..0798f9821d7 100644 --- a/test/spec/adapters/adsupply_spec.js +++ b/test/spec/adapters/adsupply_spec.js @@ -1,7 +1,7 @@ describe('adsupply adapter tests', function () { const expect = require('chai').expect; - const assert = require('chai').assert; + const AdSupplyAdapter = require('../../../src/adapters/adsupply'); const adloader = require('../../../src/adloader'); const bidmanager = require('../../../src/bidmanager');