Skip to content

Commit 62c20dc

Browse files
committed
Update support for video playerSize
1 parent 8fa2a84 commit 62c20dc

File tree

2 files changed

+129
-37
lines changed

2 files changed

+129
-37
lines changed

modules/conversantBidAdapter.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BANNER, VIDEO } from 'src/mediaTypes';
44

55
const BIDDER_CODE = 'conversant';
66
const URL = '//web.hb.ad.cpe.dotomi.com/s2s/header/24';
7-
const VERSION = '2.2.3';
7+
const VERSION = '2.2.4';
88

99
export const spec = {
1010
code: BIDDER_CODE,
@@ -62,8 +62,6 @@ export const spec = {
6262
siteId = utils.getBidIdParameter('site_id', bid.params);
6363
requestId = bid.auctionId;
6464

65-
const format = convertSizes(bid.sizes);
66-
6765
const imp = {
6866
id: bid.bidId,
6967
secure: secure,
@@ -72,25 +70,31 @@ export const spec = {
7270
displaymanagerver: VERSION
7371
};
7472

75-
copyOptProperty(bid.params, 'tag_id', imp, 'tagid');
73+
copyOptProperty(bid.params.tag_id, imp, 'tagid');
7674

7775
if (isVideoRequest(bid)) {
78-
const video = {
79-
w: format[0].w,
80-
h: format[0].h
81-
};
76+
const videoData = utils.deepAccess(bid, 'mediaTypes.video') || {};
77+
const format = convertSizes(videoData.playerSize || bid.sizes);
78+
const video = {};
79+
80+
if (format && format[0]) {
81+
copyOptProperty(format[0].w, video, 'w');
82+
copyOptProperty(format[0].h, video, 'h');
83+
}
8284

83-
copyOptProperty(bid.params, 'position', video, 'pos');
84-
copyOptProperty(bid.params, 'mimes', video);
85-
copyOptProperty(bid.params, 'maxduration', video);
86-
copyOptProperty(bid.params, 'protocols', video);
87-
copyOptProperty(bid.params, 'api', video);
85+
copyOptProperty(bid.params.position, video, 'pos');
86+
copyOptProperty(bid.params.mimes || videoData.mimes, video, 'mimes');
87+
copyOptProperty(bid.params.maxduration, video, 'maxduration');
88+
copyOptProperty(bid.params.protocols || videoData.protocols, video, 'protocols');
89+
copyOptProperty(bid.params.api || videoData.api, video, 'api');
8890

8991
imp.video = video;
9092
} else {
93+
const bannerData = utils.deepAccess(bid, 'mediaTypes.banner') || {};
94+
const format = convertSizes(bannerData.sizes || bid.sizes);
9195
const banner = {format: format};
9296

93-
copyOptProperty(bid.params, 'position', banner, 'pos');
97+
copyOptProperty(bid.params.position, banner, 'pos');
9498

9599
imp.banner = banner;
96100
}
@@ -249,11 +253,12 @@ function getDevice() {
249253
*/
250254
function convertSizes(bidSizes) {
251255
let format;
252-
253-
if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') {
254-
format = [{w: bidSizes[0], h: bidSizes[1]}];
255-
} else {
256-
format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; });
256+
if (Array.isArray(bidSizes)) {
257+
if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') {
258+
format = [{w: bidSizes[0], h: bidSizes[1]}];
259+
} else {
260+
format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; });
261+
}
257262
}
258263

259264
return format;
@@ -272,16 +277,13 @@ function isVideoRequest(bid) {
272277
/**
273278
* Copy property if exists from src to dst
274279
*
275-
* @param {object} src
276-
* @param {string} srcName
277-
* @param {object} dst
278-
* @param {string} [dstName] - Optional. If not specified then srcName is used.
280+
* @param {object} src - source object
281+
* @param {object} dst - destination object
282+
* @param {string} dstName - destination property name
279283
*/
280-
function copyOptProperty(src, srcName, dst, dstName) {
281-
dstName = dstName || srcName;
282-
const obj = utils.getBidIdParameter(srcName, src);
283-
if (obj !== '') {
284-
dst[dstName] = obj;
284+
function copyOptProperty(src, dst, dstName) {
285+
if (src) {
286+
dst[dstName] = src;
285287
}
286288
}
287289

test/spec/modules/conversantBidAdapter_spec.js

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('Conversant adapter tests', function() {
88
const siteId = '108060';
99

1010
const bidRequests = [
11+
// banner with single size
1112
{
1213
bidder: 'conversant',
1314
params: {
@@ -23,19 +24,27 @@ describe('Conversant adapter tests', function() {
2324
bidId: 'bid000',
2425
bidderRequestId: '117d765b87bed38',
2526
auctionId: 'req000'
26-
}, {
27+
},
28+
// banner with sizes in mediaTypes.banner.sizes
29+
{
2730
bidder: 'conversant',
2831
params: {
2932
site_id: siteId,
3033
secure: false
3134
},
35+
mediaTypes: {
36+
banner: {
37+
sizes: [[728, 90], [468, 60]]
38+
}
39+
},
3240
placementCode: 'pcode001',
3341
transactionId: 'tx001',
34-
sizes: [[468, 60]],
3542
bidId: 'bid001',
3643
bidderRequestId: '117d765b87bed38',
3744
auctionId: 'req000'
38-
}, {
45+
},
46+
// banner with tag id and position
47+
{
3948
bidder: 'conversant',
4049
params: {
4150
site_id: siteId,
@@ -49,7 +58,9 @@ describe('Conversant adapter tests', function() {
4958
bidId: 'bid002',
5059
bidderRequestId: '117d765b87bed38',
5160
auctionId: 'req000'
52-
}, {
61+
},
62+
// video with single size
63+
{
5364
bidder: 'conversant',
5465
params: {
5566
site_id: siteId,
@@ -69,6 +80,47 @@ describe('Conversant adapter tests', function() {
6980
bidId: 'bid003',
7081
bidderRequestId: '117d765b87bed38',
7182
auctionId: 'req000'
83+
},
84+
// video with playerSize
85+
{
86+
bidder: 'conversant',
87+
params: {
88+
site_id: siteId,
89+
maxduration: 30,
90+
api: [2, 3]
91+
},
92+
mediaTypes: {
93+
video: {
94+
context: 'instream',
95+
playerSize: [1024, 768],
96+
api: [1, 2],
97+
protocols: [1, 2, 3],
98+
mimes: ['video/mp4', 'video/x-flv']
99+
}
100+
},
101+
placementCode: 'pcode004',
102+
transactionId: 'tx004',
103+
bidId: 'bid004',
104+
bidderRequestId: '117d765b87bed38',
105+
auctionId: 'req000'
106+
},
107+
// video without sizes
108+
{
109+
bidder: 'conversant',
110+
params: {
111+
site_id: siteId
112+
},
113+
mediaTypes: {
114+
video: {
115+
context: 'instream',
116+
mimes: ['video/mp4', 'video/x-flv']
117+
}
118+
},
119+
placementCode: 'pcode005',
120+
transactionId: 'tx005',
121+
bidId: 'bid005',
122+
bidderRequestId: '117d765b87bed38',
123+
auctionId: 'req000'
72124
}];
73125

74126
const bidResponses = {
@@ -128,6 +180,8 @@ describe('Conversant adapter tests', function() {
128180
expect(spec.isBidRequestValid(bidRequests[1])).to.be.true;
129181
expect(spec.isBidRequestValid(bidRequests[2])).to.be.true;
130182
expect(spec.isBidRequestValid(bidRequests[3])).to.be.true;
183+
expect(spec.isBidRequestValid(bidRequests[4])).to.be.true;
184+
expect(spec.isBidRequestValid(bidRequests[5])).to.be.true;
131185

132186
const simpleVideo = JSON.parse(JSON.stringify(bidRequests[3]));
133187
simpleVideo.params.site_id = 123;
@@ -150,7 +204,7 @@ describe('Conversant adapter tests', function() {
150204
expect(payload).to.have.property('id', 'req000');
151205
expect(payload).to.have.property('at', 1);
152206
expect(payload).to.have.property('imp');
153-
expect(payload.imp).to.be.an('array').with.lengthOf(4);
207+
expect(payload.imp).to.be.an('array').with.lengthOf(6);
154208

155209
expect(payload.imp[0]).to.have.property('id', 'bid000');
156210
expect(payload.imp[0]).to.have.property('secure', 0);
@@ -168,18 +222,18 @@ describe('Conversant adapter tests', function() {
168222
expect(payload.imp[1]).to.have.property('secure', 0);
169223
expect(payload.imp[1]).to.have.property('bidfloor', 0);
170224
expect(payload.imp[1]).to.have.property('displaymanager', 'Prebid.js');
171-
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
225+
expect(payload.imp[1]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
172226
expect(payload.imp[1]).to.not.have.property('tagid');
173227
expect(payload.imp[1]).to.have.property('banner');
174228
expect(payload.imp[1].banner).to.not.have.property('pos');
175229
expect(payload.imp[1].banner).to.have.property('format');
176-
expect(payload.imp[1].banner.format).to.deep.equal([{w: 468, h: 60}]);
230+
expect(payload.imp[1].banner.format).to.deep.equal([{w: 728, h: 90}, {w: 468, h: 60}]);
177231

178232
expect(payload.imp[2]).to.have.property('id', 'bid002');
179233
expect(payload.imp[2]).to.have.property('secure', 0);
180234
expect(payload.imp[2]).to.have.property('bidfloor', 0);
181235
expect(payload.imp[2]).to.have.property('displaymanager', 'Prebid.js');
182-
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
236+
expect(payload.imp[2]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
183237
expect(payload.imp[2]).to.have.property('banner');
184238
expect(payload.imp[2].banner).to.have.property('pos', 2);
185239
expect(payload.imp[2].banner).to.have.property('format');
@@ -189,7 +243,7 @@ describe('Conversant adapter tests', function() {
189243
expect(payload.imp[3]).to.have.property('secure', 0);
190244
expect(payload.imp[3]).to.have.property('bidfloor', 0);
191245
expect(payload.imp[3]).to.have.property('displaymanager', 'Prebid.js');
192-
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
246+
expect(payload.imp[3]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
193247
expect(payload.imp[3]).to.not.have.property('tagid');
194248
expect(payload.imp[3]).to.have.property('video');
195249
expect(payload.imp[3].video).to.not.have.property('pos');
@@ -204,6 +258,42 @@ describe('Conversant adapter tests', function() {
204258
expect(payload.imp[3].video).to.have.property('maxduration', 30);
205259
expect(payload.imp[3]).to.not.have.property('banner');
206260

261+
expect(payload.imp[4]).to.have.property('id', 'bid004');
262+
expect(payload.imp[4]).to.have.property('secure', 0);
263+
expect(payload.imp[4]).to.have.property('bidfloor', 0);
264+
expect(payload.imp[4]).to.have.property('displaymanager', 'Prebid.js');
265+
expect(payload.imp[4]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
266+
expect(payload.imp[4]).to.not.have.property('tagid');
267+
expect(payload.imp[4]).to.have.property('video');
268+
expect(payload.imp[4].video).to.not.have.property('pos');
269+
expect(payload.imp[4].video).to.have.property('w', 1024);
270+
expect(payload.imp[4].video).to.have.property('h', 768);
271+
expect(payload.imp[4].video).to.have.property('mimes');
272+
expect(payload.imp[4].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']);
273+
expect(payload.imp[4].video).to.have.property('protocols');
274+
expect(payload.imp[4].video.protocols).to.deep.equal([1, 2, 3]);
275+
expect(payload.imp[4].video).to.have.property('api');
276+
expect(payload.imp[4].video.api).to.deep.equal([2, 3]);
277+
expect(payload.imp[4].video).to.have.property('maxduration', 30);
278+
expect(payload.imp[4]).to.not.have.property('banner');
279+
280+
expect(payload.imp[5]).to.have.property('id', 'bid005');
281+
expect(payload.imp[5]).to.have.property('secure', 0);
282+
expect(payload.imp[5]).to.have.property('bidfloor', 0);
283+
expect(payload.imp[5]).to.have.property('displaymanager', 'Prebid.js');
284+
expect(payload.imp[5]).to.have.property('displaymanagerver').that.matches(/^\d+\.\d+\.\d+$/);
285+
expect(payload.imp[5]).to.not.have.property('tagid');
286+
expect(payload.imp[5]).to.have.property('video');
287+
expect(payload.imp[5].video).to.not.have.property('pos');
288+
expect(payload.imp[5].video).to.not.have.property('w');
289+
expect(payload.imp[5].video).to.not.have.property('h');
290+
expect(payload.imp[5].video).to.have.property('mimes');
291+
expect(payload.imp[5].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']);
292+
expect(payload.imp[5].video).to.not.have.property('protocols');
293+
expect(payload.imp[5].video).to.not.have.property('api');
294+
expect(payload.imp[5].video).to.not.have.property('maxduration');
295+
expect(payload.imp[5]).to.not.have.property('banner');
296+
207297
expect(payload).to.have.property('site');
208298
expect(payload.site).to.have.property('id', siteId);
209299
expect(payload.site).to.have.property('mobile').that.is.oneOf([0, 1]);

0 commit comments

Comments
 (0)