Skip to content

Commit

Permalink
GridNMBidAdapter: Use absent in video params data from mediaTypes (pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMediaGrid authored Jun 2, 2021
1 parent befd64e commit 25106da
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 19 deletions.
2 changes: 1 addition & 1 deletion modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) {
height: serverBid.h,
creativeId: serverBid.auid, // bid.bidId,
currency: 'USD',
netRevenue: false,
netRevenue: true,
ttl: TIME_TO_LIVE,
meta: {
advertiserDomains: serverBid.adomain ? serverBid.adomain : []
Expand Down
37 changes: 32 additions & 5 deletions modules/gridNMBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const LOG_ERROR_MESS = {
hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - '
};

const VIDEO_KEYS = ['mimes', 'protocols', 'startdelay', 'placement', 'linearity', 'skip', 'skipmin', 'skipafter', 'sequence', 'battr', 'maxextended', 'minbitrate', 'maxbitrate', 'boxingallowed', 'playbackmethod', 'playbackend', 'delivery', 'pos', 'companionad', 'api', 'companiontype'];

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [ VIDEO ],
Expand All @@ -39,11 +41,12 @@ export const spec = {
!bid.params.secid || !utils.isStr(bid.params.secid) ||
!bid.params.pubid || !utils.isStr(bid.params.pubid);

const video = utils.deepAccess(bid, 'mediaTypes.video') || {};
const { protocols = video.protocols, mimes = video.mimes } = utils.deepAccess(bid, 'params.video') || {};
if (!invalid) {
invalid = !bid.params.video || !bid.params.video.protocols || !bid.params.video.mimes;
invalid = !protocols || !mimes;
}
if (!invalid) {
const {protocols, mimes} = bid.params.video;
invalid = !utils.isArray(mimes) || !mimes.length || mimes.filter((it) => !(it && utils.isStr(it))).length;
if (!invalid) {
invalid = !utils.isArray(protocols) || !protocols.length || protocols.filter((it) => !(utils.isNumber(it) && it > 0 && !(it % 1))).length;
Expand All @@ -63,7 +66,7 @@ export const spec = {
const requests = [];

bids.forEach(bid => {
const {params, bidderRequestId, sizes} = bid;
const { params, bidderRequestId, sizes } = bid;
const payload = {
sizes: utils.parseSizesInput(sizes).join(','),
r: bidderRequestId,
Expand Down Expand Up @@ -91,11 +94,32 @@ export const spec = {
}
}

const video = utils.deepAccess(bid, 'mediaTypes.video') || {};
const paramsVideo = Object.assign({}, params.video);
VIDEO_KEYS.forEach((key) => {
if (!(key in paramsVideo) && key in video) {
paramsVideo[key] = video[key];
}
});

if (!paramsVideo.size && video.playerSize && video.playerSize.length === 2) {
paramsVideo.size = video.playerSize.join('x');
}

if (!('mind' in paramsVideo) && 'minduration' in video) {
paramsVideo.mind = video.minduration;
}
if (!('maxd' in paramsVideo) && 'maxduration' in video) {
paramsVideo.maxd = video.maxduration;
}

const paramsToSend = Object.assign({}, params, {video: paramsVideo});

requests.push({
method: 'POST',
url: ENDPOINT_URL + '?' + utils.parseQueryStringParameters(payload).replace(/\&$/, ''),
bid: bid,
data: params // content
data: paramsToSend // content
});
});

Expand Down Expand Up @@ -139,11 +163,14 @@ export const spec = {
height: serverBid.h,
creativeId: serverBid.auid || bid.bidderRequestId,
currency: 'USD',
netRevenue: false,
netRevenue: true,
ttl: TIME_TO_LIVE,
dealId: serverBid.dealid,
vastXml: serverBid.adm,
mediaType: VIDEO,
meta: {
advertiserDomains: serverBid.adomain ? serverBid.adomain : []
},
adResponse: {
content: serverBid.adm
}
Expand Down
20 changes: 10 additions & 10 deletions test/spec/modules/gridBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 1</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand Down Expand Up @@ -615,7 +615,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 1</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand All @@ -631,7 +631,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 2</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand All @@ -647,7 +647,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 3</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand Down Expand Up @@ -709,7 +709,7 @@ describe('TheMediaGrid Adapter', function () {
'height': 600,
'currency': 'USD',
'mediaType': 'video',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand All @@ -728,7 +728,7 @@ describe('TheMediaGrid Adapter', function () {
'height': undefined,
'currency': 'USD',
'mediaType': 'video',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand Down Expand Up @@ -862,7 +862,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 1</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand All @@ -878,7 +878,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 2</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand All @@ -894,7 +894,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 3</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand All @@ -910,7 +910,7 @@ describe('TheMediaGrid Adapter', function () {
'ad': '<div>test content 4</div>',
'currency': 'USD',
'mediaType': 'banner',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'meta': {
advertiserDomains: []
Expand Down
85 changes: 82 additions & 3 deletions test/spec/modules/gridNMBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,43 @@ describe('TheMediaGridNM Adapter', function () {
expect(spec.isBidRequestValid(invalidBid)).to.equal(false);
});
});

it('should return true when required params is absent, but available in mediaTypes', function () {
const paramsList = [
{
'source': 'jwp',
'secid': '11',
'pubid': '22',
'video': {
'protocols': [1, 2, 3, 4, 5, 6]
}
},
{
'source': 'jwp',
'secid': '11',
'pubid': '22',
'video': {
'mimes': ['video/mp4', 'video/x-ms-wmv'],
}
}
];

const mediaTypes = {
video: {
mimes: ['video/mp4', 'video/x-ms-wmv'],
playerSize: [200, 300],
protocols: [1, 2, 3, 4, 5, 6]
}
};

paramsList.forEach((params) => {
const validBid = Object.assign({}, bid);
delete validBid.params;
validBid.params = params;
validBid.mediaTypes = mediaTypes;
expect(spec.isBidRequestValid(validBid)).to.equal(true);
});
});
});

describe('buildRequests', function () {
Expand Down Expand Up @@ -198,6 +235,39 @@ describe('TheMediaGridNM Adapter', function () {
});
});

it('should attach valid params from mediaTypes', function () {
const mediaTypes = {
video: {
skipafter: 10,
minduration: 10,
maxduration: 100,
protocols: [1, 3, 4],
playerSize: [300, 250]
}
};
const bidRequest = Object.assign({ mediaTypes }, bidRequests[0]);
const req = spec.buildRequests([bidRequest], bidderRequest)[0];
const expectedVideo = {
'skipafter': 10,
'mind': 10,
'maxd': 100,
'mimes': ['video/mp4', 'video/x-ms-wmv'],
'protocols': [1, 2, 3, 4, 5, 6],
'size': '300x250'
};
const expectedParams = Object.assign({}, bidRequest.params);
expectedParams.video = Object.assign(expectedParams.video, expectedVideo);

expect(req.url).to.be.an('string');
const payload = parseRequestUrl(req.url);
expect(payload).to.have.property('u', referrer);
expect(payload).to.have.property('r', '22edbae2733bf6');
expect(payload).to.have.property('wrapperType', 'Prebid_js');
expect(payload).to.have.property('wrapperVersion', '$prebid.version$');
expect(payload).to.have.property('sizes', '300x250,300x600');
expect(req.data).to.deep.equal(expectedParams);
});

it('if gdprConsent is present payload must have gdpr params', function () {
const [request] = spec.buildRequests([bidRequests[0]], {gdprConsent: {consentString: 'AAA', gdprApplies: true}, refererInfo: bidderRequest.refererInfo});
expect(request.url).to.be.an('string');
Expand Down Expand Up @@ -235,7 +305,7 @@ describe('TheMediaGridNM Adapter', function () {
describe('interpretResponse', function () {
const responses = [
{'bid': [{'price': 1.15, 'adm': '<VAST version=\"3.0\">\n<Ad id=\"21341234\"><\/Ad>\n<\/VAST>', 'content_type': 'video', 'h': 250, 'w': 300, 'dealid': 11}], 'seat': '2'},
{'bid': [{'price': 0.5, 'adm': '<VAST version=\"3.0\">\n<Ad id=\"21341235\"><\/Ad>\n<\/VAST>', 'content_type': 'video', 'h': 600, 'w': 300}], 'seat': '2'},
{'bid': [{'price': 0.5, 'adm': '<VAST version=\"3.0\">\n<Ad id=\"21341235\"><\/Ad>\n<\/VAST>', 'content_type': 'video', 'h': 600, 'w': 300, adomain: ['my_domain.ru']}], 'seat': '2'},
{'bid': [{'price': 0, 'h': 250, 'w': 300}], 'seat': '2'},
{'bid': [{'price': 0, 'adm': '<VAST version=\"3.0\">\n<Ad id=\"21341237\"><\/Ad>\n<\/VAST>', 'h': 250, 'w': 300}], 'seat': '2'},
undefined,
Expand Down Expand Up @@ -302,9 +372,12 @@ describe('TheMediaGridNM Adapter', function () {
'height': 250,
'currency': 'USD',
'mediaType': 'video',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'vastXml': '<VAST version=\"3.0\">\n<Ad id=\"21341234\"><\/Ad>\n<\/VAST>',
'meta': {
'advertiserDomains': []
},
'adResponse': {
'content': '<VAST version=\"3.0\">\n<Ad id=\"21341234\"><\/Ad>\n<\/VAST>'
}
Expand All @@ -318,9 +391,12 @@ describe('TheMediaGridNM Adapter', function () {
'height': 600,
'currency': 'USD',
'mediaType': 'video',
'netRevenue': false,
'netRevenue': true,
'ttl': 360,
'vastXml': '<VAST version=\"3.0\">\n<Ad id=\"21341235\"><\/Ad>\n<\/VAST>',
'meta': {
'advertiserDomains': ['my_domain.ru']
},
'adResponse': {
'content': '<VAST version=\"3.0\">\n<Ad id=\"21341235\"><\/Ad>\n<\/VAST>'
}
Expand Down Expand Up @@ -352,6 +428,9 @@ describe('TheMediaGridNM Adapter', function () {
'bidId': '2bc598e42b6a',
'bidderRequestId': '39d74f5b71464',
'auctionId': '1cbd2feafe5e8b',
'meta': {
'advertiserDomains': []
},
'mediaTypes': {
'video': {
'context': 'instream'
Expand Down

0 comments on commit 25106da

Please sign in to comment.