From 916030a0a822c7c4f09d6ea3cf05e55d2d74354d Mon Sep 17 00:00:00 2001 From: dbemiller <27972385+dbemiller@users.noreply.github.com> Date: Tue, 4 Dec 2018 14:35:08 -0500 Subject: [PATCH] Set the OpenRTB device dimensions (#3336) * Set the device dimensions if the config didnt do it. * add unit tests * Added a regresstion test to catch the bug. The code should still populate w and h even if the config doesnt have that object. --- modules/prebidServerBidAdapter/index.js | 9 +++++++ .../modules/prebidServerBidAdapter_spec.js | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index 80724630da90..165e0a6f80ea 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -196,6 +196,15 @@ function _appendSiteAppDevice(request) { if (typeof config.getConfig('device') === 'object') { request.device = config.getConfig('device'); } + if (!request.device) { + request.device = {}; + } + if (!request.device.w) { + request.device.w = window.innerWidth; + } + if (!request.device.h) { + request.device.h = window.innerHeight; + } } function transformHeightWidth(adUnit) { diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index 15aa94ad3356..77e7f3ad868c 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -558,6 +558,8 @@ describe('S2S Adapter', function () { const requestBid = JSON.parse(requests[0].requestBody); expect(requestBid.device).to.deep.equal({ ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC', + w: window.innerWidth, + h: window.innerHeight }); expect(requestBid.app).to.deep.equal({ bundle: 'com.test.app', @@ -581,6 +583,31 @@ describe('S2S Adapter', function () { const requestBid = JSON.parse(requests[0].requestBody); expect(requestBid.device).to.deep.equal({ ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC', + w: window.innerWidth, + h: window.innerHeight + }); + expect(requestBid.app).to.deep.equal({ + bundle: 'com.test.app', + publisher: {'id': '1'} + }); + }); + + it('adds device.w and device.h even if the config lacks a device object', function () { + const s2sConfig = Object.assign({}, CONFIG, { + endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' + }); + + const _config = { + s2sConfig: s2sConfig, + app: { bundle: 'com.test.app' }, + }; + + config.setConfig(_config); + adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + const requestBid = JSON.parse(requests[0].requestBody); + expect(requestBid.device).to.deep.equal({ + w: window.innerWidth, + h: window.innerHeight }); expect(requestBid.app).to.deep.equal({ bundle: 'com.test.app',