Skip to content

Commit

Permalink
BetweenBidAdapter: add video support (prebid#7594)
Browse files Browse the repository at this point in the history
* add video

* Between Bid Adapter: update video

* BetweenBidAdapter: jst fix

* BetweenBitAdapter: update test
  • Loading branch information
anastasya123 authored and Chris Pabst committed Jan 10, 2022
1 parent e84b6e6 commit f10beab
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
22 changes: 19 additions & 3 deletions modules/betweenBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { getAdUnitSizes, parseSizesInput } from '../src/utils.js';
import { getRefererInfo } from '../src/refererDetection.js';

const BIDDER_CODE = 'between';
const ENDPOINT = 'https://ads.betweendigital.com/adjson?t=prebid';
let ENDPOINT = 'https://ads.betweendigital.com/adjson?t=prebid';
const CODE_TYPES = ['inpage', 'preroll', 'midroll', 'postroll'];

export const spec = {
code: BIDDER_CODE,
aliases: ['btw'],
supportedMediaTypes: ['banner'],
supportedMediaTypes: ['banner', 'video'],
/**
* Determines whether or not the given bid request is valid.
*
Expand All @@ -30,6 +31,8 @@ export const spec = {
const refInfo = getRefererInfo();

validBidRequests.forEach((i) => {
const video = i.mediaTypes && i.mediaTypes.video;

let params = {
eids: getUsersIds(i),
sizes: parseSizesInput(getAdUnitSizes(i)),
Expand All @@ -38,12 +41,21 @@ export const spec = {
tz: getTz(),
fl: getFl(),
rr: getRr(),
s: i.params.s,
s: i.params && i.params.s,
bidid: i.bidId,
transactionid: i.transactionId,
auctionid: i.auctionId
};

if (video) {
params.mediaType = 2;
params.maxd = video.maxd;
params.mind = video.mind;
params.pos = 'atf';
ENDPOINT += '&jst=pvc';
params.codeType = CODE_TYPES.includes(video.codeType) ? video.codeType : 'inpage';
}

if (i.params.itu !== undefined) {
params.itu = i.params.itu;
}
Expand Down Expand Up @@ -94,12 +106,15 @@ export const spec = {
*/
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];

for (var i = 0; i < serverResponse.body.length; i++) {
let bidResponse = {
requestId: serverResponse.body[i].bidid,
cpm: serverResponse.body[i].cpm || 0,
width: serverResponse.body[i].w,
height: serverResponse.body[i].h,
vastXml: serverResponse.body[i].vastXml,
mediaType: serverResponse.body[i].mediaType,
ttl: serverResponse.body[i].ttl,
creativeId: serverResponse.body[i].creativeid,
currency: serverResponse.body[i].currency || 'RUB',
Expand All @@ -109,6 +124,7 @@ export const spec = {
advertiserDomains: serverResponse.body[i].adomain ? serverResponse.body[i].adomain : []
}
};

bidResponses.push(bidResponse);
}
return bidResponses;
Expand Down
41 changes: 41 additions & 0 deletions test/spec/modules/betweenBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ describe('betweenBidAdapterTests', function () {
let req_data = JSON.parse(request.data)[0].data;
expect(req_data.bidid).to.equal('bid1234');
});

it('validate_video_params', function () {
let bidRequestData = [{
bidId: 'bid1234',
bidder: 'between',
params: {w: 240, h: 400, s: 1112},
mediaTypes: {
video: {
context: 'outstream',
playerSize: [970, 250],
maxd: 123,
mind: 234,
codeType: 'unknown code type'
}
},
}];
let request = spec.buildRequests(bidRequestData);
let req_data = JSON.parse(request.data)[0].data;

expect(req_data.mediaType).to.equal(2);
expect(req_data.maxd).to.equal(123);
expect(req_data.mind).to.equal(234);
expect(req_data.pos).to.equal('atf');
expect(req_data.codeType).to.equal('inpage');
});

it('validate itu param', function() {
let bidRequestData = [{
bidId: 'bid1234',
Expand Down Expand Up @@ -230,6 +256,21 @@ describe('betweenBidAdapterTests', function () {
expect(bid.requestId).to.equal('bid1234');
expect(bid.ad).to.equal('Ad html');
});

it('validate_response_video_params', function () {
let serverResponse = {
body: [{
mediaType: 2,
vastXml: 'vastXml',
}]
};
let bids = spec.interpretResponse(serverResponse);
expect(bids).to.have.lengthOf(1);
let bid = bids[0];
expect(bid.mediaType).to.equal(2);
expect(bid.vastXml).to.equal('vastXml');
});

it('validate response params without currency', function () {
let serverResponse = {
body: [{
Expand Down

0 comments on commit f10beab

Please sign in to comment.