From e23dba3c0ea8ddd605165a4effe14c7cd52acb11 Mon Sep 17 00:00:00 2001 From: Jonathan Nadarajah <50102657+jogury@users.noreply.github.com> Date: Thu, 19 May 2022 23:31:32 +0200 Subject: [PATCH] Ogury Bid Adapter: Add device infos with size in bidrequest (#8416) * Add device infos with size in bidrequest * trigger rebuild on CI to fix tests * restore sinon stubbed methods after all tests * restore stub correctly at end of tests * trigger rebuild on CI to fix tests --- modules/oguryBidAdapter.js | 28 +++- test/spec/modules/oguryBidAdapter_spec.js | 184 +++++++++++++++++++++- 2 files changed, 208 insertions(+), 4 deletions(-) diff --git a/modules/oguryBidAdapter.js b/modules/oguryBidAdapter.js index 295a0042f4b..746fc1eec03 100644 --- a/modules/oguryBidAdapter.js +++ b/modules/oguryBidAdapter.js @@ -10,7 +10,29 @@ const DEFAULT_TIMEOUT = 1000; const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request'; const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io'; const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io'; -const ADAPTER_VERSION = '1.2.11'; +const ADAPTER_VERSION = '1.2.12'; + +function getClientWidth() { + const documentElementClientWidth = window.top.document.documentElement.clientWidth + ? window.top.document.documentElement.clientWidth + : 0 + const innerWidth = window.top.innerWidth ? window.top.innerWidth : 0 + const outerWidth = window.top.outerWidth ? window.top.outerWidth : 0 + const screenWidth = window.top.screen.width ? window.top.screen.width : 0 + + return documentElementClientWidth || innerWidth || outerWidth || screenWidth +} + +function getClientHeight() { + const documentElementClientHeight = window.top.document.documentElement.clientHeight + ? window.top.document.documentElement.clientHeight + : 0 + const innerHeight = window.top.innerHeight ? window.top.innerHeight : 0 + const outerHeight = window.top.outerHeight ? window.top.outerHeight : 0 + const screenHeight = window.top.screen.height ? window.top.screen.height : 0 + + return documentElementClientHeight || innerHeight || outerHeight || screenHeight +} function isBidRequestValid(bid) { const adUnitSizes = getAdUnitSizes(bid); @@ -60,6 +82,10 @@ function buildRequests(validBidRequests, bidderRequest) { ext: { adapterversion: ADAPTER_VERSION, prebidversion: '$prebid.version$' + }, + device: { + w: getClientWidth(), + h: getClientHeight() } }; diff --git a/test/spec/modules/oguryBidAdapter_spec.js b/test/spec/modules/oguryBidAdapter_spec.js index 0d1a530044f..028c780d9fb 100644 --- a/test/spec/modules/oguryBidAdapter_spec.js +++ b/test/spec/modules/oguryBidAdapter_spec.js @@ -226,6 +226,15 @@ describe('OguryBidAdapter', function () { }); describe('buildRequests', function () { + const stubbedWidth = 200 + const stubbedHeight = 600 + const stubbedWidthMethod = sinon.stub(window.top.document.documentElement, 'clientWidth').get(function() { + return stubbedWidth; + }); + const stubbedHeightMethod = sinon.stub(window.top.document.documentElement, 'clientHeight').get(function() { + return stubbedHeight; + }); + const defaultTimeout = 1000; const expectedRequestObject = { id: bidRequests[0].auctionId, @@ -270,10 +279,19 @@ describe('OguryBidAdapter', function () { }, ext: { prebidversion: '$prebid.version$', - adapterversion: '1.2.11' + adapterversion: '1.2.12' + }, + device: { + w: stubbedWidth, + h: stubbedHeight } }; + after(function() { + stubbedWidthMethod.restore(); + stubbedHeightMethod.restore(); + }); + it('sends bid request to ENDPOINT via POST', function () { const validBidRequests = utils.deepClone(bidRequests) @@ -290,6 +308,166 @@ describe('OguryBidAdapter', function () { expect(request.data.regs.ext.gdpr).to.be.a('number'); }); + describe('getClientWidth', () => { + function testGetClientWidth(testGetClientSizeParams) { + const stubbedClientWidth = sinon.stub(window.top.document.documentElement, 'clientWidth').get(function() { + return testGetClientSizeParams.docClientSize + }) + + const stubbedInnerWidth = sinon.stub(window.top, 'innerWidth').get(function() { + return testGetClientSizeParams.innerSize + }) + + const stubbedOuterWidth = sinon.stub(window.top, 'outerWidth').get(function() { + return testGetClientSizeParams.outerSize + }) + + const stubbedWidth = sinon.stub(window.top.screen, 'width').get(function() { + return testGetClientSizeParams.screenSize + }) + + const validBidRequests = utils.deepClone(bidRequests) + + const request = spec.buildRequests(validBidRequests, bidderRequest); + expect(request.data.device.w).to.equal(testGetClientSizeParams.expectedSize); + + stubbedClientWidth.restore(); + stubbedInnerWidth.restore(); + stubbedOuterWidth.restore(); + stubbedWidth.restore(); + } + + it('should get documentElementClientWidth by default', () => { + testGetClientWidth({ + docClientSize: 22, + innerSize: 50, + outerSize: 45, + screenSize: 10, + expectedSize: 22, + }) + }) + + it('should get innerWidth as first fallback', () => { + testGetClientWidth({ + docClientSize: undefined, + innerSize: 700, + outerSize: 650, + screenSize: 10, + expectedSize: 700, + }) + }) + + it('should get outerWidth as second fallback', () => { + testGetClientWidth({ + docClientSize: undefined, + innerSize: undefined, + outerSize: 650, + screenSize: 10, + expectedSize: 650, + }) + }) + + it('should get screenWidth as last fallback', () => { + testGetClientWidth({ + docClientSize: undefined, + innerSize: undefined, + outerSize: undefined, + screenSize: 10, + expectedSize: 10, + }); + }); + + it('should return 0 if all window width values are undefined', () => { + testGetClientWidth({ + docClientSize: undefined, + innerSize: undefined, + outerSize: undefined, + screenSize: undefined, + expectedSize: 0, + }); + }); + }); + + describe('getClientHeight', () => { + function testGetClientHeight(testGetClientSizeParams) { + const stubbedClientHeight = sinon.stub(window.top.document.documentElement, 'clientHeight').get(function() { + return testGetClientSizeParams.docClientSize + }) + + const stubbedInnerHeight = sinon.stub(window.top, 'innerHeight').get(function() { + return testGetClientSizeParams.innerSize + }) + + const stubbedOuterHeight = sinon.stub(window.top, 'outerHeight').get(function() { + return testGetClientSizeParams.outerSize + }) + + const stubbedHeight = sinon.stub(window.top.screen, 'height').get(function() { + return testGetClientSizeParams.screenSize + }) + + const validBidRequests = utils.deepClone(bidRequests) + + const request = spec.buildRequests(validBidRequests, bidderRequest); + expect(request.data.device.h).to.equal(testGetClientSizeParams.expectedSize); + + stubbedClientHeight.restore(); + stubbedInnerHeight.restore(); + stubbedOuterHeight.restore(); + stubbedHeight.restore(); + } + + it('should get documentElementClientHeight by default', () => { + testGetClientHeight({ + docClientSize: 420, + innerSize: 500, + outerSize: 480, + screenSize: 230, + expectedSize: 420, + }); + }); + + it('should get innerHeight as first fallback', () => { + testGetClientHeight({ + docClientSize: undefined, + innerSize: 500, + outerSize: 480, + screenSize: 230, + expectedSize: 500, + }); + }); + + it('should get outerHeight as second fallback', () => { + testGetClientHeight({ + docClientSize: undefined, + innerSize: undefined, + outerSize: 480, + screenSize: 230, + expectedSize: 480, + }); + }); + + it('should get screenHeight as last fallback', () => { + testGetClientHeight({ + docClientSize: undefined, + innerSize: undefined, + outerSize: undefined, + screenSize: 230, + expectedSize: 230, + }); + }); + + it('should return 0 if all window height values are undefined', () => { + testGetClientHeight({ + docClientSize: undefined, + innerSize: undefined, + outerSize: undefined, + screenSize: undefined, + expectedSize: 0, + }); + }); + }); + it('should not add gdpr infos if not present', () => { const bidderRequestWithoutGdpr = { ...bidderRequest, @@ -481,7 +659,7 @@ describe('OguryBidAdapter', function () { advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[0].adomain }, nurl: openRtbBidResponse.body.seatbid[0].bid[0].nurl, - adapterVersion: '1.2.11', + adapterVersion: '1.2.12', prebidVersion: '$prebid.version$' }, { requestId: openRtbBidResponse.body.seatbid[0].bid[1].impid, @@ -498,7 +676,7 @@ describe('OguryBidAdapter', function () { advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[1].adomain }, nurl: openRtbBidResponse.body.seatbid[0].bid[1].nurl, - adapterVersion: '1.2.11', + adapterVersion: '1.2.12', prebidVersion: '$prebid.version$' }]