From f6adf06f6d3a2014b738fb91016c1cdb86ca5f86 Mon Sep 17 00:00:00 2001 From: Sy Dao Date: Fri, 7 Aug 2020 17:57:41 -0700 Subject: [PATCH] add support for mediaTypes.video --- modules/tripleliftBidAdapter.js | 29 +++++++++++++------ .../spec/modules/tripleliftBidAdapter_spec.js | 10 ++++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 83033e73611..d6b1f95351d 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -14,7 +14,8 @@ export const tripleliftAdapterSpec = { supportedMediaTypes: [BANNER, VIDEO], isBidRequestValid: function (bid) { if (bid.mediaTypes.video) { - if (!bid.params.video) return false; + let video = _getORTBVideo(bid); + if (!video.w || !video.h) return false; } return typeof bid.params.inventoryCode !== 'undefined'; }, @@ -110,17 +111,16 @@ function _getSyncType(syncOptions) { function _buildPostBody(bidRequests) { let data = {}; let { schain } = bidRequests[0]; - data.imp = bidRequests.map(function(bid, index) { + data.imp = bidRequests.map(function(bidRequest, index) { let imp = { id: index, - tagid: bid.params.inventoryCode, - floor: _getFloor(bid) + tagid: bidRequest.params.inventoryCode, + floor: _getFloor(bidRequest) }; - - if (bid.mediaTypes.video) { - imp.video = bid.params.video; - } else if (bid.mediaTypes.banner) { - imp.banner = { format: _sizes(bid.sizes) }; + if (bidRequest.mediaTypes.video) { + imp.video = _getORTBVideo(bidRequest); + } else if (bidRequest.mediaTypes.banner) { + imp.banner = { format: _sizes(bidRequest.sizes) }; }; return imp; }); @@ -145,6 +145,17 @@ function _buildPostBody(bidRequests) { return data; } +function _getORTBVideo(bidRequest) { + // give precedent to mediaTypes.video + let video = { ...bidRequest.params.video, ...bidRequest.mediaTypes.video }; + if (!video.w) video.w = video.playerSize[0][0]; + if (!video.h) video.h = video.playerSize[0][1]; + if (video.context === 'instream') video.placement = 1; + // clean up oRTB object + delete video.playerSize; + return video; +} + function _getFloor (bid) { let floor = null; if (typeof bid.getFloor === 'function') { diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index daf232bb24e..c6c3b622755 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -37,7 +37,7 @@ describe('triplelift adapter', function () { instreamBid = { bidder: 'triplelift', params: { - inventoryCode: '12345', + inventoryCode: 'insteam_test', floor: 1.0, video: { mimes: ['video/mp4'], @@ -87,7 +87,9 @@ describe('triplelift adapter', function () { }); it('should return false when required params are not passed - instream', function () { - delete instreamBid.params.video; + delete instreamBid.mediaTypes.playerSize; + delete instreamBid.params.video.w; + delete instreamBid.params.video.h; expect(tripleliftAdapterSpec.isBidRequestValid(instreamBid)).to.equal(false); }); }); @@ -137,7 +139,7 @@ describe('triplelift adapter', function () { { bidder: 'triplelift', params: { - inventoryCode: '12345-instream', + inventoryCode: 'insteam_test', floor: 1.0, video: { mimes: ['video/mp4'], @@ -217,7 +219,7 @@ describe('triplelift adapter', function () { expect(payload.imp[0].tagid).to.equal('12345'); expect(payload.imp[0].floor).to.equal(1.0); expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - expect(payload.imp[1].tagid).to.equal('12345-instream'); + expect(payload.imp[1].tagid).to.equal('insteam_test'); expect(payload.imp[1].floor).to.equal(1.0); expect(payload.imp[1].video).to.exist.and.to.be.a('object'); });