Skip to content

Commit

Permalink
Rubicon Bid Adapter: Choose video when banner mediaType is not present (
Browse files Browse the repository at this point in the history
prebid#8997)

* Choose video when banner mediaType is not present

* Define video.params as needed

* Refactor unit tests for classifiedAsVideo

* Unit test fixes

* Add video+banner+params.video test

* Remove obsolete test
  • Loading branch information
spotxslagle authored Sep 20, 2022
1 parent 7f8d671 commit dd0f8ac
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
22 changes: 16 additions & 6 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,15 +1109,25 @@ function mapSizes(sizes) {

/**
* Test if bid has mediaType or mediaTypes set for video.
* Also makes sure the video object is present in the rubicon bidder params
* Also checks if the video object is present in the rubicon bidder params
* @param {BidRequest} bidRequest
* @returns {boolean}
*/
export function hasVideoMediaType(bidRequest) {
if (typeof deepAccess(bidRequest, 'params.video') !== 'object') {
return false;
export function classifiedAsVideo(bidRequest) {
let isVideo = typeof deepAccess(bidRequest, `mediaTypes.${VIDEO}`) !== 'undefined';
let isBanner = typeof deepAccess(bidRequest, `mediaTypes.${BANNER}`) !== 'undefined';
let isMissingVideoParams = typeof deepAccess(bidRequest, 'params.video') !== 'object';
// If an ad has both video and banner types, a legacy implementation allows choosing video over banner
// based on whether or not there is a video object defined in the params
// Given this legacy implementation, other code depends on params.video being defined

if (isBanner && isMissingVideoParams) {
isVideo = false;
}
return (typeof deepAccess(bidRequest, `mediaTypes.${VIDEO}`) !== 'undefined');
if (isVideo && isMissingVideoParams) {
deepSetValue(bidRequest, 'params.video', {});
}
return isVideo;
}

/**
Expand All @@ -1128,7 +1138,7 @@ export function hasVideoMediaType(bidRequest) {
*/
function bidType(bid, log = false) {
// Is it considered video ad unit by rubicon
if (hasVideoMediaType(bid)) {
if (classifiedAsVideo(bid)) {
// Removed legacy mediaType support. new way using mediaTypes.video object is now required
// We require either context as instream or outstream
if (['outstream', 'instream'].indexOf(deepAccess(bid, `mediaTypes.${VIDEO}.context`)) === -1) {
Expand Down
63 changes: 28 additions & 35 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getPriceGranularity,
masSizeOrdering,
resetUserSync,
hasVideoMediaType,
classifiedAsVideo,
resetRubiConf
} from 'modules/rubiconBidAdapter.js';
import {parse as parseQuery} from 'querystring';
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('the rubicon adapter', function () {
context: 'instream'
},
};
bid.params.video = '';
bid.params.video = false;
}

function createVideoBidderRequestOutstream() {
Expand Down Expand Up @@ -2320,57 +2320,50 @@ describe('the rubicon adapter', function () {
});
});

describe('hasVideoMediaType', function () {
it('should return true if mediaType is video and size_id is set', function () {
describe('classifiedAsVideo', function () {
it('should return true if mediaTypes is video', function () {
createVideoBidderRequest();
const legacyVideoTypeBidRequest = hasVideoMediaType(bidderRequest.bids[0]);
expect(legacyVideoTypeBidRequest).is.equal(true);
const bidClassifiedAsVideo = classifiedAsVideo(bidderRequest.bids[0]);
expect(bidClassifiedAsVideo).is.equal(true);
});

it('should return false if trying to use legacy mediaType with video', function () {
createVideoBidderRequest();
delete bidderRequest.bids[0].mediaTypes;
bidderRequest.bids[0].mediaType = 'video';
const legacyVideoTypeBidRequest = hasVideoMediaType(bidderRequest.bids[0]);
const legacyVideoTypeBidRequest = classifiedAsVideo(bidderRequest.bids[0]);
expect(legacyVideoTypeBidRequest).is.equal(false);
});

it('should return false if bidRequest.mediaType is not equal to video', function () {
expect(hasVideoMediaType({
it('should return false if bid.mediaTypes is not equal to video', function () {
expect(classifiedAsVideo({
mediaType: 'banner'
})).is.equal(false);
});

it('should return false if bidRequest.mediaType is not defined', function () {
expect(hasVideoMediaType({})).is.equal(false);
it('should return false if bid.mediaTypes is not defined', function () {
expect(classifiedAsVideo({})).is.equal(false);
});

it('should return true if bidRequest.mediaTypes.video.context is instream and size_id is defined', function () {
expect(hasVideoMediaType({
mediaTypes: {
video: {
context: 'instream'
}
},
params: {
video: {
size_id: 7
}
}
})).is.equal(true);
it('Should return false if both banner and video mediaTypes are set and params.video is not an object', function () {
createVideoBidderRequestNoVideo();
let bid = bidderRequest.bids[0];
bid.mediaTypes.banner = {flag: true};
expect(classifiedAsVideo(bid)).to.equal(false);
});
it('Should return true if both banner and video mediaTypes are set and params.video is an object', function () {
createVideoBidderRequestNoVideo();
let bid = bidderRequest.bids[0];
bid.mediaTypes.banner = {flag: true};
bid.params.video = {};
expect(classifiedAsVideo(bid)).to.equal(true);
});

it('should return false if bidRequest.mediaTypes.video.context is instream but size_id is not defined', function () {
expect(spec.isBidRequestValid({
mediaTypes: {
video: {
context: 'instream'
}
},
params: {
video: {}
}
})).is.equal(false);
it('Should return true and create a params.video object if one is not already present', function () {
createVideoBidderRequestNoVideo();
let bid = bidderRequest.bids[0]
expect(classifiedAsVideo(bid)).to.equal(true);
expect(bid.params.video).to.not.be.undefined;
});
});
});
Expand Down

0 comments on commit dd0f8ac

Please sign in to comment.