-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a few unit tests, and added fixtures for shared data structures.
- Loading branch information
Showing
6 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"code": "video1", | ||
"sizes": [640,480], | ||
"mediaType": "video", | ||
"bids": [ | ||
{ | ||
"bidder": "appnexusAst", | ||
"params": { | ||
"placementId": "9333431", | ||
"video": { | ||
"skipppable": false, | ||
"playback_methods": ["auto_play_sound_off"] | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"auctionStart": 1462918897459, | ||
"bidderCode": "appnexusAst", | ||
"bidderRequestId": "2946b569352ef2", | ||
"bids": [ | ||
{ | ||
"bidder": "appnexusAst", | ||
"params": { | ||
"placementId": "9333431", | ||
"video": { | ||
"skipppable": false, | ||
"playback_methods": ["auto_play_sound_off"] | ||
} | ||
}, | ||
"placementCode": "video1", | ||
"sizes": [640,480], | ||
"bidId": "392b5a6b05d648", | ||
"bidderRequestId": "2946b569352ef2", | ||
"requestId": "6172477f-987f-4523-a967-fa6d7a434ddf", | ||
"startTime": 1462918897462 | ||
} | ||
], | ||
"requestId": "6172477f-987f-4523-a967-fa6d7a434ddf", | ||
"start": 1462918897460, | ||
"timeout": 5000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"adUnitCode": "video1", | ||
"bidder": "appnexusAst", | ||
"bidderCode": "appnexusAst", | ||
"code": "appnexusAst", | ||
"dealId": "foo", | ||
"cpm": 0.1, | ||
"height": 480, | ||
"mediaType": "video", | ||
"requestId": "6172477f-987f-4523-a967-fa6d7a434ddf", | ||
"vastUrl": "www.myVastUrl.com", | ||
"width": 640 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as videoCache from 'src/video-cache'; | ||
|
||
/** | ||
* Function which can be called from unit tests to stub out the video cache. | ||
* | ||
* @param {Object} responses | ||
* @param {} responses.store If this is an Error, we'll stub out the store function so that it fails. | ||
* If it's anything else, the store function will succeed, sending that value into the callback. | ||
* | ||
* @return {function} A function which returns the current stubs for the mocked functions. | ||
*/ | ||
export default function useVideoCacheStub(responses) { | ||
let storeStub; | ||
|
||
beforeEach(() => { | ||
storeStub = sinon.stub(videoCache, 'store'); | ||
|
||
if (responses.store instanceof Error) { | ||
storeStub.callsArgWith(1, responses.store); | ||
} else { | ||
storeStub.callsArgWith(1, null, responses.store); | ||
} | ||
}); | ||
|
||
afterEach(() => { | ||
videoCache.store.restore(); | ||
}); | ||
|
||
return function() { | ||
return { | ||
store: storeStub | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { expect } from 'chai'; | ||
import * as bidManager from 'src/bidmanager'; | ||
import useVideoCacheStubs from 'test/mocks/videoCacheStub'; | ||
import adUnit from 'test/fixtures/video/adUnit'; | ||
import bidRequest from 'test/fixtures/video/bidRequest'; | ||
import bidResponse from 'test/fixtures/video/bidResponse'; | ||
|
||
describe('The Bid Manager', () => { | ||
describe('addBidResponse() function', () => { | ||
before(() => { | ||
$$PREBID_GLOBAL$$.cbTimeout = 5000; | ||
$$PREBID_GLOBAL$$.timeoutBuffer = 50; | ||
}); | ||
|
||
useVideoCacheStubs({ | ||
store: [{ cacheId: 'FAKE_UUID' }], | ||
}); | ||
|
||
describe('when more bids are expected after this one', () => { | ||
beforeEach(() => { | ||
const tweakedBidRequest = JSON.parse(JSON.stringify(bidRequest)); | ||
const tweakedBidRequestBid = Object.assign({}, bidRequest.bids[0], { placementCode: 'video2' }); | ||
tweakedBidRequest.bids.push(tweakedBidRequestBid); | ||
tweakedBidRequest.start = new Date().getTime(); | ||
|
||
$$PREBID_GLOBAL$$.adUnits = [adUnit, Object.assign({}, adUnit, { code: 'video2' })]; | ||
$$PREBID_GLOBAL$$._bidsRequested = [tweakedBidRequest]; | ||
$$PREBID_GLOBAL$$._bidsReceived = []; | ||
$$PREBID_GLOBAL$$._adUnitCodes = $$PREBID_GLOBAL$$.adUnits.map(unit => unit.code); | ||
}); | ||
|
||
it('should add video bids, but *not* call the end-of-auction callbacks', () => { | ||
const mockResponse = Object.assign({}, bidResponse); | ||
const spy = sinon.spy(); | ||
bidManager.addOneTimeCallback(spy); | ||
|
||
mockResponse.getSize = function() { | ||
return `${this.height}x${this.width}` | ||
}; | ||
bidManager.addBidResponse(adUnit.code, mockResponse); | ||
|
||
expect($$PREBID_GLOBAL$$._bidsReceived.length).to.equal(1); | ||
|
||
const bid = $$PREBID_GLOBAL$$._bidsReceived[0]; | ||
expect(bid.vastUrl).to.equal('www.myVastUrl.com'); | ||
expect(bid.videoCacheKey).to.equal('FAKE_UUID'); | ||
|
||
expect(spy.called).to.equal(false); | ||
}); | ||
|
||
it("shouldn't add bids which arrive after the auction times out", () => { | ||
expect(true).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('when this is the last bid expected in the auction', () => { | ||
beforeEach(() => { | ||
$$PREBID_GLOBAL$$.adUnits = [adUnit]; | ||
$$PREBID_GLOBAL$$._bidsRequested = [bidRequest]; | ||
$$PREBID_GLOBAL$$._bidsReceived = []; | ||
$$PREBID_GLOBAL$$._adUnitCodes = $$PREBID_GLOBAL$$.adUnits.map(unit => unit.code); | ||
}); | ||
|
||
it("shouldn't add invalid bids", () => { | ||
bidManager.addBidResponse('', { }); | ||
bidManager.addBidResponse('testCode', { mediaType: 'video' }); | ||
bidManager.addBidResponse('testCode', { mediaType: 'native' }); | ||
expect($$PREBID_GLOBAL$$._bidsReceived.length).to.equal(0); | ||
}); | ||
|
||
it('should add valid video bids and then execute the callbacks signaling the end of the auction', () => { | ||
const mockResponse = Object.assign({}, bidResponse); | ||
const spy = sinon.spy(); | ||
bidManager.addOneTimeCallback(spy); | ||
|
||
mockResponse.getSize = function() { | ||
return `${this.height}x${this.width}` | ||
}; | ||
bidManager.addBidResponse(adUnit.code, mockResponse); | ||
|
||
expect($$PREBID_GLOBAL$$._bidsReceived.length).to.equal(1); | ||
|
||
const bid = $$PREBID_GLOBAL$$._bidsReceived[0]; | ||
expect(bid.vastUrl).to.equal('www.myVastUrl.com'); | ||
expect(bid.videoCacheKey).to.equal('FAKE_UUID'); | ||
|
||
expect(spy.calledOnce).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
}); |