From 14cc203ce687df268b7380773877009e515bc768 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Mon, 2 Oct 2023 17:03:33 -0400 Subject: [PATCH 1/3] uses getAdUnit --- libraries/creativeRender/direct.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/creativeRender/direct.js b/libraries/creativeRender/direct.js index 0b4fb2f0a75..9a92da6e7a7 100644 --- a/libraries/creativeRender/direct.js +++ b/libraries/creativeRender/direct.js @@ -35,12 +35,13 @@ export function renderAdDirect(doc, adId, options) { } else { bid = auctionManager.findBidByAdId(adId); - if (FEATURES.VIDEO) { + if (FEATURES.VIDEO && bid.mediaType === 'video') { // TODO: could the video module implement this as a custom renderer, rather than a special case in here? const adUnit = bid && auctionManager.index.getAdUnit(bid); const videoModule = getGlobal().videoModule; - if (adUnit?.video && videoModule) { - videoModule.renderBid(adUnit.video.divId, bid); + const divId = adUnit && adUnit.video && adUnit.video.divId; + if (divId && videoModule) { + videoModule.renderBid(divId, bid); return; } } From 0e32edf7feafd8244bc55dc2a129f9d25b336400 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Tue, 3 Oct 2023 14:06:31 -0400 Subject: [PATCH 2/3] updates tests --- .../videoModule/jwplayer/bidsBackHandlerOverride.html | 4 +++- test/spec/unit/pbjs_api_spec.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html b/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html index 66eaff26090..7a7b71eba82 100644 --- a/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html +++ b/integrationExamples/videoModule/jwplayer/bidsBackHandlerOverride.html @@ -119,7 +119,9 @@ }); bid.vastUrl = videoUrl; - pbjs.videoModule.renderBid('player', bid); + pbjs.renderAd(null, bid.adId); + // Alternatively you can use: + // pbjs.videoModule.renderBid('player', bid); }); } }); diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 39123d4aa41..35efe41662b 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1206,6 +1206,8 @@ describe('Unit: Prebid Module', function () { var spyAddWinningBid; var inIframe = true; var triggerPixelStub; + let indexStub; + let auctionManagerInstance; function pushBidResponseToAuction(obj) { adResponse = Object.assign({ @@ -1251,6 +1253,10 @@ describe('Unit: Prebid Module', function () { inIframe = true; sinon.stub(utils, 'inIframe').callsFake(() => inIframe); triggerPixelStub = sinon.stub(utils.internal, 'triggerPixel'); + + indexStub = sinon.stub(auctionManager, 'index'); + auctionManagerInstance = newAuctionManager(); + indexStub.get(() => auctionManagerInstance.index); }); afterEach(function () { @@ -1261,6 +1267,7 @@ describe('Unit: Prebid Module', function () { utils.inIframe.restore(); triggerPixelStub.restore(); spyAddWinningBid.restore(); + indexStub.restore(); }); it('should require doc and id params', function () { From 86081d971008e9f9483b07e72b930c4a03a6e34b Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Wed, 8 Nov 2023 19:19:20 -0300 Subject: [PATCH 3/3] includes unit test --- test/spec/unit/pbjs_api_spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 35efe41662b..b18a7292581 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1476,6 +1476,25 @@ describe('Unit: Prebid Module', function () { $$PREBID_GLOBAL$$.offEvent(CONSTANTS.EVENTS.STALE_RENDER, onStaleEvent); configObj.setConfig({'auctionOptions': {}}); }); + + if (FEATURES.VIDEO) { + it('should render in the Video Module when mediaType is video and the AdUnit includes a video config', function () { + const adUnit = { + video: { + divId: 'playerDivId' + } + }; + sinon.stub(auctionManager.index, 'getAdUnit').callsFake(() => adUnit); + pushBidResponseToAuction({ + mediaType: 'video' + }); + const renderBidSpy = sinon.spy($$PREBID_GLOBAL$$.videoModule, 'renderBid'); + $$PREBID_GLOBAL$$.renderAd(null, bidId); + assert.ok(renderBidSpy.calledOnce, 'videoModule.renderBid should be called when adUnit is configured for Video Module'); + const args = renderBidSpy.getCall(0).args; + assert.ok(args[0] === 'playerDivId', 'divId from adUnit must be passed as an argument'); + }); + } }); describe('requestBids', function () {