From 7b5b8fa22226684c687ca9198577c20f0f865077 Mon Sep 17 00:00:00 2001 From: Karim Mourra Date: Wed, 8 Nov 2023 19:19:20 -0300 Subject: [PATCH] includes unit test --- src/prebid.js | 2 +- test/spec/unit/pbjs_api_spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/prebid.js b/src/prebid.js index a2aac8562e18..ee2d49b88dc7 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -524,7 +524,7 @@ pbjsInstance.renderAd = hook('async', function (doc, id, options) { const {height, width, ad, mediaType, adUrl, renderer} = bid; // video module - if (FEATURES.VIDEO) { + if (FEATURES.VIDEO && mediaType === 'video') { const adUnit = auctionManager.index.getAdUnit(bid); const videoModule = pbjsInstance.videoModule; const divId = adUnit && adUnit.video && adUnit.video.divId; diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index b458f2482d46..037b66651a5d 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -1482,6 +1482,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 () {