Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBjs Core: bugfix - accessing array instead of adUnit #10567

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
});
Expand Down
7 changes: 4 additions & 3 deletions libraries/creativeRender/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +38 to +44
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgirardi i ported the changes over to direct.js ; open to creating a custom renderer but not sure what you mean by that . Is it an existing pattern ?

return;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand Down Expand Up @@ -1469,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 () {
Expand Down