Skip to content

Commit

Permalink
Fix Centro adapter to allow requests of the same units (#1746)
Browse files Browse the repository at this point in the history
* Add centro adapter and tests for it.

* fix bug with different types of bid.sectionID and bid.unit from config

* add query parameter adapter=prebid

* update tests for centro adapter

* fixed bug with call of JSONP callback with name, that contain invalid characters

* Centro adapter fix: do not call logError if 'No Bid' was received

* Centro adapter: pass the bid request object to bidfactory.createBid

* Centro adapter: fix ESLintError

* Fix Centro adapter to allow requests of the same units

* Fix spec file for Centro adapter
  • Loading branch information
Niksok authored and matthewlane committed Oct 27, 2017
1 parent c2dd4c7 commit a592a7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/centroBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions test/spec/modules/centroBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
{
Expand All @@ -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'
}
]
Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -117,6 +120,7 @@ describe('centro adapter tests', function () {
params: {
unit: 28136
},
bidId: '12345',
placementCode: '/19968336/header-bid-tag-0'
},
{
Expand All @@ -125,6 +129,7 @@ describe('centro adapter tests', function () {
params: {
unit: 111111
},
bidId: '12346',
placementCode: '/19968336/header-bid-tag-1'
},
{
Expand All @@ -133,6 +138,7 @@ describe('centro adapter tests', function () {
params: {
unit: 222222
},
bidId: '12347',
placementCode: '/19968336/header-bid-tag-2'
},
{
Expand All @@ -141,6 +147,7 @@ describe('centro adapter tests', function () {
params: {
unit: 333333
},
bidId: '12348',
placementCode: '/19968336/header-bid-tag-3'
}
]
Expand All @@ -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');
});

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit a592a7a

Please sign in to comment.