Skip to content

Commit

Permalink
Doceree Bid Adapter: new bid adapter (prebid#6437)
Browse files Browse the repository at this point in the history
* doceree adapter

* add fix for impression register

* fix linting issues

* fix build issue

* remove extra spaces

* fixing - Implicit operand conversion

* fixed ci/cd lint issue

* update test case

* support for advertiserdomains and updated test case

* remove space to rerun test cases

* remove the client side creative creation
  • Loading branch information
sourbh-doceree authored and stsepelin committed May 28, 2021
1 parent b3150ad commit ecfd1eb
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 23 deletions.
65 changes: 65 additions & 0 deletions modules/docereeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
const BIDDER_CODE = 'doceree';
const END_POINT = 'https://bidder.doceree.com'

export const spec = {
code: BIDDER_CODE,
url: '',
supportedMediaTypes: [ BANNER ],

isBidRequestValid: (bid) => {
const { placementId } = bid.params;
return !!placementId
},
buildRequests: (validBidRequests) => {
const serverRequests = [];
const { data } = config.getConfig('doceree.user')
const { page, domain, token } = config.getConfig('doceree.context')
const encodedUserInfo = window.btoa(encodeURIComponent(JSON.stringify(data)))

validBidRequests.forEach(function(validBidRequest) {
const { publisherUrl, placementId } = validBidRequest.params;
const url = publisherUrl || page
let queryString = '';
queryString = utils.tryAppendQueryString(queryString, 'id', placementId);
queryString = utils.tryAppendQueryString(queryString, 'publisherDomain', domain);
queryString = utils.tryAppendQueryString(queryString, 'pubRequestedURL', encodeURIComponent(url));
queryString = utils.tryAppendQueryString(queryString, 'loggedInUser', encodedUserInfo);
queryString = utils.tryAppendQueryString(queryString, 'currentUrl', url);
queryString = utils.tryAppendQueryString(queryString, 'prebidjs', true);
queryString = utils.tryAppendQueryString(queryString, 'token', token);
queryString = utils.tryAppendQueryString(queryString, 'requestId', validBidRequest.bidId);

serverRequests.push({
method: 'GET',
url: END_POINT + '/v1/adrequest?' + queryString
})
})
return serverRequests;
},
interpretResponse: (serverResponse, request) => {
const responseJson = serverResponse ? serverResponse.body : {};
const placementId = responseJson.DIVID;
const bidResponse = {
ad: responseJson.sourceHTML,
width: Number(responseJson.width),
height: Number(responseJson.height),
requestId: responseJson.guid,
netRevenue: true,
ttl: 30,
cpm: responseJson.cpmBid,
currency: responseJson.currency,
mediaType: 'banner',
creativeId: placementId,
meta: {
advertiserDomains: [responseJson.advertiserDomain]
}
};
return [bidResponse];
}
};

registerBidder(spec);
47 changes: 24 additions & 23 deletions modules/docereeBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
# Overview

Module Name: Doceree Bidder Adapter
Module Type: Bidder Adapter

# Description
```
Module Name: Doceree Bidder Adapter
Module Type: Bidder Adapter
Maintainer: sourbh.gupta@doceree.com
```

<!-- # Description -->
Connects to Doceree demand source to fetch bids.
Please use ```doceree``` as the bidder code.
Please use ```doceree``` as the bidder code.


# Test Parameters
```
var adUnits = [
var adUnits = [
{
code: 'doceree',
sizes: [
[300, 250]
],
bids: [
{
code: 'desktop-banner-ad-div',
sizes: [[300, 250]],
bids: [
{
bidder: "doceree",
params: {
accountID: '167283',
zoneID: '445501',
domain: 'adbserver.doceree.com',
extra: {
tuid: '1234-abcd'
}
}
}
]
},
];
bidder: "doceree",
params: {
placementId: 'DOC_7jm9j5eqkl0xvc5w', //required
publisherUrl: document.URL || window.location.href, //optional
}
}
]
}
];
```
97 changes: 97 additions & 0 deletions test/spec/modules/docereeBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {expect} from 'chai';
import {spec} from '../../../modules/docereeBidAdapter.js';
import { config } from '../../../src/config.js';

describe('BidlabBidAdapter', function () {
config.setConfig({
doceree: {
context: {
data: {
token: 'testing-token', // required
}
},
user: {
data: {
gender: '',
email: '',
hashedEmail: '',
firstName: '',
lastName: '',
npi: '',
hashedNPI: '',
city: '',
zipCode: '',
specialization: '',
}
}
}
});
let bid = {
bidId: 'testing',
bidder: 'doceree',
params: {
placementId: 'DOC_7jm9j5eqkl0xvc5w',
}
};

describe('isBidRequestValid', function () {
it('Should return true if placementId is present', function () {
expect(spec.isBidRequestValid(bid)).to.be.true;
});
it('Should return false if placementId is not present', function () {
delete bid.params.placementId;
expect(spec.isBidRequestValid(bid)).to.be.false;
});
});

describe('buildRequests', function () {
let serverRequest = spec.buildRequests([bid]);
serverRequest = serverRequest[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;
});
it('Returns GET method', function () {
expect(serverRequest.method).to.equal('GET');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://bidder.doceree.com/v1/adrequest?id=DOC_7jm9j5eqkl0xvc5w&pubRequestedURL=undefined&loggedInUser=JTdCJTIyZ2VuZGVyJTIyJTNBJTIyJTIyJTJDJTIyZW1haWwlMjIlM0ElMjIlMjIlMkMlMjJoYXNoZWRFbWFpbCUyMiUzQSUyMiUyMiUyQyUyMmZpcnN0TmFtZSUyMiUzQSUyMiUyMiUyQyUyMmxhc3ROYW1lJTIyJTNBJTIyJTIyJTJDJTIybnBpJTIyJTNBJTIyJTIyJTJDJTIyaGFzaGVkTlBJJTIyJTNBJTIyJTIyJTJDJTIyY2l0eSUyMiUzQSUyMiUyMiUyQyUyMnppcENvZGUlMjIlM0ElMjIlMjIlMkMlMjJzcGVjaWFsaXphdGlvbiUyMiUzQSUyMiUyMiU3RA%3D%3D&prebidjs=true&requestId=testing&');
});
});
describe('interpretResponse', function () {
it('Should interpret banner response', function () {
const banner = {
body: {
DIVID: 'DOC_7jm9j5eqkl0xvc5w',
creativeType: 'banner',
guid: 'G125fzC5NKl3FHeOT8yvL98ILfQS9TVUgk6Q',
currency: 'USD',
cpmBid: 2,
height: '250',
width: '300',
ctaLink: 'https://doceree.com/',
sourceURL: '',
sourceHTML: '<div>test</div>',
advertiserDomain: 'doceree.com',
}
};
let bannerResponses = spec.interpretResponse(banner);
expect(bannerResponses).to.be.an('array').that.is.not.empty;
let dataItem = bannerResponses[0];
expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl',
'netRevenue', 'currency', 'mediaType', 'creativeId', 'meta');
expect(dataItem.requestId).to.equal('G125fzC5NKl3FHeOT8yvL98ILfQS9TVUgk6Q');
expect(dataItem.cpm).to.equal(2);
expect(dataItem.width).to.equal(300);
expect(dataItem.height).to.equal(250);
expect(dataItem.ad).to.equal('<div>test</div>');
expect(dataItem.ttl).to.equal(30);
expect(dataItem.netRevenue).to.be.true;
expect(dataItem.currency).to.equal('USD');
expect(dataItem.creativeId).to.equal('DOC_7jm9j5eqkl0xvc5w');
expect(dataItem.meta.advertiserDomains).to.be.an('array').that.is.not.empty;
expect(dataItem.meta.advertiserDomains[0]).to.equal('doceree.com')
});
})
});

0 comments on commit ecfd1eb

Please sign in to comment.