Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions modules/adformOpenRTBBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,3 +188,7 @@ function setOnAny(collection, key) {
}
}
}

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