diff --git a/modules/docereeBidAdapter.js b/modules/docereeBidAdapter.js new file mode 100644 index 00000000000..f9f3e1bcc70 --- /dev/null +++ b/modules/docereeBidAdapter.js @@ -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); diff --git a/modules/docereeBidAdapter.md b/modules/docereeBidAdapter.md index 9e3d4bbe1b8..d977e11f40a 100644 --- a/modules/docereeBidAdapter.md +++ b/modules/docereeBidAdapter.md @@ -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 +``` + 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 + } + } + ] + } +]; ``` diff --git a/test/spec/modules/docereeBidAdapter_spec.js b/test/spec/modules/docereeBidAdapter_spec.js new file mode 100644 index 00000000000..efff2efa319 --- /dev/null +++ b/test/spec/modules/docereeBidAdapter_spec.js @@ -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: '