Skip to content

Commit

Permalink
Vrtcal Markets Inc. Bid Adapter Addition (prebid#4259)
Browse files Browse the repository at this point in the history
* Added 3 key Vrtcal Adapter files: adapter,markdown,unit tests

* Removed unused getUserSyncs;Added mediaTypes.banner.sizes support;Raised test coverage to 85%

* lint formatting errors corrected
  • Loading branch information
vrtcal-dev authored and sa1omon committed Nov 28, 2019
1 parent d3acc44 commit 2bcde2b
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 0 deletions.
88 changes: 88 additions & 0 deletions modules/vrtcalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {registerBidder} from '../src/adapters/bidderFactory';
import { BANNER } from '../src/mediaTypes';
import {ajax} from '../src/ajax';

export const spec = {
code: 'vrtcal',
supportedMediaTypes: [BANNER],
isBidRequestValid: function (bid) {
if (bid.bidId == '' || bid.auctionId == '') { return false; } else { return true; }// No extras params required
},
buildRequests: function (bidRequests) {
const requests = bidRequests.map(function (bid) {
const params = {

prebidJS: 1,
prebidAdUnitCode: bid.adUnitCode,
id: bid.bidId,
imp: [{
id: '1',
banner: {
},
bidfloor: 0.75
}],
site: {
id: 'VRTCAL_FILLED',
name: 'VRTCAL_FILLED',
cat: ['VRTCAL_FILLED'],
domain: decodeURIComponent(window.location.href).replace('https://', '').replace('http://', '').split('/')[0]

},
device: {
ua: 'VRTCAL_FILLED',
ip: 'VRTCAL_FILLED'
}
};

if (typeof (bid.mediaTypes) !== 'undefined' && typeof (bid.mediaTypes.banner) !== 'undefined' && typeof (bid.mediaTypes.banner.sizes) !== 'undefined') {
params.imp[0].banner.w = bid.mediaTypes.banner.sizes[0][0];
params.imp[0].banner.h = bid.mediaTypes.banner.sizes[0][1];
} else {
params.imp[0].banner.w = bid.sizes[0][0];
params.imp[0].banner.h = bid.sizes[0][1];
}

return {method: 'POST', url: 'https://rtb.vrtcal.com/bidder_prebid.vap?ssp=1804', data: JSON.stringify(params), options: {withCredentials: false, crossOrigin: true}}
});

return requests;
},
interpretResponse: function (serverResponse, bidRequest) {
if (!serverResponse || !serverResponse.body) {
return [];
}

const bidResponses = [];

var response = serverResponse.body;

if (response) {
const bidResponse = {
requestId: response.id,
cpm: response.seatbid[0].bid[0].price,
width: response.seatbid[0].bid[0].w,
height: response.seatbid[0].bid[0].h,
creativeId: response.seatbid[0].bid[0].crid,
currency: 'USD',
netRevenue: true,
ttl: 900,
ad: response.seatbid[0].bid[0].adm,
nurl: response.seatbid[0].bid[0].nurl
};

bidResponses.push(bidResponse);
}
return bidResponses;
},
onBidWon: function(bid) {
if (!bid.nurl) { return false; }
const winUrl = bid.nurl.replace(
/\$\{AUCTION_PRICE\}/,
bid.cpm
);
ajax(winUrl, null);
return true;
}
};

registerBidder(spec);
30 changes: 30 additions & 0 deletions modules/vrtcalBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Overview

Module Name: Vrtcal Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]

# Description

You can use this adapter to get a bid from vrtcal.com.


# Test Parameters
```
var adUnits = [
{
code: "vrtcal-test-adunit",
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: "vrtcal"
}
]
}
];
```
#Vrtcal requires no extra params passed, thus no params struct included
135 changes: 135 additions & 0 deletions test/spec/modules/vrtcalBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import {expect} from 'chai';
import {spec} from '../../../modules/vrtcalBidAdapter';

describe('Vrtcal Adapter', function () {
let bid = {
bidId: 'bidID0001',
bidder: 'vrtcal',
bidderRequestId: 'brID0001',
auctionId: 'auID0001',
sizes: [[300, 250]],
transactionId: 'tid0001',
adUnitCode: 'vrtcal-test-adunit'
};

describe('isBidRequestValid', function () {
it('Should return true when base params as set', function () {
expect(spec.isBidRequestValid(bid)).to.be.true;
});
it('Should return false when bid.bidId is blank', function () {
bid.bidId = '';
expect(spec.isBidRequestValid(bid)).to.be.false;
});
it('Should return false when bid.auctionId is blank', function () {
bid.auctionId = '';
expect(spec.isBidRequestValid(bid)).to.be.false;
});
});

describe('buildRequests', function () {
let serverRequests = spec.buildRequests([bid]);

let serverRequest = serverRequests[0];

it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequest).to.exist;
expect(serverRequest.method).to.exist;
expect(serverRequest.url).to.exist;
expect(serverRequest.data).to.exist;
});
it('Returns POST method', function () {
expect(serverRequest.method).to.equal('POST');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://rtb.vrtcal.com/bidder_prebid.vap?ssp=1804');
});

it('Returns valid data if array of bids is valid', function () {
let data = JSON.parse(serverRequest.data);
expect(data).to.be.an('object');
expect(data).to.have.all.keys('prebidJS', 'prebidAdUnitCode', 'id', 'imp', 'site', 'device');
expect(data.prebidJS).to.not.equal('');
expect(data.prebidAdUnitCode).to.not.equal('');
});

it('Sets width and height based on existence of bid.mediaTypes.banner', function () {
let data = JSON.parse(serverRequest.data);
if (typeof (bid.mediaTypes) !== 'undefined' && typeof (bid.mediaTypes.banner) !== 'undefined' && typeof (bid.mediaTypes.banner.sizes) !== 'undefined') {
expect(data.imp[0].banner.w).to.equal(bid.mediaTypes.banner.sizes[0][0]);
expect(data.imp[0].banner.h).to.equal(bid.mediaTypes.banner.sizes[0][1]);
} else {
expect(data.imp[0].banner.w).to.equal(bid.sizes[0][0]);
expect(data.imp[0].banner.h).to.equal(bid.sizes[0][1]);
}
});

it('Returns empty data if no valid requests are passed', function () {
serverRequests = spec.buildRequests([]);
expect(serverRequests).to.be.an('array').that.is.empty;
});
});

describe('interpretResponse', function () {
let bid = {
bidId: 'bidID0001',
bidder: 'vrtcal',
bidderRequestId: 'brID0001',
auctionId: 'auID0001',
sizes: [[300, 250]],
transactionId: 'tid0001',
adUnitCode: 'vrtcal-test-adunit'
};

let serverRequests = spec.buildRequests([bid]);

let resObject = {body: {id: 'vrtcal-test-id', width: 300, height: 250, seatbid: [{bid: [{price: 3.0, w: 300, h: 250, crid: 'testcrid', adm: 'testad', nurl: 'https://vrtcal.com/faketracker'}]}], currency: 'USD', netRevenue: true, ttl: 900}};

let serverResponses = spec.interpretResponse(resObject, serverRequests);

it('Returns an array of valid server responses if response object is valid', function () {
expect(serverResponses).to.be.an('array').that.is.not.empty;
for (let i = 0; i < serverResponses.length; i++) {
let dataItem = serverResponses[i];
expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId',
'netRevenue', 'currency', 'nurl');
expect(dataItem.requestId).to.be.a('string');
expect(dataItem.cpm).to.be.a('number');
expect(dataItem.width).to.be.a('number');
expect(dataItem.height).to.be.a('number');
expect(dataItem.ad).to.be.a('string');
expect(dataItem.ttl).to.be.a('number');
expect(dataItem.creativeId).to.be.a('string');
expect(dataItem.netRevenue).to.be.a('boolean');
expect(dataItem.currency).to.be.a('string');
expect(dataItem.nurl).to.be.a('string');
}

it('Returns an empty array if invalid response is passed', function () {
serverResponses = spec.interpretResponse('invalid_response');
expect(serverResponses).to.be.an('array').that.is.empty;
});
});
});

describe('onBidWon', function () {
let bid = {
bidId: '2dd581a2b6281d',
bidder: 'vrtcal',
bidderRequestId: '145e1d6a7837c9',
auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2',
sizes: [[300, 250]],
transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62',
adUnitCode: 'vrtcal-test-adunit'
};

let serverRequests = spec.buildRequests([bid]);
let resObject = {body: {id: 'vrtcal-test-id', width: 300, height: 250, seatbid: [{bid: [{price: 3.0, w: 300, h: 250, crid: 'testcrid', adm: 'testad', nurl: 'https://vrtcal.com/faketracker'}]}], currency: 'USD', netRevenue: true, ttl: 900}};
let serverResponses = spec.interpretResponse(resObject, serverRequests);
let wonbid = serverResponses[0];

it('Returns true is nurl is good/not blank', function () {
expect(wonbid.nurl).to.not.equal('');
expect(spec.onBidWon(wonbid)).to.be.true;
});
});
});

0 comments on commit 2bcde2b

Please sign in to comment.