diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 4817d62348a..ffcc230ac13 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -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; } /** @@ -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) { diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index fb1b336ef92..e81ef1c805f 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -4,7 +4,7 @@ import { getPriceGranularity, masSizeOrdering, resetUserSync, - hasVideoMediaType, + classifiedAsVideo, resetRubiConf } from 'modules/rubiconBidAdapter.js'; import {parse as parseQuery} from 'querystring'; @@ -257,7 +257,7 @@ describe('the rubicon adapter', function () { context: 'instream' }, }; - bid.params.video = ''; + bid.params.video = false; } function createVideoBidderRequestOutstream() { @@ -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; }); }); });