From 9ec940c6f2ca223c62a4e20bd328b5d0a1ea32f3 Mon Sep 17 00:00:00 2001 From: Tomas Kovtun Date: Thu, 18 Jul 2019 16:51:45 +0300 Subject: [PATCH 1/2] adformOpenRTB adatper: size targeting using aspect ratios --- modules/adformOpenRTBBidAdapter.js | 27 ++++++- .../modules/adformOpenRTBBidAdapter_spec.js | 76 ++++++++++++++++++- 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/modules/adformOpenRTBBidAdapter.js b/modules/adformOpenRTBBidAdapter.js index 94433d907c4..e09dde374a7 100644 --- a/modules/adformOpenRTBBidAdapter.js +++ b/modules/adformOpenRTBBidAdapter.js @@ -66,11 +66,28 @@ export const spec = { }; if (props) { asset.id = props.id; + let wmin, hmin, w, h; + let aRatios = bidParams.aspect_ratios; + + if (aRatios) { + aRatios = aRatios[0]; + wmin = aRatios.min_width || 0; + hmin = aRatios.ratio_height * wmin / aRatios.ratio_width | 0; + } + + if (bidParams.sizes) { + const sizes = flatten(bidParams.sizes); + w = sizes[0]; + h = sizes[1]; + } + asset[props.name] = { len: bidParams.len, - wmin: bidParams.sizes && bidParams.sizes[0], - hmin: bidParams.sizes && bidParams.sizes[1], - type: props.type + type: props.type, + wmin, + hmin, + w, + h }; return asset; @@ -171,3 +188,7 @@ function setOnAny(collection, key) { } } } + +function flatten(arr) { + return [].concat(...arr); +} diff --git a/test/spec/modules/adformOpenRTBBidAdapter_spec.js b/test/spec/modules/adformOpenRTBBidAdapter_spec.js index 5c0009ab1c7..168ac4fe2af 100644 --- a/test/spec/modules/adformOpenRTBBidAdapter_spec.js +++ b/test/spec/modules/adformOpenRTBBidAdapter_spec.js @@ -262,13 +262,85 @@ describe('AdformOpenRTB adapter', function () { let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; assert.ok(assets[0].title); assert.equal(assets[0].title.len, 140); - assert.deepEqual(assets[1].img, { type: 3, wmin: 150, hmin: 50 }); - assert.deepEqual(assets[2].img, { type: 1, wmin: 50, hmin: 50 }); + assert.deepEqual(assets[1].img, { type: 3, w: 150, h: 50 }); + assert.deepEqual(assets[2].img, { type: 1, w: 50, h: 50 }); assert.deepEqual(assets[3].data, { type: 2, len: 140 }); assert.deepEqual(assets[4].data, { type: 1 }); assert.deepEqual(assets[5].data, { type: 12 }); assert.ok(!assets[6]); }); + + describe('icon/image sizing', function () { + it('should flatten sizes and utilise first pair', function () { + const validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + image: { + sizes: [[200, 300], [100, 200]] + }, + } + }]; + + let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; + assert.ok(assets[0].img); + assert.equal(assets[0].img.w, 200); + assert.equal(assets[0].img.h, 300); + }); + }); + + it('should utilise aspect_ratios', function () { + const validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + image: { + aspect_ratios: [{ + min_width: 100, + ratio_height: 3, + ratio_width: 1 + }] + }, + icon: { + aspect_ratios: [{ + min_width: 10, + ratio_height: 5, + ratio_width: 2 + }] + } + } + }]; + + let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; + assert.ok(assets[0].img); + assert.equal(assets[0].img.wmin, 100); + assert.equal(assets[0].img.hmin, 300); + + assert.ok(assets[1].img); + assert.equal(assets[1].img.wmin, 10); + assert.equal(assets[1].img.hmin, 25); + }); + }); + + it('should expect any dimensions if min_width not passed', function () { + const validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + image: { + aspect_ratios: [{ + ratio_height: 3, + ratio_width: 1 + }] + } + } + }]; + + let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; + assert.ok(assets[0].img); + assert.equal(assets[0].img.wmin, 0); + assert.equal(assets[0].img.hmin, 0); + assert.ok(!assets[1]); }); }); }); From 7d831f27d04b8ef9d6bddd9e1a5b288f4abf8594 Mon Sep 17 00:00:00 2001 From: Jurij Sinickij Date: Tue, 30 Jul 2019 16:52:35 +0300 Subject: [PATCH 2/2] avoid throwing errors while parsing aspect_ratios --- modules/adformOpenRTBBidAdapter.js | 2 +- .../modules/adformOpenRTBBidAdapter_spec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/adformOpenRTBBidAdapter.js b/modules/adformOpenRTBBidAdapter.js index e09dde374a7..40b979fc72d 100644 --- a/modules/adformOpenRTBBidAdapter.js +++ b/modules/adformOpenRTBBidAdapter.js @@ -69,7 +69,7 @@ export const spec = { let wmin, hmin, w, h; let aRatios = bidParams.aspect_ratios; - if (aRatios) { + if (aRatios && aRatios[0]) { aRatios = aRatios[0]; wmin = aRatios.min_width || 0; hmin = aRatios.ratio_height * wmin / aRatios.ratio_width | 0; diff --git a/test/spec/modules/adformOpenRTBBidAdapter_spec.js b/test/spec/modules/adformOpenRTBBidAdapter_spec.js index 168ac4fe2af..39caead5afc 100644 --- a/test/spec/modules/adformOpenRTBBidAdapter_spec.js +++ b/test/spec/modules/adformOpenRTBBidAdapter_spec.js @@ -320,6 +320,23 @@ describe('AdformOpenRTB adapter', function () { assert.equal(assets[1].img.wmin, 10); assert.equal(assets[1].img.hmin, 25); }); + + it('should not throw error if aspect_ratios config is not defined', function () { + const validBidRequests = [{ + bidId: 'bidId', + params: { siteId: 'siteId', mid: 1000 }, + nativeParams: { + image: { + aspect_ratios: [] + }, + icon: { + aspect_ratios: [] + } + } + }]; + + assert.doesNotThrow(() => spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } })); + }); }); it('should expect any dimensions if min_width not passed', function () {