Skip to content

Commit

Permalink
Conversant Bid Adapter update for 3.0 (#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
pycnvr authored and sumit116 committed Oct 22, 2019
1 parent a65a11b commit b5f3c99
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
13 changes: 6 additions & 7 deletions modules/conversantBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {registerBidder} from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';

const BIDDER_CODE = 'conversant';
const URL = '//web.hb.ad.cpe.dotomi.com/s2s/header/24';
const URL = 'https://web.hb.ad.cpe.dotomi.com/s2s/header/24';

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -44,26 +44,24 @@ export const spec = {
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} validBidRequests - an array of bids
* @param bidderRequest
* @return {ServerRequest} Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
const loc = utils.getTopWindowLocation();
const page = loc.href;
const isPageSecure = (loc.protocol === 'https:') ? 1 : 0;
const page = (bidderRequest && bidderRequest.refererInfo) ? bidderRequest.refererInfo.referer : '';
let siteId = '';
let requestId = '';
let pubcid = null;

const conversantImps = validBidRequests.map(function(bid) {
const bidfloor = utils.getBidIdParameter('bidfloor', bid.params);
const secure = isPageSecure || (utils.getBidIdParameter('secure', bid.params) ? 1 : 0);

siteId = utils.getBidIdParameter('site_id', bid.params);
requestId = bid.auctionId;

const imp = {
id: bid.bidId,
secure: secure,
secure: 1,
bidfloor: bidfloor || 0,
displaymanager: 'Prebid.js',
displaymanagerver: '$prebid.version$'
Expand Down Expand Up @@ -154,6 +152,7 @@ export const spec = {
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @param bidRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
Expand Down Expand Up @@ -249,7 +248,7 @@ function getDevice() {
*
* [[300, 250], [300, 600]] => [{w: 300, h: 250}, {w: 300, h: 600}]
*
* @param {number[2][]|number[2]} bidSizes - arrays of widths and heights
* @param {Array.<Array.<number>>} bidSizes - arrays of widths and heights
* @returns {object[]} Array of objects with w and h
*/
function convertSizes(bidSizes) {
Expand Down
6 changes: 5 additions & 1 deletion modules/conversantBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ Module that connects to Conversant's demand sources. Supports banners and video
var adUnits = [
{
code: 'banner-test-div',
sizes: [[300, 250]],
mediaTypes: {
banner: {
sizes: [[300, 250],[300,600]]
}
},
bids: [{
bidder: "conversant",
params: {
Expand Down
40 changes: 20 additions & 20 deletions test/spec/modules/conversantBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {expect} from 'chai';
import {spec} from 'modules/conversantBidAdapter';
import * as utils from 'src/utils';

var Adapter = require('modules/conversantBidAdapter');

describe('Conversant adapter tests', function() {
const siteId = '108060';
const versionPattern = /^\d+\.\d+\.\d+(.)*$/;
Expand All @@ -16,7 +14,6 @@ describe('Conversant adapter tests', function() {
site_id: siteId,
position: 1,
tag_id: 'tagid-1',
secure: false,
bidfloor: 0.5
},
placementCode: 'pcode000',
Expand All @@ -30,8 +27,7 @@ describe('Conversant adapter tests', function() {
{
bidder: 'conversant',
params: {
site_id: siteId,
secure: false
site_id: siteId
},
mediaTypes: {
banner: {
Expand All @@ -50,8 +46,7 @@ describe('Conversant adapter tests', function() {
params: {
site_id: siteId,
position: 2,
tag_id: '',
secure: false
tag_id: ''
},
placementCode: 'pcode002',
transactionId: 'tx002',
Expand Down Expand Up @@ -198,9 +193,15 @@ describe('Conversant adapter tests', function() {
});

it('Verify buildRequest', function() {
const request = spec.buildRequests(bidRequests);
const page = 'http://test.com?a=b&c=123';
const bidderRequest = {
refererInfo: {
referer: page
}
};
const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.method).to.equal('POST');
expect(request.url).to.equal('//web.hb.ad.cpe.dotomi.com/s2s/header/24');
expect(request.url).to.equal('https://web.hb.ad.cpe.dotomi.com/s2s/header/24');
const payload = request.data;

expect(payload).to.have.property('id', 'req000');
Expand All @@ -209,7 +210,7 @@ describe('Conversant adapter tests', function() {
expect(payload.imp).to.be.an('array').with.lengthOf(6);

expect(payload.imp[0]).to.have.property('id', 'bid000');
expect(payload.imp[0]).to.have.property('secure', 0);
expect(payload.imp[0]).to.have.property('secure', 1);
expect(payload.imp[0]).to.have.property('bidfloor', 0.5);
expect(payload.imp[0]).to.have.property('displaymanager', 'Prebid.js');
expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(versionPattern);
Expand All @@ -221,7 +222,7 @@ describe('Conversant adapter tests', function() {
expect(payload.imp[0]).to.not.have.property('video');

expect(payload.imp[1]).to.have.property('id', 'bid001');
expect(payload.imp[1]).to.have.property('secure', 0);
expect(payload.imp[1]).to.have.property('secure', 1);
expect(payload.imp[1]).to.have.property('bidfloor', 0);
expect(payload.imp[1]).to.have.property('displaymanager', 'Prebid.js');
expect(payload.imp[1]).to.have.property('displaymanagerver').that.matches(versionPattern);
Expand All @@ -232,7 +233,7 @@ describe('Conversant adapter tests', function() {
expect(payload.imp[1].banner.format).to.deep.equal([{w: 728, h: 90}, {w: 468, h: 60}]);

expect(payload.imp[2]).to.have.property('id', 'bid002');
expect(payload.imp[2]).to.have.property('secure', 0);
expect(payload.imp[2]).to.have.property('secure', 1);
expect(payload.imp[2]).to.have.property('bidfloor', 0);
expect(payload.imp[2]).to.have.property('displaymanager', 'Prebid.js');
expect(payload.imp[2]).to.have.property('displaymanagerver').that.matches(versionPattern);
Expand All @@ -242,7 +243,7 @@ describe('Conversant adapter tests', function() {
expect(payload.imp[2].banner.format).to.deep.equal([{w: 300, h: 600}, {w: 160, h: 600}]);

expect(payload.imp[3]).to.have.property('id', 'bid003');
expect(payload.imp[3]).to.have.property('secure', 0);
expect(payload.imp[3]).to.have.property('secure', 1);
expect(payload.imp[3]).to.have.property('bidfloor', 0);
expect(payload.imp[3]).to.have.property('displaymanager', 'Prebid.js');
expect(payload.imp[3]).to.have.property('displaymanagerver').that.matches(versionPattern);
Expand All @@ -261,7 +262,7 @@ describe('Conversant adapter tests', function() {
expect(payload.imp[3]).to.not.have.property('banner');

expect(payload.imp[4]).to.have.property('id', 'bid004');
expect(payload.imp[4]).to.have.property('secure', 0);
expect(payload.imp[4]).to.have.property('secure', 1);
expect(payload.imp[4]).to.have.property('bidfloor', 0);
expect(payload.imp[4]).to.have.property('displaymanager', 'Prebid.js');
expect(payload.imp[4]).to.have.property('displaymanagerver').that.matches(versionPattern);
Expand All @@ -280,7 +281,7 @@ describe('Conversant adapter tests', function() {
expect(payload.imp[4]).to.not.have.property('banner');

expect(payload.imp[5]).to.have.property('id', 'bid005');
expect(payload.imp[5]).to.have.property('secure', 0);
expect(payload.imp[5]).to.have.property('secure', 1);
expect(payload.imp[5]).to.have.property('bidfloor', 0);
expect(payload.imp[5]).to.have.property('displaymanager', 'Prebid.js');
expect(payload.imp[5]).to.have.property('displaymanagerver').that.matches(versionPattern);
Expand All @@ -299,8 +300,7 @@ describe('Conversant adapter tests', function() {
expect(payload).to.have.property('site');
expect(payload.site).to.have.property('id', siteId);
expect(payload.site).to.have.property('mobile').that.is.oneOf([0, 1]);
const loc = utils.getTopWindowLocation();
const page = loc.href;

expect(payload.site).to.have.property('page', page);

expect(payload).to.have.property('device');
Expand Down Expand Up @@ -365,7 +365,7 @@ describe('Conversant adapter tests', function() {

it('Verify publisher commond id support', function() {
// clone bidRequests
let requests = utils.deepClone(bidRequests)
let requests = utils.deepClone(bidRequests);

// add pubcid to every entry
requests.forEach((unit) => {
Expand All @@ -378,7 +378,7 @@ describe('Conversant adapter tests', function() {

it('Verify User ID publisher commond id support', function() {
// clone bidRequests
let requests = utils.deepClone(bidRequests)
let requests = utils.deepClone(bidRequests);

// add pubcid to every entry
requests.forEach((unit) => {
Expand Down Expand Up @@ -415,4 +415,4 @@ describe('Conversant adapter tests', function() {
expect(payload).to.have.deep.nested.property('user.ext.consent', '');
expect(payload).to.not.have.deep.nested.property('regs.ext.gdpr');
});
})
});

0 comments on commit b5f3c99

Please sign in to comment.