Skip to content

Commit

Permalink
Ogury Bid Adapter: Add device infos with size in bidrequest (#8416)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jogury authored May 19, 2022
1 parent b2c496c commit e23dba3
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 4 deletions.
28 changes: 27 additions & 1 deletion modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -60,6 +82,10 @@ function buildRequests(validBidRequests, bidderRequest) {
ext: {
adapterversion: ADAPTER_VERSION,
prebidversion: '$prebid.version$'
},
device: {
w: getClientWidth(),
h: getClientHeight()
}
};

Expand Down
184 changes: 181 additions & 3 deletions test/spec/modules/oguryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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$'
}]

Expand Down

0 comments on commit e23dba3

Please sign in to comment.