Skip to content

Commit

Permalink
adformOpenRTB adapter: size targeting using aspect ratios (#4019)
Browse files Browse the repository at this point in the history
* adformOpenRTB adatper: size targeting using aspect ratios

* avoid throwing errors while parsing aspect_ratios
  • Loading branch information
braizhas authored and msm0504 committed Jul 30, 2019
1 parent 03bc30d commit 0561222
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 5 deletions.
27 changes: 24 additions & 3 deletions modules/adformOpenRTBBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,28 @@ export const spec = {
};
if (props) {
asset.id = props.id;
let wmin, hmin, w, h;
let aRatios = bidParams.aspect_ratios;

if (aRatios && aRatios[0]) {
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;
Expand Down Expand Up @@ -175,3 +192,7 @@ function setOnAny(collection, key) {
}
}
}

function flatten(arr) {
return [].concat(...arr);
}
93 changes: 91 additions & 2 deletions test/spec/modules/adformOpenRTBBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,102 @@ 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 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 () {
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]);
});
});
});
Expand Down

0 comments on commit 0561222

Please sign in to comment.