Skip to content

Commit

Permalink
feat(unruly-bid-adapter): use bidResponse siteId when configuring the…
Browse files Browse the repository at this point in the history
… renderer (prebid#3865)

* feat(unruly-bid-adapter): use bidResponse siteId when configuring the renderer

* feat(unruly-bid-adapter): bail if siteId is missing

* feat(unruly-bid-adapter): log (but don't throw) when siteId is no present
  • Loading branch information
paprikka authored and sa1omon committed Nov 28, 2019
1 parent be6207c commit 046a19c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 12 deletions.
16 changes: 14 additions & 2 deletions modules/unrulyBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { registerBidder } from '../src/adapters/bidderFactory'
import { VIDEO } from '../src/mediaTypes'

function configureUniversalTag (exchangeRenderer) {
if (!exchangeRenderer.config) throw new Error('UnrulyBidAdapter: Missing renderer config.')
if (!exchangeRenderer.config.siteId) throw new Error('UnrulyBidAdapter: Missing renderer siteId.')

parent.window.unruly = parent.window.unruly || {};
parent.window.unruly['native'] = parent.window.unruly['native'] || {};
parent.window.unruly['native'].siteId = parent.window.unruly['native'].siteId || exchangeRenderer.siteId;
parent.window.unruly['native'].siteId = parent.window.unruly['native'].siteId || exchangeRenderer.config.siteId;
parent.window.unruly['native'].supplyMode = 'prebid';
}

Expand Down Expand Up @@ -35,9 +38,18 @@ const serverResponseToBid = (bid, rendererInstance) => ({

const buildPrebidResponseAndInstallRenderer = bids =>
bids
.filter(serverBid => !!utils.deepAccess(serverBid, 'ext.renderer'))
.filter(serverBid => {
const hasConfig = !!utils.deepAccess(serverBid, 'ext.renderer.config');
const hasSiteId = !!utils.deepAccess(serverBid, 'ext.renderer.config.siteId');

if (!hasConfig) utils.logError(new Error('UnrulyBidAdapter: Missing renderer config.'));
if (!hasSiteId) utils.logError(new Error('UnrulyBidAdapter: Missing renderer siteId.'));

return hasSiteId
})
.map(serverBid => {
const exchangeRenderer = utils.deepAccess(serverBid, 'ext.renderer');

configureUniversalTag(exchangeRenderer);
configureRendererQueue();

Expand Down
81 changes: 71 additions & 10 deletions test/spec/modules/unrulyBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ describe('UnrulyAdapter', function () {
'statusCode': statusCode,
'renderer': {
'id': 'unruly_inarticle',
'config': {},
'config': {
'siteId': 123456,
'targetingUUID': 'xxx-yyy-zzz'
},
'url': 'https://video.unrulymedia.com/native/prebid-loader.js'
},
'adUnitCode': adUnitCode
Expand Down Expand Up @@ -125,10 +128,10 @@ describe('UnrulyAdapter', function () {
it('should be a function', function () {
expect(typeof adapter.interpretResponse).to.equal('function');
});
it('should return empty array when serverResponse is undefined', function () {
it('should return [] when serverResponse is undefined', function () {
expect(adapter.interpretResponse()).to.deep.equal([]);
});
it('should return empty array when serverResponse has no bids', function () {
it('should return [] when serverResponse has no bids', function () {
const mockServerResponse = { body: { bids: [] } };
expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([])
});
Expand Down Expand Up @@ -157,7 +160,13 @@ describe('UnrulyAdapter', function () {
expect(fakeRenderer.setRender.called).to.be.false;

const mockReturnedBid = createOutStreamExchangeBid({adUnitCode: 'video1', bidId: 'mockBidId'});
const mockRenderer = { url: 'value: mockRendererURL' };
const mockRenderer = {
url: 'value: mockRendererURL',
config: {
siteId: 123456,
targetingUUID: 'xxx-yyy-zzz'
}
};
mockReturnedBid.ext.renderer = mockRenderer;
const mockServerResponse = createExchangeResponse(mockReturnedBid);

Expand All @@ -173,6 +182,58 @@ describe('UnrulyAdapter', function () {
sinon.assert.calledWithExactly(fakeRenderer.setRender, sinon.match.func)
});

it('should return [] and log if bidResponse renderer config is not available', function () {
sinon.assert.notCalled(utils.logError)

expect(Renderer.install.called).to.be.false;
expect(fakeRenderer.setRender.called).to.be.false;

const mockReturnedBid = createOutStreamExchangeBid({adUnitCode: 'video1', bidId: 'mockBidId'});
const mockRenderer = {
url: 'value: mockRendererURL'
};
mockReturnedBid.ext.renderer = mockRenderer;
const mockServerResponse = createExchangeResponse(mockReturnedBid);

expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]);

const logErrorCalls = utils.logError.getCalls();
expect(logErrorCalls.length).to.equal(2);

const [ configErrorCall, siteIdErrorCall ] = logErrorCalls;

expect(configErrorCall.args.length).to.equal(1);
expect(configErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing renderer config.');

expect(siteIdErrorCall.args.length).to.equal(1);
expect(siteIdErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing renderer siteId.');
});

it('should return [] and log if siteId is not available', function () {
sinon.assert.notCalled(utils.logError)

expect(Renderer.install.called).to.be.false;
expect(fakeRenderer.setRender.called).to.be.false;

const mockReturnedBid = createOutStreamExchangeBid({adUnitCode: 'video1', bidId: 'mockBidId'});
const mockRenderer = {
url: 'value: mockRendererURL',
config: {}
};
mockReturnedBid.ext.renderer = mockRenderer;
const mockServerResponse = createExchangeResponse(mockReturnedBid);

expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]);

const logErrorCalls = utils.logError.getCalls();
expect(logErrorCalls.length).to.equal(1);

const [ siteIdErrorCall ] = logErrorCalls;

expect(siteIdErrorCall.args.length).to.equal(1);
expect(siteIdErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing renderer siteId.');
});

it('bid is placed on the bid queue when render is called', function () {
const exchangeBid = createOutStreamExchangeBid({ adUnitCode: 'video', vastUrl: 'value: vastUrl' });
const exchangeResponse = createExchangeResponse(exchangeBid);
Expand All @@ -191,7 +252,7 @@ describe('UnrulyAdapter', function () {
expect(sentRendererConfig.vastUrl).to.equal('value: vastUrl');
expect(sentRendererConfig.renderer).to.equal(fakeRenderer);
expect(sentRendererConfig.adUnitCode).to.equal('video')
})
});

it('should ensure that renderer is placed in Prebid supply mode', function () {
const mockExchangeBid = createOutStreamExchangeBid({adUnitCode: 'video1', bidId: 'mockBidId'});
Expand Down Expand Up @@ -237,28 +298,28 @@ describe('UnrulyAdapter', function () {
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html'
})
})
});

it('should append consent params if gdpr does apply and consent is given', () => {
const mockConsent = {
gdprApplies: true,
consentString: 'hello'
}
};
const response = {}
const syncOptions = { iframeEnabled: true }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent)
expect(syncs[0]).to.deep.equal({
type: 'iframe',
url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html?gdpr=1&gdpr_consent=hello'
})
})
});

it('should append consent param if gdpr applies and no consent is given', () => {
const mockConsent = {
gdprApplies: true,
consentString: {}
}
const response = {}
};
const response = {};
const syncOptions = { iframeEnabled: true }
const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent)
expect(syncs[0]).to.deep.equal({
Expand Down

0 comments on commit 046a19c

Please sign in to comment.