Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebid 1.0 Fix issue with video bid validation #1680

Merged
merged 6 commits into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/video.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { videoAdapters } from './adaptermanager';
import { getBidRequest, deepAccess } from './utils';
import { auctionManager } from './auctionManager';

const VIDEO_MEDIA_TYPE = 'video';
const OUTSTREAM = 'outstream';
Expand All @@ -23,7 +24,7 @@ export const hasNonVideoBidder = adUnit =>
* @return {boolean} If object is valid
*/
export function isValidVideoBid(bid) {
const bidRequest = getBidRequest(bid.adId);
const bidRequest = getBidRequest(bid.adId, auctionManager.getBidsRequested());

const videoMediaType =
bidRequest && deepAccess(bidRequest, 'mediaTypes.video');
Expand Down
86 changes: 58 additions & 28 deletions test/spec/video_spec.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
import { isValidVideoBid } from 'src/video';
const utils = require('src/utils');
import { auctionManager } from 'src/auctionManager';

describe('video.js', () => {
beforeEach(() => {
sinon.stub(auctionManager, 'getBidsRequested');
});

afterEach(() => {
utils.getBidRequest.restore();
auctionManager.getBidsRequested.restore();
});

it('validates valid instream bids', () => {
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'instream' },
},
}));
auctionManager.getBidsRequested.returns([
{
bids: [{
bidId: '123abc',
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'instream' }
}
}]
}
]);

const valid = isValidVideoBid({
adId: '123abc',
vastUrl: 'http://www.example.com/vastUrl'
});

expect(valid).to.be(true);
});

it('catches invalid instream bids', () => {
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'instream' },
},
}));
auctionManager.getBidsRequested.returns([
{
bids: [{
bidId: '123abc',
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'instream' }
}
}]
}
]);

const valid = isValidVideoBid({});
const valid = isValidVideoBid({
adId: '123abc'
});

expect(valid).to.be(false);
});

it('validates valid outstream bids', () => {
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'outstream' },
},
}));
auctionManager.getBidsRequested.returns([
{
bids: [{
bidId: '123abc',
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'outstream' }
}
}]
}
]);

const valid = isValidVideoBid({
adId: '123abc',
renderer: {
url: 'render.url',
render: () => true,
Expand All @@ -53,14 +76,21 @@ describe('video.js', () => {
});

it('catches invalid outstream bids', () => {
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'outstream' },
},
}));
auctionManager.getBidsRequested.returns([
{
bids: [{
bidId: '123abc',
bidder: 'appnexusAst',
mediaTypes: {
video: { context: 'outstream' }
}
}]
}
]);

const valid = isValidVideoBid({});
const valid = isValidVideoBid({
adId: '123abc'
});

expect(valid).to.be(false);
});
Expand Down