Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mediasquare: add native and video support #5823

Merged
merged 8 commits into from
Nov 4, 2020
14 changes: 11 additions & 3 deletions modules/mediasquareBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ajax} from '../src/ajax.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';

const BIDDER_CODE = 'mediasquare';
const BIDDER_URL_PROD = 'https://pbs-front.mediasquare.fr/'
Expand All @@ -13,7 +13,7 @@ const BIDDER_ENDPOINT_WINNING = 'winning';
export const spec = {
code: BIDDER_CODE,
aliases: ['msq'], // short code
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, NATIVE, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
Expand Down Expand Up @@ -99,6 +99,14 @@ export const spec = {
'code': value['code']
}
};
if ('native' in value) {
bidResponse['native'] = value['native'];
bidResponse['mediaType'] = 'native';
} else if ('video' in value) {
if ('url' in value['video']) { bidResponse['vastUrl'] = value['video']['url'] }
if ('xml' in value['video']) { bidResponse['vastXml'] = value['video']['xml'] }
bidResponse['mediaType'] = 'video';
}
if (value.hasOwnProperty('deal_id')) { bidResponse['dealId'] = value['deal_id']; }
bidResponses.push(bidResponse);
});
Expand Down Expand Up @@ -136,7 +144,7 @@ export const spec = {
// fires a pixel to confirm a winning bid
let params = [];
let endpoint = document.location.search.match(/msq_test=true/) ? BIDDER_URL_TEST : BIDDER_URL_PROD;
let paramsToSearchFor = ['cpm', 'size', 'mediaType', 'currency', 'creativeId', 'adUnitCode', 'timeToRespond', 'auctionId', 'requestId']
let paramsToSearchFor = ['cpm', 'size', 'mediaType', 'currency', 'creativeId', 'adUnitCode', 'timeToRespond']
if (bid.hasOwnProperty('mediasquare')) {
if (bid['mediasquare'].hasOwnProperty('bidder')) { params.push('bidder=' + bid['mediasquare']['bidder']); }
if (bid['mediasquare'].hasOwnProperty('code')) { params.push('code=' + bid['mediasquare']['code']); }
Expand Down
56 changes: 56 additions & 0 deletions test/spec/modules/mediasquareBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,43 @@ describe('MediaSquare bid adapter tests', function () {
code: 'publishername_atf_desktop_rg_pave'
},
}];
var VIDEO_PARAMS = [{
adUnitCode: 'banner-div',
bidId: 'aaaa1234',
auctionId: 'bbbb1234',
transactionId: 'cccc1234',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480],
mimes: ['video/mp4'],
}
},
bidder: 'mediasquare',
GLStephen marked this conversation as resolved.
Show resolved Hide resolved
params: {
owner: 'test',
code: 'publishername_atf_desktop_rg_pave'
},
}];
var NATIVE_PARAMS = [{
adUnitCode: 'banner-div',
bidId: 'aaaa1234',
auctionId: 'bbbb1234',
transactionId: 'cccc1234',
mediaTypes: {
native: {
title: {
required: true,
len: 80
},
}
},
bidder: 'mediasquare',
params: {
owner: 'test',
code: 'publishername_atf_desktop_rg_pave'
},
}];

var BID_RESPONSE = {'body': {
'responses': [{
Expand Down Expand Up @@ -128,4 +165,23 @@ describe('MediaSquare bid adapter tests', function () {
expect(syncs[0]).to.have.property('type').and.to.equal('image');
expect(syncs[0]).to.have.property('url').and.to.equal('http://www.cookie.sync.org/');
});
it('Verifies native in bid response', function () {
const request = spec.buildRequests(NATIVE_PARAMS, DEFAULT_OPTIONS);
BID_RESPONSE.body.responses[0].native = {'title': 'native title'};
const response = spec.interpretResponse(BID_RESPONSE, request);
expect(response).to.have.lengthOf(1);
const bid = response[0];
expect(bid).to.have.property('native');
delete BID_RESPONSE.body.responses[0].native;
});
it('Verifies video in bid response', function () {
const request = spec.buildRequests(VIDEO_PARAMS, DEFAULT_OPTIONS);
BID_RESPONSE.body.responses[0].video = {'xml': 'my vast XML', 'url': 'my vast url'};
const response = spec.interpretResponse(BID_RESPONSE, request);
expect(response).to.have.lengthOf(1);
const bid = response[0];
expect(bid).to.have.property('vastXml');
expect(bid).to.have.property('vastUrl');
delete BID_RESPONSE.body.responses[0].video;
});
});