Skip to content

Commit

Permalink
vidazooBidAdapter: feature/multi size request (prebid#5007)
Browse files Browse the repository at this point in the history
* feat(module): multi size request

* fix getUserSyncs
added tests

* update(module): package-lock.json from master

Co-authored-by: roman <shmoop207@gmail.com>
  • Loading branch information
2 people authored and rjvelicaria committed Apr 9, 2020
1 parent 61695b2 commit c207925
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 78 deletions.
96 changes: 52 additions & 44 deletions modules/vidazooBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER} from '../src/mediaTypes.js';

export const URL = 'https://prebid.cootlogix.com';
const BIDDER_CODE = 'vidazoo';
const CURRENCY = 'USD';
Expand All @@ -19,25 +20,29 @@ function isBidRequestValid(bid) {
return !!(params.cId && params.pId);
}

function buildRequest(bid, topWindowUrl, size, bidderRequest) {
function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
const {params, bidId} = bid;
const {bidFloor, cId, pId, ext} = params;
// Prebid's util function returns AppNexus style sizes (i.e. 300x250)
const [width, height] = size.split('x');

const dto = {
method: 'GET',
url: `${URL}/prebid/${cId}`,
data: {
url: encodeURIComponent(topWindowUrl),
cb: Date.now(),
bidFloor: bidFloor,
bidId: bidId,
publisherId: pId,
consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString,
width,
height
let data = {
url: encodeURIComponent(topWindowUrl),
cb: Date.now(),
bidFloor: bidFloor,
bidId: bidId,
publisherId: pId,
sizes: sizes,
};
if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString) {
data.gdprConsent = bidderRequest.gdprConsent.consentString;
}
if (bidderRequest.gdprConsent.gdprApplies !== undefined) {
data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
}
}
const dto = {
method: 'POST',
url: `${URL}/prebid/multi/${cId}`,
data: data
};

utils._each(ext, (value, key) => {
Expand All @@ -52,10 +57,8 @@ function buildRequests(validBidRequests, bidderRequest) {
const requests = [];
validBidRequests.forEach(validBidRequest => {
const sizes = utils.parseSizesInput(validBidRequest.sizes);
sizes.forEach(size => {
const request = buildRequest(validBidRequest, topWindowUrl, size, bidderRequest);
requests.push(request);
});
const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest);
requests.push(request);
});
return requests;
}
Expand All @@ -64,23 +67,30 @@ function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body) {
return [];
}
const {creativeId, ad, price, exp} = serverResponse.body;
if (!ad || !price) {
return [];
}
const {bidId, width, height} = request.data;
const {bidId} = request.data;
const {results} = serverResponse.body;

let output = [];

try {
return [{
requestId: bidId,
cpm: price,
width: width,
height: height,
creativeId: creativeId,
currency: CURRENCY,
netRevenue: true,
ttl: exp || TTL_SECONDS,
ad: ad
}];
results.forEach(result => {
const {creativeId, ad, price, exp, width, height, currency} = result;
if (!ad || !price) {
return;
}
output.push({
requestId: bidId,
cpm: price,
width: width,
height: height,
creativeId: creativeId,
currency: currency || CURRENCY,
netRevenue: true,
ttl: exp || TTL_SECONDS,
ad: ad
})
});
return output;
} catch (e) {
return [];
}
Expand All @@ -101,20 +111,18 @@ function getUserSyncs(syncOptions, responses) {
const syncs = [];
responses.forEach(response => {
const {body} = response;
const cookies = body ? body.cookies || [] : [];
cookies.forEach(cookie => {
switch (cookie.type) {
case INTERNAL_SYNC_TYPE.IFRAME:
break;
case INTERNAL_SYNC_TYPE.IMAGE:
const results = body ? body.results || [] : [];
results.forEach(result => {
(result.cookies || []).forEach(cookie => {
if (cookie.type === INTERNAL_SYNC_TYPE.IMAGE) {
if (pixelEnabled && !lookup[cookie.src]) {
syncs.push({
type: EXTERNAL_SYNC_TYPE.IMAGE,
url: cookie.src
});
}
break;
}
}
});
});
});
return syncs;
Expand Down
76 changes: 42 additions & 34 deletions test/spec/modules/vidazooBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const BID = {

const BIDDER_REQUEST = {
'gdprConsent': {
'consentString': 'consent_string'
'consentString': 'consent_string',
'gdprApplies': true
},
'refererInfo': {
'referer': 'https://www.greatsite.com'
Expand All @@ -31,16 +32,20 @@ const BIDDER_REQUEST = {

const SERVER_RESPONSE = {
body: {
'ad': '<iframe>console.log("hello world")</iframe>',
'price': 0.8,
'creativeId': '12610997325162499419',
'exp': 30,
'cookies': [{
'src': 'https://sync.com',
'type': 'iframe'
}, {
'src': 'https://sync.com',
'type': 'img'
results: [{
'ad': '<iframe>console.log("hello world")</iframe>',
'price': 0.8,
'creativeId': '12610997325162499419',
'exp': 30,
'width': 300,
'height': 250,
'cookies': [{
'src': 'https://sync.com',
'type': 'iframe'
}, {
'src': 'https://sync.com',
'type': 'img'
}]
}]
}
};
Expand Down Expand Up @@ -119,30 +124,14 @@ describe('VidazooBidAdapter', function () {

it('should build request for each size', function () {
const requests = adapter.buildRequests([BID], BIDDER_REQUEST);
expect(requests).to.have.length(2);
expect(requests).to.have.length(1);
expect(requests[0]).to.deep.equal({
method: 'GET',
url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`,
method: 'POST',
url: `${URL}/prebid/multi/59db6b3b4ffaa70004f45cdc`,
data: {
consent: 'consent_string',
width: '300',
height: '250',
url: 'https%3A%2F%2Fwww.greatsite.com',
cb: 1000,
bidFloor: 0.1,
bidId: '2d52001cabd527',
publisherId: '59ac17c192832d0011283fe3',
'ext.param1': 'loremipsum',
'ext.param2': 'dolorsitamet',
}
});
expect(requests[1]).to.deep.equal({
method: 'GET',
url: `${URL}/prebid/59db6b3b4ffaa70004f45cdc`,
data: {
consent: 'consent_string',
width: '300',
height: '600',
gdprConsent: 'consent_string',
gdpr: 1,
sizes: ['300x250', '300x600'],
url: 'https%3A%2F%2Fwww.greatsite.com',
cb: 1000,
bidFloor: 0.1,
Expand All @@ -158,6 +147,25 @@ describe('VidazooBidAdapter', function () {
sandbox.restore();
});
});
describe('getUserSyncs', function () {
it('should have valid user sync with iframeEnabled', function () {
const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]);

expect(result).to.deep.equal([{
type: 'iframe',
url: 'https://static.cootlogix.com/basev/sync/user_sync.html'
}]);
});

it('should have valid user sync with pixelEnabled', function () {
const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]);

expect(result).to.deep.equal([{
'url': 'https://sync.com',
'type': 'image'
}]);
})
});

describe('interpret response', function () {
it('should return empty array when there is no response', function () {
Expand Down Expand Up @@ -193,7 +201,7 @@ describe('VidazooBidAdapter', function () {

it('should take default TTL', function () {
const serverResponse = utils.deepClone(SERVER_RESPONSE);
delete serverResponse.body.exp;
delete serverResponse.body.results[0].exp;
const responses = adapter.interpretResponse(serverResponse, REQUEST);
expect(responses).to.have.length(1);
expect(responses[0].ttl).to.equal(300);
Expand Down

0 comments on commit c207925

Please sign in to comment.