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

Viously Bid Adapter : Handle banner requests #9513

Merged
merged 1 commit into from
Mar 2, 2023
Merged
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
75 changes: 53 additions & 22 deletions modules/viouslyBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepAccess, logError, parseUrl, parseSizesInput, triggerPixel } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { VIDEO } from '../src/mediaTypes.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import find from 'core-js-pure/features/array/find.js'; // eslint-disable-line prebid/validate-imports

const BIDDER_CODE = 'viously';
Expand All @@ -16,7 +16,7 @@ const REQUIRED_VIOUSLY_PARAMS = ['pid'];
export const spec = {
code: BIDDER_CODE,
// gvlid: GVLID,
supportedMediaTypes: [VIDEO],
supportedMediaTypes: [BANNER, VIDEO],

/**
* Determines whether or not the given bid request is valid.
Expand All @@ -26,33 +26,48 @@ export const spec = {
*/
isBidRequestValid: function(bid) {
let videoParams = deepAccess(bid, 'mediaTypes.video');
let bannerParams = deepAccess(bid, 'mediaTypes.banner');

if (!bid.params) {
logError('The bid params are missing');
return false;
}

if (!videoParams) {
logError('The placement must be of video type');
if (!bannerParams && !videoParams) {
logError('The placement must be of banner or video type');
return false;
}

/**
* VIDEO checks
* BANNER checks
*/

if (bannerParams) {
let sizes = bannerParams.sizes;

if (!sizes || parseSizesInput(sizes).length == 0) {
logError('mediaTypes.banner.sizes must be set for banner placement at the right format.');
return false;
}
}

/**
* VIDEO checks
*/
let areParamsValid = true;

REQUIRED_VIDEO_PARAMS.forEach(function(videoParam) {
if (typeof videoParams[videoParam] === 'undefined') {
logError('mediaTypes.video.' + videoParam + ' must be set for video placement.');
if (videoParams) {
REQUIRED_VIDEO_PARAMS.forEach(function(videoParam) {
if (typeof videoParams[videoParam] === 'undefined') {
logError('mediaTypes.video.' + videoParam + ' must be set for video placement.');
areParamsValid = false;
}
});

if (parseSizesInput(videoParams.playerSize).length === 0) {
logError('mediaTypes.video.playerSize must be set for video placement at the right format.');
areParamsValid = false;
}
});

if (parseSizesInput(videoParams.playerSize).length === 0) {
logError('mediaTypes.video.playerSize must be set for video placement at the right format.');
return false;
}

/**
Expand Down Expand Up @@ -132,11 +147,23 @@ export const spec = {
bid_id: bidRequest.bidId
};

request.video_params = {
context: deepAccess(bidRequest, 'mediaTypes.video.context'),
playbackmethod: deepAccess(bidRequest, 'mediaTypes.video.playbackmethod'),
size: parseSizesInput(deepAccess(bidRequest, 'mediaTypes.video.playerSize'))
};
if (deepAccess(bidRequest, 'mediaTypes.banner')) {
let position = deepAccess(bidRequest, 'mediaTypes.banner.pos');

request.type = BANNER;

request.sizes = parseSizesInput(deepAccess(bidRequest, 'mediaTypes.banner.sizes'));

request.position = position || 0;
} else {
request.type = VIDEO;

request.video_params = {
context: deepAccess(bidRequest, 'mediaTypes.video.context'),
playbackmethod: deepAccess(bidRequest, 'mediaTypes.video.playbackmethod'),
size: parseSizesInput(deepAccess(bidRequest, 'mediaTypes.video.playerSize'))
};
}

return request;
});
Expand Down Expand Up @@ -170,16 +197,20 @@ export const spec = {
currency: CURRENCY,
netRevenue: true,
ttl: TTL,
mediaType: 'video',
mediaType: bidResponse.type,
meta: {},
// Tracking data
nurl: bidResponse.nurl ? bidResponse.nurl : []
};

if (bidResponse.ad_url) {
bid.vastUrl = bidResponse.ad_url;
if (bidResponse.type == VIDEO) {
if (bidResponse.ad_url) {
bid.vastUrl = bidResponse.ad_url;
} else {
bid.vastXml = bidResponse.ad;
}
} else {
bid.vastXml = bidResponse.ad;
bid.ad = bidResponse.ad;
}

bidResponses.push(bid);
Expand Down
98 changes: 97 additions & 1 deletion test/spec/modules/ViouslyBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect} from 'chai';

import { deepClone, mergeDeep } from 'src/utils';
import { BANNER, VIDEO } from 'src/mediaTypes';
import { createEidsArray } from 'modules/userId/eids.js';

import {spec as adapter} from 'modules/viouslyBidAdapter';
Expand All @@ -13,6 +14,21 @@ const TTL = 60;
const HTTP_METHOD = 'POST';
const REQUEST_URL = 'https://bidder.viously.com/bid';

const VALID_BID_BANNER = {
bidder: 'viously',
bidId: '5e6f7g8h',
adUnitCode: 'id-5678',
params: {
pid: '123e4567-e89b-12d3-a456-426614174002'
},
mediaTypes: {
banner: {
sizes: [300, 50],
pos: 1
}
}
};

const VALID_BID_VIDEO = {
bidder: 'viously',
bidId: '5e6f7g8h',
Expand All @@ -29,6 +45,24 @@ const VALID_BID_VIDEO = {
}
};

const VALID_REQUEST_BANNER = {
method: HTTP_METHOD,
url: REQUEST_URL,
data: {
pid: '123e4567-e89b-12d3-a456-426614174002',
currency_code: CURRENCY,
placements: [
{
id: 'id-5678',
bid_id: '5e6f7g8h',
sizes: ['300x50'],
type: BANNER,
position: 1
}
]
}
};

const VALID_REQUEST_VIDEO = {
method: HTTP_METHOD,
url: REQUEST_URL,
Expand All @@ -39,6 +73,7 @@ const VALID_REQUEST_VIDEO = {
{
id: 'id-5678',
bid_id: '5e6f7g8h',
type: VIDEO,
video_params: {
context: 'instream',
playbackmethod: [1, 2, 3, 4],
Expand Down Expand Up @@ -68,9 +103,30 @@ describe('ViouslyAdapter', function () {
describe('isBidRequestValid', function () {
describe('Check method return', function () {
it('should return true', function () {
expect(adapter.isBidRequestValid(VALID_BID_BANNER)).to.equal(true);
expect(adapter.isBidRequestValid(VALID_BID_VIDEO)).to.equal(true);
});

it('should return true for banner with no pos', function () {
let newBid = deepClone(VALID_BID_BANNER);
let newRequest = deepClone(VALID_REQUEST_BANNER);

delete newBid.mediaTypes.banner.pos;
newRequest.data.placements[0].position = 0;

expect(adapter.buildRequests([newBid])).to.deep.equal(newRequest);
});

it('should return false because the banner size is missing', function () {
let wrongBid = deepClone(VALID_BID_BANNER);

wrongBid.mediaTypes.banner.sizes = '123456';
expect(adapter.isBidRequestValid(wrongBid)).to.equal(false);

delete wrongBid.mediaTypes.banner.sizes;
expect(adapter.isBidRequestValid(wrongBid)).to.equal(false);
});

it('should return false because the pid is missing', function () {
let wrongBid = deepClone(VALID_BID_VIDEO);
delete wrongBid.params.pid;
Expand All @@ -89,6 +145,10 @@ describe('ViouslyAdapter', function () {

describe('buildRequests', function () {
describe('Check method return', function () {
it('should return the right formatted banner requests', function() {
expect(adapter.buildRequests([VALID_BID_BANNER])).to.deep.equal(VALID_REQUEST_BANNER);
});

it('should return the right formatted video requests', function() {
expect(adapter.buildRequests([VALID_BID_VIDEO])).to.deep.equal(VALID_REQUEST_VIDEO);
});
Expand Down Expand Up @@ -214,7 +274,7 @@ describe('ViouslyAdapter', function () {
expect(adapter.buildRequests([bid])).to.deep.equal(requests);
});

it('should return the right formatted request with endpint test', function() {
it('should return the right formatted request with endpoint test', function() {
let endpoint = 'https://bid-test.viously.com/prebid';

let bid = mergeDeep(deepClone(VALID_BID_VIDEO), {
Expand Down Expand Up @@ -259,6 +319,20 @@ describe('ViouslyAdapter', function () {
'win.domain.com'
]
},
{
bid: true,
creative_id: '1357',
id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-2',
bid_id: '9101112',
cpm: 1.5,
ad: 'html content',
type: 'banner',
size: '300x50',
nurl: [
'win.domain2.com',
'win.domain3.com'
]
},
{
bid: true,
creative_id: '1469',
Expand All @@ -283,6 +357,10 @@ describe('ViouslyAdapter', function () {
id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-1',
bid_id: '5678'
},
{
id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-2',
bid_id: '9101112'
},
{
id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-3',
bid_id: '2570'
Expand All @@ -309,6 +387,24 @@ describe('ViouslyAdapter', function () {
'win.domain.com'
]
},
{
requestId: '9101112',
id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-2',
cpm: 1.5,
width: '300',
height: '50',
creativeId: '1357',
currency: CURRENCY,
netRevenue: true,
ttl: TTL,
mediaType: 'banner',
meta: {},
ad: 'html content',
nurl: [
'win.domain2.com',
'win.domain3.com'
]
},
{
requestId: '2570',
id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-3',
Expand Down