Skip to content

Commit

Permalink
Fix adapter tests that hardcoded pbjs. (prebid#1666)
Browse files Browse the repository at this point in the history
Updated adapters to use `$$PREBID_GLOBAL$$` instead.
Now if you change `globalVarName` in `package.json` the
tests won't fail.
  • Loading branch information
mattpr authored and Rachel Joyce committed Oct 20, 2017
1 parent 73b6f43 commit 8ffcc0c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
20 changes: 10 additions & 10 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript with correct parameters', () => {
sinon.assert.calledOnce(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
});
});

Expand All @@ -402,7 +402,7 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript with correct parameters', () => {
sinon.assert.calledOnce(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pubid%22%3A1032%2C%22pkey%22%3A%22data_team_test_hb_smoke_test%22%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pubid%22%3A1032%2C%22pkey%22%3A%22data_team_test_hb_smoke_test%22%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
});
});

Expand All @@ -417,7 +417,7 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript with correct parameters', () => {
sinon.assert.calledOnce(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012546%2C%22kvw%22%3A%7B%22hbkv%22%3A%5B%2201%22%5D%7D%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012546%2C%22kvw%22%3A%7B%22hbkv%22%3A%5B%2201%22%5D%7D%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
});
});

Expand All @@ -432,7 +432,7 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript with correct parameters', () => {
sinon.assert.calledOnce(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
});
});

Expand All @@ -447,8 +447,8 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript twice with correct parameters', () => {
sinon.assert.calledTwice(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543211%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%224d5e6f%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543211%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%224d5e6f%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
});
});

Expand All @@ -463,9 +463,9 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript thrice with correct parameters', () => {
sinon.assert.calledThrice(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543211%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%224d5e6f%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543212%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%227g8h9i%22%2C%22pid%22%3A1012546%2C%22kvw%22%3A%7B%22hbkv%22%3A%5B%2201%22%5D%7D%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543211%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%224d5e6f%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543212%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%227g8h9i%22%2C%22pid%22%3A1012546%2C%22kvw%22%3A%7B%22hbkv%22%3A%5B%2201%22%5D%7D%2C%22banner%22%3A%7B%7D%7D%5D%7D%7D', null);
});
});

Expand Down Expand Up @@ -493,7 +493,7 @@ describe('improvedigital adapter tests', function () {
});
it('should call loadScript twice with correct parameters', () => {
sinon.assert.calledOnce(adloader.loadScript);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22pbjs.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%2C%7B%22id%22%3A%224d5e6f%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
sinon.assert.calledWith(adloader.loadScript, 'http://ad.360yield.com/hb?jsonp=%7B%22bid_request%22%3A%7B%22id%22%3A%229876543210%22%2C%22callback%22%3A%22$$PREBID_GLOBAL$$.improveDigitalResponse%22%2C%22secure%22%3A0%2C%22version%22%3A%22' + improveDigitalAdapter.LIB_VERSION + '-' + improveDigitalAdapter.idClient.CONSTANTS.CLIENT_VERSION + '%22%2C%22imp%22%3A%5B%7B%22id%22%3A%221a2b3c%22%2C%22pid%22%3A1012544%2C%22banner%22%3A%7B%7D%7D%2C%7B%22id%22%3A%224d5e6f%22%2C%22pid%22%3A1012545%2C%22banner%22%3A%7B%22w%22%3A800%2C%22h%22%3A600%7D%7D%5D%7D%7D', null);
});
});

Expand Down
22 changes: 11 additions & 11 deletions test/spec/modules/orbitsoftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Orbitsoft Adapter tests', function () {

describe('test orbitsoft callback response', function () {
it('should exist and be a function', function () {
expect(pbjs.handleOASCB).to.exist.and.to.be.a('function');
expect($$PREBID_GLOBAL$$.handleOASCB).to.exist.and.to.be.a('function');
});

it('should add empty bid responses if no bids returned', function () {
Expand Down Expand Up @@ -43,8 +43,8 @@ describe('Orbitsoft Adapter tests', function () {
cpm: 0
};

pbjs._bidsRequested.push(bidderRequest);
pbjs.handleOASCB(response);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$.handleOASCB(response);

let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0];
let bidResponse1 = stubAddBidResponse.getCall(0).args[1];
Expand Down Expand Up @@ -79,8 +79,8 @@ describe('Orbitsoft Adapter tests', function () {
cpm: 0
};

pbjs._bidsRequested.push(bidderRequest);
pbjs.handleOASCB(response);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$.handleOASCB(response);

expect(stubAddBidResponse.getCall(0)).to.equal(null);
stubAddBidResponse.restore();
Expand Down Expand Up @@ -116,8 +116,8 @@ describe('Orbitsoft Adapter tests', function () {
height: 250
};

pbjs._bidsRequested.push(bidderRequest);
pbjs.handleOASCB(response);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$.handleOASCB(response);

let bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0];
let bidResponse1 = stubAddBidResponse.getCall(0).args[1];
Expand Down Expand Up @@ -277,9 +277,9 @@ describe('Orbitsoft Adapter tests', function () {
height: 250
};

pbjs._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);

pbjs.handleOASCB(response);
$$PREBID_GLOBAL$$.handleOASCB(response);

let bidResponse1 = stubAddBidResponse.getCall(0).args[1];
let adUrl = bidResponse1.adUrl;
Expand Down Expand Up @@ -339,8 +339,8 @@ describe('Orbitsoft Adapter tests', function () {
height: 250
};

pbjs._bidsRequested.push(bidderRequest);
pbjs.handleOASCB(response);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$.handleOASCB(response);

let bidResponse1 = stubAddBidResponse.getCall(0).args[1];
let adUrl = bidResponse1.adUrl;
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('sharethrough adapter', () => {

describe('when bidResponse string cannot be JSON parsed', () => {
beforeEach(() => {
pbjs._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
adapter.str.placementCodeSet['foo'] = {};

server.respondWith(/aaaa1111/, 'non JSON string');
Expand All @@ -199,7 +199,7 @@ describe('sharethrough adapter', () => {

describe('when no fill', () => {
beforeEach(() => {
pbjs._bidsRequested.push(bidderRequest);
$$PREBID_GLOBAL$$._bidsRequested.push(bidderRequest);
adapter.str.placementCodeSet['foo'] = {};

let bidderResponse1 = {
Expand Down
6 changes: 3 additions & 3 deletions test/spec/modules/trustxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ describe('trustx adapter tests', function () {
var bidmanager = require('src/bidmanager');
var adLoader = require('src/adloader');
var utils = require('src/utils');
window.pbjs = window.pbjs || {};
window.$$PREBID_GLOBAL$$ = window.$$PREBID_GLOBAL$$ || {};

if (typeof (pbjs) === 'undefined') {
var pbjs = window.pbjs;
var pbjs = window.$$PREBID_GLOBAL$$;
}
let stubLoadScript;
beforeEach(function () {
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('trustx adapter tests', function () {
sinon.assert.calledWith(stubLoadScript, bidUrl);
var parsedBidUrl = urlParse(bidUrl);
var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);
var generatedCallback = 'pbjs.trustx_callback_wrapper_5_6';
var generatedCallback = '$$PREBID_GLOBAL$$.trustx_callback_wrapper_5_6';
expect(parsedBidUrl.hostname).to.equal('sofia.trustx.org');
expect(parsedBidUrl.pathname).to.equal('/hb');
expect(parsedBidUrlQueryString).to.have.property('auids').and.to.equal('5,6');
Expand Down

0 comments on commit 8ffcc0c

Please sign in to comment.