Skip to content

Commit

Permalink
Address #642 - adLoader was not being stubbed, thus resulting in re…
Browse files Browse the repository at this point in the history
…questing resources that are not always script responses. This should resolve `script error` type build failures (#678)
  • Loading branch information
Matt Kendall authored Oct 5, 2016
1 parent c9652cb commit b385300
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 101 deletions.
16 changes: 8 additions & 8 deletions test/spec/adapters/centro_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ describe('centro adapter tests', function () {
var pbjs = window.pbjs;
}

var spyLoadScript;
let stubLoadScript;
beforeEach(function () {
spyLoadScript = sinon.spy(adLoader, 'loadScript');
stubLoadScript = sinon.stub(adLoader, 'loadScript');
});

afterEach(function () {
spyLoadScript.restore();
stubLoadScript.restore();
});

var logErrorSpy;
Expand Down Expand Up @@ -70,11 +70,11 @@ describe('centro adapter tests', function () {
};

adapter().callBids(params);
var bidUrl1 = spyLoadScript.getCall(0).args[0];
var bidUrl2 = spyLoadScript.getCall(1).args[0];
var bidUrl1 = stubLoadScript.getCall(0).args[0];
var bidUrl2 = stubLoadScript.getCall(1).args[0];

sinon.assert.calledWith(logErrorSpy, 'Bid has no unit', 'centro');
sinon.assert.calledWith(spyLoadScript, bidUrl1);
sinon.assert.calledWith(stubLoadScript, bidUrl1);

var parsedBidUrl = urlParse(bidUrl1);
var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);
Expand All @@ -88,7 +88,7 @@ describe('centro adapter tests', function () {
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);
sinon.assert.calledWith(stubLoadScript, bidUrl2);

parsedBidUrl = urlParse(bidUrl2);
parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);
Expand Down Expand Up @@ -225,4 +225,4 @@ describe('centro adapter tests', function () {
stubAddBidResponse.restore();
});
});
});
});
47 changes: 23 additions & 24 deletions test/spec/adapters/jcm_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe('jcm adapter tests', function () {

var expect = require('chai').expect;
var urlParse = require('url-parse');

// FYI: querystringify will perform encoding/decoding
var querystringify = require('querystringify');

Expand All @@ -13,21 +13,21 @@ describe('jcm adapter tests', function () {
window.pbjs = window.pbjs || {};
if (typeof(pbjs)==="undefined"){
var pbjs = window.pbjs;
}
var spyLoadScript;
}
let stubLoadScript;

beforeEach(function () {
spyLoadScript = sinon.spy(adLoader, 'loadScript');
stubLoadScript = sinon.stub(adLoader, 'loadScript');
});

afterEach(function () {
spyLoadScript.restore();
stubLoadScript.restore();
});


describe('creation of bid url', function () {

if (typeof(pbjs._bidsReceived)==="undefined"){
if (typeof(pbjs._bidsReceived)==="undefined"){
pbjs._bidsReceived = [];
}
if (typeof(pbjs._bidsRequested)==="undefined"){
Expand All @@ -50,14 +50,14 @@ describe('jcm adapter tests', function () {
params: { siteId: '3608', adSizes:'300x250' },
requestId: '10b327aa396609',
placementCode: '/19968336/header-bid-tag-0'
}
}

]
};

adapter().callBids(params);

sinon.assert.calledOnce(spyLoadScript);
sinon.assert.calledOnce(stubLoadScript);

});

Expand All @@ -80,19 +80,19 @@ describe('jcm adapter tests', function () {
};

adapter().callBids(params);
var bidUrl = spyLoadScript.getCall(0).args[0];
var bidUrl = stubLoadScript.getCall(0).args[0];

sinon.assert.calledWith(spyLoadScript, bidUrl);
sinon.assert.calledWith(stubLoadScript, bidUrl);

var parsedBidUrl = urlParse(bidUrl);
var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);
var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);

expect(parsedBidUrl.hostname).to.equal('media.adfrontiers.com');
expect(parsedBidUrl.pathname).to.equal('/pq');

expect(parsedBidUrlQueryString).to.have.property('t').and.to.equal('hb');
expect(parsedBidUrlQueryString).to.have.property('bids');

var bidObjArr = JSON.parse(parsedBidUrlQueryString.bids);
expect(bidObjArr).to.have.property('bids');
var bidObj = bidObjArr.bids[0];
Expand All @@ -101,7 +101,7 @@ describe('jcm adapter tests', function () {
expect(bidObj).to.have.property('siteId').and.to.equal('3608');
expect(bidObj).to.have.property('callbackId').and.to.equal('3c9408cdbf2f68');
});

});

describe('placement by size', function () {
Expand Down Expand Up @@ -145,9 +145,9 @@ describe('jcm adapter tests', function () {
};

adapter().callBids(params);
var bidUrl = spyLoadScript.getCall(0).args[0];
var bidUrl = stubLoadScript.getCall(0).args[0];

sinon.assert.calledWith(spyLoadScript, bidUrl);
sinon.assert.calledWith(stubLoadScript, bidUrl);

var parsedBidUrl = urlParse(bidUrl);
var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('jcm adapter tests', function () {
it('bidmanager.addBidResponse should be called twice with correct arguments', function () {

var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse');

adapter().callBids(params);

var adUnits = new Array();
Expand All @@ -242,7 +242,7 @@ describe('jcm adapter tests', function () {
}
else{
pbjs._bidsRequested.push(params);
}
}
pbjs.adUnits = adUnits;
pbjs.processJCMResponse(response);

Expand All @@ -257,16 +257,15 @@ describe('jcm adapter tests', function () {
expect(bidObject1.width).to.equal(300);
expect(bidObject1.height).to.equal(250);
expect(bidObject1.getStatusCode()).to.equal(1);
expect(bidObject1.bidderCode).to.equal('jcm');
expect(bidObject1.bidderCode).to.equal('jcm');

expect(bidPlacementCode2).to.equal('/19968336/header-bid-tag-1');
expect(bidObject2.getStatusCode()).to.equal(2);

sinon.assert.calledTwice(stubAddBidResponse);
stubAddBidResponse.restore();
});
stubAddBidResponse.restore();
});

});

});

11 changes: 5 additions & 6 deletions test/spec/adapters/memeglobal_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ describe('memeglobal adapter tests', function () {
const adLoader = require('src/adloader');
var bidderName = 'memeglobal';

var spyLoadScript;
let stubLoadScript;
beforeEach(function () {
spyLoadScript = sinon.spy(adLoader, 'loadScript');
stubLoadScript = sinon.stub(adLoader, 'loadScript');
});

afterEach(function () {
spyLoadScript.restore();
stubLoadScript.restore();
});

function getBidSetForBidder() {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('memeglobal adapter tests', function () {
};

adapter().callBids(params);
sinon.assert.calledOnce(spyLoadScript);
sinon.assert.calledOnce(stubLoadScript);
});

it('callBids empty params', function () {
Expand All @@ -72,7 +72,7 @@ describe('memeglobal adapter tests', function () {
};

adapter().callBids({});
expect(spyLoadScript.callCount).to.equal(0);
expect(stubLoadScript.callCount).to.equal(0);
});
});

Expand Down Expand Up @@ -169,4 +169,3 @@ describe('memeglobal adapter tests', function () {
});
});
});

Loading

0 comments on commit b385300

Please sign in to comment.