Skip to content

Commit

Permalink
Set the OpenRTB device dimensions (prebid#3336)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
dbemiller authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent 80a151f commit 869e48c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 869e48c

Please sign in to comment.