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

Core: fix missing AD_RENDER_SUCCEDED for outstream renderers #11073

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
6 changes: 5 additions & 1 deletion src/adRendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const {AD_RENDER_FAILED, AD_RENDER_SUCCEEDED, STALE_RENDER, BID_WON} = constants
*/
export function emitAdRenderFail({ reason, message, bid, id }) {
const data = { reason, message };
if (bid) data.bid = bid;
if (bid) {
data.bid = bid;
data.adId = bid.adId;
}
if (id) data.adId = id;

logError(`Error rendering ad (id: ${id}): ${message}`);
Expand Down Expand Up @@ -64,6 +67,7 @@ export function handleRender(renderFn, {adId, options, bidResponse, doc}) {
// rendering for outstream safeframe
if (isRendererRequired(renderer)) {
executeRenderer(renderer, bidResponse, doc);
emitAdRenderSucceeded({doc, bid: bidResponse, id: adId})
} else if (adId) {
if (mediaType === VIDEO) {
emitAdRenderFail({
Expand Down
56 changes: 48 additions & 8 deletions test/spec/unit/secureCreatives_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ import {handleRender} from '../../../src/adRendering.js';
var CONSTANTS = require('src/constants.json');

describe('secureCreatives', () => {
let sandbox;

beforeEach(() => {
sandbox = sinon.sandbox.create();
});

afterEach(() => {
sandbox.restore();
});

function makeEvent(ev) {
return Object.assign({origin: 'mock-origin', ports: []}, ev)
}
Expand Down Expand Up @@ -63,14 +73,44 @@ describe('secureCreatives', () => {
}
});

it('does not invoke renderFn, but the renderer instead, if the ad has one', () => {
const renderer = {
url: 'some-custom-renderer',
render: sinon.spy()
}
handleRender(renderFn, {bidResponse: {renderer}});
sinon.assert.notCalled(renderFn);
sinon.assert.called(renderer.render);
describe('when the ad has a renderer', () => {
let bidResponse;
beforeEach(() => {
sandbox.stub(events, 'emit');
bidResponse = {
adId: 'mock-ad-id',
renderer: {
url: 'some-custom-renderer',
render: sinon.stub()
}
}
});

it('does not invoke renderFn, but the renderer instead', () => {
handleRender(renderFn, {bidResponse});
sinon.assert.notCalled(renderFn);
sinon.assert.called(bidResponse.renderer.render);
});

it('emits AD_RENDER_SUCCEDED', () => {
handleRender(renderFn, {bidResponse});
sinon.assert.calledWith(events.emit, CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED, sinon.match({
bid: bidResponse,
adId: bidResponse.adId
}));
});

it('emits AD_RENDER_FAILED', () => {
const err = new Error('error message');
bidResponse.renderer.render.throws(err);
handleRender(renderFn, {bidResponse});
sinon.assert.calledWith(events.emit, CONSTANTS.EVENTS.AD_RENDER_FAILED, sinon.match({
bid: bidResponse,
adId: bidResponse.adId,
reason: CONSTANTS.AD_RENDER_FAILED_REASON.EXCEPTION,
message: err.message
}));
})
});

['ad', 'adUrl'].forEach((prop) => {
Expand Down