From 9edcb2b9148429dfcd2be5737b711414f0866b1b Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Tue, 23 Aug 2016 14:36:37 +0300 Subject: [PATCH 01/10] Add centro adapter and tests for it. --- adapters.json | 1 + src/adapters/centro.js | 120 ++++++++++++++++ test/spec/adapters/centro_spec.js | 228 ++++++++++++++++++++++++++++++ 3 files changed, 349 insertions(+) create mode 100644 src/adapters/centro.js create mode 100644 test/spec/adapters/centro_spec.js diff --git a/adapters.json b/adapters.json index b0e5e41d1a9..45d80f34432 100644 --- a/adapters.json +++ b/adapters.json @@ -24,6 +24,7 @@ "jcm", "underdogmedia", "memeglobal", + "centro", { "appnexus": { "alias": "brealtime" diff --git a/src/adapters/centro.js b/src/adapters/centro.js new file mode 100644 index 00000000000..7e7dc100c77 --- /dev/null +++ b/src/adapters/centro.js @@ -0,0 +1,120 @@ +var utils = require('../utils.js'); +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader'); + +var CentroAdapter = function CentroAdapter() { + var baseUrl = '//t.brand-server.com/hb', + devUrl = '//staging.brand-server.com/hb', + bidderCode = 'centro', + handlerPrefix = 'adCentroHandler_', + + LOG_ERROR_MESS = { + noUnit: 'Bid has no unit', + noAdTag: 'Bid has missmatch format.', + noBid: 'Response has no bid.', + anotherCode: 'Bid has another bidderCode - ', + undefBid: 'Bid is undefined', + unitNum: 'Requested unit is ' + }; + + function _makeHandler(handlerName, unit, placementCode) { + return function(response){ + try { + delete window[handlerName]; + } catch(err) {//catching for old IE + window[handlerName] = undefined; + } + _responseProcessing(response, unit, placementCode); + }; + } + + function _sendBidRequest(bid) { + var placementCode = bid.placementCode, + size = bid.sizes && bid.sizes[0]; + + bid = bid.params; + if (!bid.unit) { + //throw exception, or call utils.logError + utils.logError(LOG_ERROR_MESS.noUnit, bidderCode); + return; + } + var query = ['s=' + bid.unit];//,'url=www.abc15.com','sz=320x50']; + var isDev = bid.unit.toString() === '28136'; + + if (bid.page_url) { + query.push('url=' + encodeURIComponent(bid.page_url)); + } + //check size format + if ( + size instanceof Array && + size.length===2 && + typeof size[0] === 'number' && + typeof size[1] === 'number' + ) { + query.push('sz=' + size.join('x')); + } + //make handler name for JSONP request + var handlerName = handlerPrefix + bid.unit + size.join('x'); + query.push('callback=' + handlerName); + + //maybe is needed add some random parameter to disable cache + //query.push('r='+Math.round(Math.random() * 1e5)); + + window[handlerName] = _makeHandler(handlerName, bid.unit, placementCode); + + adloader.loadScript((document.location.protocol === 'https:'? 'https:' : 'http:') + (isDev? devUrl : baseUrl) + '?' + query.join('&')); + } + + /* + "sectionID": 7302, + "height": 250, + "width": 300, + "value": 3.2, + "adTag":'' + */ + function _responseProcessing(resp, unit, placementCode) { + var bidObject; + var bid = resp && resp.bid || resp; + + if (bid && bid.adTag && bid.sectionID === unit) { + bidObject = bidfactory.createBid(1); + bidObject.cpm = bid.value; + bidObject.ad = bid.adTag; + bidObject.width = bid.width; + bidObject.height = bid.height; + } else { + //throw exception, or call utils.logError with resp.statusMessage + utils.logError(LOG_ERROR_MESS.unitNum + unit + '. ' + (bid? bid.statusMessage || LOG_ERROR_MESS.noAdTag : LOG_ERROR_MESS.noBid), bidderCode); + bidObject = bidfactory.createBid(2); + } + bidObject.bidderCode = bidderCode; + bidmanager.addBidResponse(placementCode, bidObject); + } + + /* + { + bidderCode: "centro", + bids: [ + { + unit: '3242432', + page_url: "http://", + size: [300, 250] + */ + function _callBids(params) { + var bid, bids = params.bids || []; + for (var i = 0; i < bids.length; i++) { + bid = bids[i]; + if (bid && bid.bidder === bidderCode) { + _sendBidRequest(bid); + } + } + } + + return { + callBids: _callBids + }; +}; + + +module.exports = CentroAdapter; diff --git a/test/spec/adapters/centro_spec.js b/test/spec/adapters/centro_spec.js new file mode 100644 index 00000000000..68b80c58107 --- /dev/null +++ b/test/spec/adapters/centro_spec.js @@ -0,0 +1,228 @@ +describe('centro adapter tests', function () { + var expect = require('chai').expect; + var assert = require('chai').assert; + var urlParse = require('url-parse'); + var querystringify = require('querystringify'); + + var adapter = require('src/adapters/centro'); + var bidmanager = require('src/bidmanager'); + var adLoader = require('src/adloader'); + var utils = require('src/utils'); + + window.pbjs = window.pbjs || {}; + if (typeof(pbjs)==="undefined"){ + var pbjs = window.pbjs; + } + + var spyLoadScript; + beforeEach(function () { + spyLoadScript = sinon.spy(adLoader, 'loadScript'); + }); + + afterEach(function () { + spyLoadScript.restore(); + }); + + var logErrorSpy; + beforeEach(function () { + logErrorSpy = sinon.spy(utils, 'logError'); + }); + + afterEach(function () { + logErrorSpy.restore(); + }); + + describe('creation of bid url', function () { + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = []; + } + + it('should fix parameter name', function () { + + var params = { + bidderCode: 'centro', + bids: [ + { + bidder: 'centro', + sizes: [[300, 250]], + params: { + unit: 28136, + page_url: 'http://test_url.ru' + }, + placementCode: 'div-gpt-ad-12345-1' + }, + { + bidder: 'centro', + sizes: [[728, 90]], + params: { + unit: 28137 + }, + placementCode: 'div-gpt-ad-12345-2' + }, + { + bidder: 'centro', + sizes: [[728, 90]], + params: {}, + placementCode: 'div-gpt-ad-12345-3' + } + ] + }; + + adapter().callBids(params); + var bidUrl1 = spyLoadScript.getCall(0).args[0]; + var bidUrl2 = spyLoadScript.getCall(1).args[0]; + + sinon.assert.calledWith(logErrorSpy, 'Bid has no unit', 'centro'); + sinon.assert.calledWith(spyLoadScript, bidUrl1); + + var parsedBidUrl = urlParse(bidUrl1); + var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); + var generatedCallback = 'adCentroHandler_28136300x250'; + + expect(parsedBidUrl.hostname).to.equal('staging.brand-server.com'); + expect(parsedBidUrl.pathname).to.equal('/hb'); + + expect(parsedBidUrlQueryString).to.have.property('s').and.to.equal('28136'); + expect(parsedBidUrlQueryString).to.have.property('url').and.to.equal('http://test_url.ru'); + expect(parsedBidUrlQueryString).to.have.property('sz').and.to.equal('300x250'); + expect(parsedBidUrlQueryString).to.have.property('callback').and.to.equal(generatedCallback); + + sinon.assert.calledWith(spyLoadScript, bidUrl2); + + parsedBidUrl = urlParse(bidUrl2); + parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); + generatedCallback = 'adCentroHandler_28137728x90'; + + expect(parsedBidUrl.hostname).to.equal('t.brand-server.com'); + expect(parsedBidUrl.pathname).to.equal('/hb'); + + expect(parsedBidUrlQueryString).to.have.property('s').and.to.equal('28137'); + expect(parsedBidUrlQueryString).to.not.have.property('url'); + expect(parsedBidUrlQueryString).to.have.property('sz').and.to.equal('728x90'); + expect(parsedBidUrlQueryString).to.have.property('callback').and.to.equal(generatedCallback); + }); + + }); + + describe('handling of the callback response', function () { + if (typeof(pbjs._bidsReceived)==="undefined"){ + pbjs._bidsReceived = []; + } + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = []; + } + if (typeof(pbjs._adsReceived)==="undefined"){ + pbjs._adsReceived = []; + } + + var params = { + bidderCode: 'centro', + bids: [ + { + bidder: 'centro', + sizes: [[300, 250]], + params: { + unit: 28136 + }, + placementCode: '/19968336/header-bid-tag-0' + }, + { + bidder: 'centro', + sizes: [[728, 90]], + params: { + unit: 111111 + }, + placementCode: '/19968336/header-bid-tag-1' + }, + { + bidder: 'centro', + sizes: [[728, 90]], + params: { + unit: 222222 + }, + placementCode: '/19968336/header-bid-tag-2' + }, + { + bidder: 'centro', + sizes: [[728, 90]], + params: { + unit: 333333 + }, + placementCode: '/19968336/header-bid-tag-3' + } + ] + }; + + it('callback function should exist', function () { + + adapter().callBids(params); + + expect(window['adCentroHandler_28136300x250']).to.exist.and.to.be.a('function'); + expect(window['adCentroHandler_111111728x90']).to.exist.and.to.be.a('function'); + }); + + it('bidmanager.addBidResponse should be called with correct arguments', function () { + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + adapter().callBids(params); + + var adUnits = new Array(); + var unit = new Object(); + unit.bids = params.bids; + unit.code = '/19968336/header-bid-tag'; + unit.sizes=[[300,250],[728,90]]; + adUnits.push(unit); + + if (typeof(pbjs._bidsRequested)==="undefined"){ + pbjs._bidsRequested = [params]; + } + else{ + pbjs._bidsRequested.push(params); + } + + pbjs.adUnits = adUnits; + + var response = {"adTag":"
test content
","statusMessage":"Bid available","height":250,"_comment":"","value":0.2,"width":300,"sectionID":28136}; + var response2 = {"adTag":"","statusMessage":"No bid.","height":0,"value":0,"width":0,"sectionID":111111}; + var response3 = {"adTag":"","height":0,"value":0,"width":0,"sectionID":222222}; + var response4 = ''; + + window['adCentroHandler_28136300x250'](response); + window['adCentroHandler_111111728x90'](response2); + window['adCentroHandler_222222728x90'](response3); + window['adCentroHandler_333333728x90'](response4); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + var bidPlacementCode2 = stubAddBidResponse.getCall(1).args[0]; + var bidObject2 = stubAddBidResponse.getCall(1).args[1]; + var bidPlacementCode3 = stubAddBidResponse.getCall(2).args[0]; + var bidObject3 = stubAddBidResponse.getCall(2).args[1]; + var bidPlacementCode4 = stubAddBidResponse.getCall(3).args[0]; + var bidObject4 = stubAddBidResponse.getCall(3).args[1]; + + expect(logErrorSpy.getCall(0).args[0]).to.equal('Requested unit is 111111. No bid.'); + expect(logErrorSpy.getCall(1).args[0]).to.equal('Requested unit is 222222. Bid has missmatch format.'); + expect(logErrorSpy.getCall(2).args[0]).to.equal('Requested unit is 333333. Response has no bid.'); + + expect(bidPlacementCode1).to.equal('/19968336/header-bid-tag-0'); + expect(bidObject1.cpm).to.equal(0.2); + expect(bidObject1.ad).to.equal('
test content
'); + expect(bidObject1.width).to.equal(300); + expect(bidObject1.height).to.equal(250); + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.bidderCode).to.equal('centro'); + + expect(bidPlacementCode2).to.equal('/19968336/header-bid-tag-1'); + expect(bidObject2.getStatusCode()).to.equal(2); + expect(bidPlacementCode3).to.equal('/19968336/header-bid-tag-2'); + expect(bidObject3.getStatusCode()).to.equal(2); + expect(bidPlacementCode4).to.equal('/19968336/header-bid-tag-3'); + expect(bidObject4.getStatusCode()).to.equal(2); + + stubAddBidResponse.restore(); + }); + }); +}); \ No newline at end of file From 47c74aad877a51f64a04abc165c405dfb15f61f2 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Thu, 16 Feb 2017 16:02:13 +0300 Subject: [PATCH 02/10] fix bug with different types of bid.sectionID and bid.unit from config --- src/adapters/centro.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index 7e7dc100c77..8d51ca7e1f3 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -55,7 +55,7 @@ var CentroAdapter = function CentroAdapter() { query.push('sz=' + size.join('x')); } //make handler name for JSONP request - var handlerName = handlerPrefix + bid.unit + size.join('x'); + var handlerName = handlerPrefix + bid.unit + size.join('x') + Math.round(Math.random() * 1000); query.push('callback=' + handlerName); //maybe is needed add some random parameter to disable cache @@ -77,7 +77,7 @@ var CentroAdapter = function CentroAdapter() { var bidObject; var bid = resp && resp.bid || resp; - if (bid && bid.adTag && bid.sectionID === unit) { + if (bid && bid.adTag && bid.sectionID == unit) { bidObject = bidfactory.createBid(1); bidObject.cpm = bid.value; bidObject.ad = bid.adTag; From d0ca7a0dec8a237c1dbc77e0f6ff3227b1acf0c4 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Thu, 16 Feb 2017 16:21:22 +0300 Subject: [PATCH 03/10] add query parameter adapter=prebid --- src/adapters/centro.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index 8d51ca7e1f3..1a2443cfc14 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -39,7 +39,7 @@ var CentroAdapter = function CentroAdapter() { utils.logError(LOG_ERROR_MESS.noUnit, bidderCode); return; } - var query = ['s=' + bid.unit];//,'url=www.abc15.com','sz=320x50']; + var query = ['s=' + bid.unit, 'adapter=prebid'];//,'url=www.abc15.com','sz=320x50']; var isDev = bid.unit.toString() === '28136'; if (bid.page_url) { From 8a092fee9db0188883a406cc492b9b63b009df0c Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Thu, 16 Feb 2017 17:18:36 +0300 Subject: [PATCH 04/10] update tests for centro adapter --- src/adapters/centro.js | 8 +++----- test/spec/adapters/centro_spec.js | 20 +++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index 1a2443cfc14..cad9dc7713b 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -42,9 +42,7 @@ var CentroAdapter = function CentroAdapter() { var query = ['s=' + bid.unit, 'adapter=prebid'];//,'url=www.abc15.com','sz=320x50']; var isDev = bid.unit.toString() === '28136'; - if (bid.page_url) { - query.push('url=' + encodeURIComponent(bid.page_url)); - } + query.push('url=' + encodeURIComponent(bid.page_url || location.href)); //check size format if ( size instanceof Array && @@ -55,7 +53,7 @@ var CentroAdapter = function CentroAdapter() { query.push('sz=' + size.join('x')); } //make handler name for JSONP request - var handlerName = handlerPrefix + bid.unit + size.join('x') + Math.round(Math.random() * 1000); + var handlerName = handlerPrefix + bid.unit + size.join('x') + encodeURIComponent(placementCode); query.push('callback=' + handlerName); //maybe is needed add some random parameter to disable cache @@ -77,7 +75,7 @@ var CentroAdapter = function CentroAdapter() { var bidObject; var bid = resp && resp.bid || resp; - if (bid && bid.adTag && bid.sectionID == unit) { + if (bid && bid.adTag && bid.sectionID && bid.sectionID.toString() === unit.toString()) { bidObject = bidfactory.createBid(1); bidObject.cpm = bid.value; bidObject.ad = bid.adTag; diff --git a/test/spec/adapters/centro_spec.js b/test/spec/adapters/centro_spec.js index a3a8f184e92..abc83f6c603 100644 --- a/test/spec/adapters/centro_spec.js +++ b/test/spec/adapters/centro_spec.js @@ -78,7 +78,7 @@ describe('centro adapter tests', function () { var parsedBidUrl = urlParse(bidUrl1); var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - var generatedCallback = 'adCentroHandler_28136300x250'; + var generatedCallback = 'adCentroHandler_28136300x250div-gpt-ad-12345-1'; expect(parsedBidUrl.hostname).to.equal('staging.brand-server.com'); expect(parsedBidUrl.pathname).to.equal('/hb'); @@ -92,13 +92,13 @@ describe('centro adapter tests', function () { parsedBidUrl = urlParse(bidUrl2); parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - generatedCallback = 'adCentroHandler_28137728x90'; + generatedCallback = 'adCentroHandler_28137728x90div-gpt-ad-12345-2'; expect(parsedBidUrl.hostname).to.equal('t.brand-server.com'); expect(parsedBidUrl.pathname).to.equal('/hb'); expect(parsedBidUrlQueryString).to.have.property('s').and.to.equal('28137'); - expect(parsedBidUrlQueryString).to.not.have.property('url'); + expect(parsedBidUrlQueryString).to.have.property('url').and.to.equal(location.href); expect(parsedBidUrlQueryString).to.have.property('sz').and.to.equal('728x90'); expect(parsedBidUrlQueryString).to.have.property('callback').and.to.equal(generatedCallback); }); @@ -158,8 +158,10 @@ describe('centro adapter tests', function () { adapter().callBids(params); - expect(window['adCentroHandler_28136300x250']).to.exist.and.to.be.a('function'); - expect(window['adCentroHandler_111111728x90']).to.exist.and.to.be.a('function'); + expect(window['adCentroHandler_28136300x250%2F19968336%2Fheader-bid-tag-0']) + .to.exist.and.to.be.a('function'); + expect(window['adCentroHandler_111111728x90%2F19968336%2Fheader-bid-tag-1']) + .to.exist.and.to.be.a('function'); }); it('bidmanager.addBidResponse should be called with correct arguments', function () { @@ -189,10 +191,10 @@ describe('centro adapter tests', function () { var response3 = {"adTag":"","height":0,"value":0,"width":0,"sectionID":222222}; var response4 = ''; - window['adCentroHandler_28136300x250'](response); - window['adCentroHandler_111111728x90'](response2); - window['adCentroHandler_222222728x90'](response3); - window['adCentroHandler_333333728x90'](response4); + window['adCentroHandler_28136300x250%2F19968336%2Fheader-bid-tag-0'](response); + window['adCentroHandler_111111728x90%2F19968336%2Fheader-bid-tag-1'](response2); + window['adCentroHandler_222222728x90%2F19968336%2Fheader-bid-tag-2'](response3); + window['adCentroHandler_333333728x90%2F19968336%2Fheader-bid-tag-3'](response4); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1]; From c3a9704ddc4b5b37f7d3cb8d161273c8431fadee Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Thu, 23 Mar 2017 14:58:09 +0300 Subject: [PATCH 05/10] fixed bug with call of JSONP callback with name, that contain invalid characters --- src/adapters/centro.js | 2 +- test/spec/adapters/centro_spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index cad9dc7713b..85303afc823 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -54,7 +54,7 @@ var CentroAdapter = function CentroAdapter() { } //make handler name for JSONP request var handlerName = handlerPrefix + bid.unit + size.join('x') + encodeURIComponent(placementCode); - query.push('callback=' + handlerName); + query.push('callback=' + encodeURIComponent('window["' + handlerName + '"]')); //maybe is needed add some random parameter to disable cache //query.push('r='+Math.round(Math.random() * 1e5)); diff --git a/test/spec/adapters/centro_spec.js b/test/spec/adapters/centro_spec.js index abc83f6c603..a3f186fad65 100644 --- a/test/spec/adapters/centro_spec.js +++ b/test/spec/adapters/centro_spec.js @@ -78,7 +78,7 @@ describe('centro adapter tests', function () { var parsedBidUrl = urlParse(bidUrl1); var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - var generatedCallback = 'adCentroHandler_28136300x250div-gpt-ad-12345-1'; + var generatedCallback = 'window["adCentroHandler_28136300x250div-gpt-ad-12345-1"]'; expect(parsedBidUrl.hostname).to.equal('staging.brand-server.com'); expect(parsedBidUrl.pathname).to.equal('/hb'); @@ -92,7 +92,7 @@ describe('centro adapter tests', function () { parsedBidUrl = urlParse(bidUrl2); parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - generatedCallback = 'adCentroHandler_28137728x90div-gpt-ad-12345-2'; + generatedCallback = 'window["adCentroHandler_28137728x90div-gpt-ad-12345-2"]'; expect(parsedBidUrl.hostname).to.equal('t.brand-server.com'); expect(parsedBidUrl.pathname).to.equal('/hb'); From 4c134fbe57f8c7309fa94d700265b37187c02f81 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Mon, 5 Jun 2017 17:46:00 +0300 Subject: [PATCH 06/10] Centro adapter fix: do not call logError if 'No Bid' was received --- src/adapters/centro.js | 16 ++++++++++------ test/spec/adapters/centro_spec.js | 7 +++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index 903d475d712..aded86f9953 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -75,12 +75,16 @@ var CentroAdapter = function CentroAdapter() { var bidObject; var bid = resp && resp.bid || resp; - if (bid && bid.adTag && bid.sectionID && bid.sectionID.toString() === unit.toString()) { - bidObject = bidfactory.createBid(1); - bidObject.cpm = bid.value; - bidObject.ad = bid.adTag; - bidObject.width = bid.width; - bidObject.height = bid.height; + if (bid && (bid.adTag || bid.statusMessage === 'No bid') && bid.sectionID && bid.sectionID.toString() === unit.toString()) { + if (bid.adTag) { + bidObject = bidfactory.createBid(1); + bidObject.cpm = bid.value; + bidObject.ad = bid.adTag; + bidObject.width = bid.width; + bidObject.height = bid.height; + } else { + bidObject = bidfactory.createBid(2); + } } else { // throw exception, or call utils.logError with resp.statusMessage utils.logError(LOG_ERROR_MESS.unitNum + unit + '. ' + (bid ? bid.statusMessage || LOG_ERROR_MESS.noAdTag : LOG_ERROR_MESS.noBid), bidderCode); diff --git a/test/spec/adapters/centro_spec.js b/test/spec/adapters/centro_spec.js index 73dcf287ff0..5c98dc2ff03 100644 --- a/test/spec/adapters/centro_spec.js +++ b/test/spec/adapters/centro_spec.js @@ -181,7 +181,7 @@ describe('centro adapter tests', function () { pbjs.adUnits = adUnits; var response = {'adTag': '
test content
', 'statusMessage': 'Bid available', 'height': 250, '_comment': '', 'value': 0.2, 'width': 300, 'sectionID': 28136}; - var response2 = {'adTag': '', 'statusMessage': 'No bid.', 'height': 0, 'value': 0, 'width': 0, 'sectionID': 111111}; + var response2 = {'adTag': '', 'statusMessage': 'No bid', 'height': 0, 'value': 0, 'width': 0, 'sectionID': 111111}; var response3 = {'adTag': '', 'height': 0, 'value': 0, 'width': 0, 'sectionID': 222222}; var response4 = ''; @@ -199,9 +199,8 @@ describe('centro adapter tests', function () { var bidPlacementCode4 = stubAddBidResponse.getCall(3).args[0]; var bidObject4 = stubAddBidResponse.getCall(3).args[1]; - expect(logErrorSpy.getCall(0).args[0]).to.equal('Requested unit is 111111. No bid.'); - expect(logErrorSpy.getCall(1).args[0]).to.equal('Requested unit is 222222. Bid has missmatch format.'); - expect(logErrorSpy.getCall(2).args[0]).to.equal('Requested unit is 333333. Response has no bid.'); + expect(logErrorSpy.getCall(0).args[0]).to.equal('Requested unit is 222222. Bid has missmatch format.'); + expect(logErrorSpy.getCall(1).args[0]).to.equal('Requested unit is 333333. Response has no bid.'); expect(bidPlacementCode1).to.equal('/19968336/header-bid-tag-0'); expect(bidObject1.cpm).to.equal(0.2); From 8d70cc032a6239ab239c83a0e418de7d8ae0a71e Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Thu, 15 Jun 2017 15:31:03 +0300 Subject: [PATCH 07/10] Centro adapter: pass the bid request object to bidfactory.createBid --- src/adapters/centro.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index aded86f9953..997fa39cb2e 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -18,22 +18,21 @@ var CentroAdapter = function CentroAdapter() { unitNum: 'Requested unit is ' }; - function _makeHandler(handlerName, unit, placementCode) { + function _makeHandler(handlerName, unit, requestedBid) { return function(response) { try { delete window[handlerName]; } catch (err) { // catching for old IE window[handlerName] = undefined; } - _responseProcessing(response, unit, placementCode); + _responseProcessing(response, unit, requestedBid); }; } - function _sendBidRequest(bid) { - var placementCode = bid.placementCode, - size = bid.sizes && bid.sizes[0]; + function _sendBidRequest(requestedBid) { + var bid, size = requestedBid.sizes && requestedBid.sizes[0]; - bid = bid.params; + bid = requestedBid.params; if (!bid.unit) { // throw exception, or call utils.logError utils.logError(LOG_ERROR_MESS.noUnit, bidderCode); @@ -53,13 +52,13 @@ var CentroAdapter = function CentroAdapter() { query.push('sz=' + size.join('x')); } // make handler name for JSONP request - var handlerName = handlerPrefix + bid.unit + size.join('x') + encodeURIComponent(placementCode); + var handlerName = handlerPrefix + bid.unit + size.join('x') + encodeURIComponent(requestedBid.placementCode); query.push('callback=' + encodeURIComponent('window["' + handlerName + '"]')); // maybe is needed add some random parameter to disable cache // query.push('r='+Math.round(Math.random() * 1e5)); - window[handlerName] = _makeHandler(handlerName, bid.unit, placementCode); + window[handlerName] = _makeHandler(handlerName, bid.unit, requestedBid); adloader.loadScript((document.location.protocol === 'https:' ? 'https:' : 'http:') + (isDev ? devUrl : baseUrl) + '?' + query.join('&')); } @@ -71,27 +70,26 @@ var CentroAdapter = function CentroAdapter() { "value": 3.2, "adTag":'' */ - function _responseProcessing(resp, unit, placementCode) { + function _responseProcessing(resp, unit, requestedBid) { var bidObject; var bid = resp && resp.bid || resp; if (bid && (bid.adTag || bid.statusMessage === 'No bid') && bid.sectionID && bid.sectionID.toString() === unit.toString()) { if (bid.adTag) { - bidObject = bidfactory.createBid(1); + bidObject = bidfactory.createBid(1, requestedBid); bidObject.cpm = bid.value; bidObject.ad = bid.adTag; bidObject.width = bid.width; bidObject.height = bid.height; } else { - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(2, requestedBid); } } else { // throw exception, or call utils.logError with resp.statusMessage utils.logError(LOG_ERROR_MESS.unitNum + unit + '. ' + (bid ? bid.statusMessage || LOG_ERROR_MESS.noAdTag : LOG_ERROR_MESS.noBid), bidderCode); - bidObject = bidfactory.createBid(2); + bidObject = bidfactory.createBid(2, requestedBid); } - bidObject.bidderCode = bidderCode; - bidmanager.addBidResponse(placementCode, bidObject); + bidmanager.addBidResponse(requestedBid.placementCode, bidObject); } /* From 52b0021940d27b6b01f2e4170770001c153992dc Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Thu, 15 Jun 2017 15:46:02 +0300 Subject: [PATCH 08/10] Centro adapter: fix ESLintError --- src/adapters/centro.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/centro.js b/src/adapters/centro.js index 997fa39cb2e..b1b2b3c7a01 100644 --- a/src/adapters/centro.js +++ b/src/adapters/centro.js @@ -30,7 +30,7 @@ var CentroAdapter = function CentroAdapter() { } function _sendBidRequest(requestedBid) { - var bid, size = requestedBid.sizes && requestedBid.sizes[0]; + var bid, size = requestedBid.sizes && requestedBid.sizes[0]; bid = requestedBid.params; if (!bid.unit) { From c95f9b18e0c70cb3ddefb60b2d0c0556652ec718 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Mon, 23 Oct 2017 12:10:16 +0300 Subject: [PATCH 09/10] Fix Centro adapter to allow requests of the same units --- modules/centroBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/centroBidAdapter.js b/modules/centroBidAdapter.js index 9cd3ec004fa..34162f8d1ec 100644 --- a/modules/centroBidAdapter.js +++ b/modules/centroBidAdapter.js @@ -54,7 +54,7 @@ var CentroAdapter = function CentroAdapter() { query.push('sz=' + size.join('x')); } // make handler name for JSONP request - var handlerName = handlerPrefix + bid.unit + size.join('x') + encodeURIComponent(requestedBid.placementCode); + var handlerName = handlerPrefix + bid.unit + size.join('x') + encodeURIComponent(requestedBid.bidId); query.push('callback=' + encodeURIComponent('window["' + handlerName + '"]')); // maybe is needed add some random parameter to disable cache From e311ea7140ac6fb97e4e2bd894a96b4c3f8b21f4 Mon Sep 17 00:00:00 2001 From: Nikolay Sokolov Date: Tue, 24 Oct 2017 19:38:52 +0300 Subject: [PATCH 10/10] Fix spec file for Centro adapter --- test/spec/modules/centroBidAdapter_spec.js | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/test/spec/modules/centroBidAdapter_spec.js b/test/spec/modules/centroBidAdapter_spec.js index 9f354e1ba56..a4bceb5de39 100644 --- a/test/spec/modules/centroBidAdapter_spec.js +++ b/test/spec/modules/centroBidAdapter_spec.js @@ -43,6 +43,7 @@ describe('centro adapter tests', function () { unit: 28136, page_url: 'http://test_url.ru' }, + bidId: '1234', placementCode: 'div-gpt-ad-12345-1' }, { @@ -51,12 +52,14 @@ describe('centro adapter tests', function () { params: { unit: 28137 }, + bidId: '5678', placementCode: 'div-gpt-ad-12345-2' }, { bidder: 'centro', sizes: [[728, 90]], params: {}, + bidId: '9101112', placementCode: 'div-gpt-ad-12345-3' } ] @@ -71,7 +74,7 @@ describe('centro adapter tests', function () { var parsedBidUrl = urlParse(bidUrl1); var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - var generatedCallback = 'window["adCentroHandler_28136300x250div-gpt-ad-12345-1"]'; + var generatedCallback = 'window["adCentroHandler_28136300x2501234"]'; expect(parsedBidUrl.hostname).to.equal('staging.brand-server.com'); expect(parsedBidUrl.pathname).to.equal('/hb'); @@ -85,7 +88,7 @@ describe('centro adapter tests', function () { parsedBidUrl = urlParse(bidUrl2); parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - generatedCallback = 'window["adCentroHandler_28137728x90div-gpt-ad-12345-2"]'; + generatedCallback = 'window["adCentroHandler_28137728x905678"]'; expect(parsedBidUrl.hostname).to.equal('t.brand-server.com'); expect(parsedBidUrl.pathname).to.equal('/hb'); @@ -117,6 +120,7 @@ describe('centro adapter tests', function () { params: { unit: 28136 }, + bidId: '12345', placementCode: '/19968336/header-bid-tag-0' }, { @@ -125,6 +129,7 @@ describe('centro adapter tests', function () { params: { unit: 111111 }, + bidId: '12346', placementCode: '/19968336/header-bid-tag-1' }, { @@ -133,6 +138,7 @@ describe('centro adapter tests', function () { params: { unit: 222222 }, + bidId: '12347', placementCode: '/19968336/header-bid-tag-2' }, { @@ -141,6 +147,7 @@ describe('centro adapter tests', function () { params: { unit: 333333 }, + bidId: '12348', placementCode: '/19968336/header-bid-tag-3' } ] @@ -149,9 +156,9 @@ describe('centro adapter tests', function () { it('callback function should exist', function () { adapter().callBids(params); - expect(window['adCentroHandler_28136300x250%2F19968336%2Fheader-bid-tag-0']) + expect(window['adCentroHandler_28136300x25012345']) .to.exist.and.to.be.a('function'); - expect(window['adCentroHandler_111111728x90%2F19968336%2Fheader-bid-tag-1']) + expect(window['adCentroHandler_111111728x9012346']) .to.exist.and.to.be.a('function'); }); @@ -180,10 +187,10 @@ describe('centro adapter tests', function () { var response3 = {'adTag': '', 'height': 0, 'value': 0, 'width': 0, 'sectionID': 222222}; var response4 = ''; - window['adCentroHandler_28136300x250%2F19968336%2Fheader-bid-tag-0'](response); - window['adCentroHandler_111111728x90%2F19968336%2Fheader-bid-tag-1'](response2); - window['adCentroHandler_222222728x90%2F19968336%2Fheader-bid-tag-2'](response3); - window['adCentroHandler_333333728x90%2F19968336%2Fheader-bid-tag-3'](response4); + window['adCentroHandler_28136300x25012345'](response); + window['adCentroHandler_111111728x9012346'](response2); + window['adCentroHandler_222222728x9012347'](response3); + window['adCentroHandler_333333728x9012348'](response4); var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; var bidObject1 = stubAddBidResponse.getCall(0).args[1];