From a6762af00b45a100d399e2d7eafa4750fb664fc2 Mon Sep 17 00:00:00 2001 From: gcarnec Date: Fri, 1 Dec 2017 10:51:32 +0100 Subject: [PATCH 1/8] Update adapter to prebid v1.0 --- modules/smartadserverBidAdapter.js | 147 ++++++---- modules/smartadserverBidAdapter.md | 34 +++ .../modules/smartadserverBidAdapter_spec.js | 272 +++++++++--------- 3 files changed, 262 insertions(+), 191 deletions(-) create mode 100644 modules/smartadserverBidAdapter.md diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index d815f69c752..d39ff9198c8 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -1,60 +1,93 @@ -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader.js'); -var url = require('src/url.js'); -var adaptermanager = require('src/adaptermanager'); +import * as utils from 'src/utils'; +import { + config +} from 'src/config'; +import { + registerBidder +} from 'src/adapters/bidderFactory'; +const BIDDER_CODE = 'smartadserver'; +export const spec = { + code: BIDDER_CODE, + aliases: ['smart'], // short code + /** + * Determines whether or not the given bid request is valid. + * + * @param {BidRequest} bid The bid params to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function (bid) { + return !!(bid.params && bid.params.siteId && bid.params.pageId && bid.params.formatId && bid.params.domain); + }, + /** + * Make a server request from the list of BidRequests. + * + * @param {validBidRequests[]} - an array of bids + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function (validBidRequests) { + // use bidderRequest.bids[] to get bidder-dependent request info -var SmartAdServer = function SmartAdServer() { - var generateCallback = function(bid) { - var callbackId = 'sas_' + utils.getUniqueIdentifierStr(); - $$PREBID_GLOBAL$$[callbackId] = function(adUnit) { - var bidObject; - if (adUnit) { - utils.logMessage(`[SmartAdServer] bid response for placementCode ${bid.placementCode}`); - bidObject = bidfactory.createBid(1); - bidObject.bidderCode = 'smartadserver'; - bidObject.cpm = adUnit.cpm; - bidObject.currency = adUnit.currency; - bidObject.ad = adUnit.ad; - bidObject.width = adUnit.width; - bidObject.height = adUnit.height; - bidObject.dealId = adUnit.dealId; - bidmanager.addBidResponse(bid.placementCode, bidObject); - } else { - utils.logMessage(`[SmartAdServer] no bid response for placementCode ${bid.placementCode}`); - bidObject = bidfactory.createBid(2); - bidObject.bidderCode = 'smartadserver'; - bidmanager.addBidResponse(bid.placementCode, bidObject); - } - }; - return callbackId; - }; + // if your bidder supports multiple currencies, use config.getConfig(currency) + // to find which one the ad server needs - return { - callBids: function(params) { - for (var i = 0; i < params.bids.length; i++) { - var bid = params.bids[i]; - var adCall = url.parse(bid.params.domain); - adCall.pathname = '/prebid'; - adCall.search = { - 'pbjscbk': '$$PREBID_GLOBAL$$.' + generateCallback(bid), - 'siteid': bid.params.siteId, - 'pgid': bid.params.pageId, - 'fmtid': bid.params.formatId, - 'ccy': bid.params.currency || 'USD', - 'bidfloor': bid.params.bidfloor || 0.0, - 'tgt': encodeURIComponent(bid.params.target || ''), - 'tag': bid.placementCode, - 'sizes': bid.sizes.map(size => size[0] + 'x' + size[1]).join(','), - 'async': 1 - }; - adloader.loadScript(url.format(adCall)); - } + // pull requested transaction ID from bidderRequest.bids[].transactionId + if (!Array.isArray(validBidRequests)) { + validBidRequests = [validBidRequests]; } - }; -}; - -adaptermanager.registerBidAdapter(new SmartAdServer(), 'smartadserver'); - -module.exports = SmartAdServer; + var bid = validBidRequests[0]; + const payload = { + siteid: bid.params.siteId, + pageid: bid.params.pageId, + formatid: bid.params.formatId, + currencyCode: config.getConfig('currency'), + bidfloor: bid.params.bidfloor || 0.0, + targeting: bid.params.target && bid.params.target != '' ? bid.params.target : undefined, + tagId: bid.adUnitCode, + sizes: bid.sizes.map(size => ({ + w: size[0], + h: size[1] + })), + pageDomain: utils.getTopWindowUrl(), + transactionId: bid.transactionId, + timeout: config.getConfig('bidderTimeout') + }; + const payloadString = JSON.stringify(payload); + return { + method: 'POST', + url: bid.params.domain + '/prebid/v1', + data: payloadString, + }; + }, + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function (serverResponse, bidRequest) { + const bidResponses = []; + if (serverResponse) { + const bidResponse = { + requestId: bidRequest.bidId, + bidderCode: spec.code, + cpm: serverResponse.cpm, + width: serverResponse.width, + height: serverResponse.height, + creativeId: serverResponse.creativeId, + dealId: serverResponse.dealId, + currency: serverResponse.currency, + netRevenue: serverResponse.isNetCpm, + ttl: serverResponse.ttl, + referrer: utils.getTopWindowUrl(), + ad: serverResponse.ad + }; + bidResponses.push(bidResponse); + } + return bidResponses; + }, + getUserSyncs: function (syncOptions) { + // iframe || image + return undefined; + } +} +registerBidder(spec); diff --git a/modules/smartadserverBidAdapter.md b/modules/smartadserverBidAdapter.md new file mode 100644 index 00000000000..6fe79527c3d --- /dev/null +++ b/modules/smartadserverBidAdapter.md @@ -0,0 +1,34 @@ +# Overview + +``` +Module Name: Smart Ad Server Bidder Adapter +Module Type: Bidder Adapter +``` + +# Description + +Connect to Smart for bids. + +The Smart adapter requires setup and approval from the Smart team. +Please reach out to your Technical account manager for more information. + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div', + sizes: [[300, 250]], // a display size + bids: [ + { + bidder: "smart", + params: { + domain: 'http://prg.smartadserver.com', + siteId: 32216, + pageId: 881291, + formatId: 13695, + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index bfb89cf4ead..a7e29186893 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -1,154 +1,158 @@ -describe('smartadserver adapter tests', function () { - var urlParse = require('url-parse'); - var querystringify = require('querystringify'); - var adapter = require('modules/smartadserverBidAdapter'); - var adLoader = require('src/adloader'); - var expect = require('chai').expect; - var bidmanager = require('src/bidmanager'); - var CONSTANTS = require('src/constants.json'); - +import { + expect +} from 'chai'; +import { + spec +} from 'modules/smartadserverBidAdapter'; +import { + getTopWindowLocation +} from 'src/utils'; +import { + newBidder +} from 'src/adapters/bidderFactory'; +import { + config +} from 'src/config'; +import * as utils from 'src/utils'; + +describe('Smart ad server bid adapter tests', () => { var DEFAULT_PARAMS = { - bidderCode: 'smartadserver', - bids: [{ - bidId: 'abcd1234', - sizes: [[300, 250], [300, 200]], - bidder: 'smartadserver', - params: { - domain: 'http://www.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - currency: 'EUR', - bidfloor: 0.420 - }, - requestId: 'efgh5678', - placementCode: 'sas_42' - } - ] + adUnitCode: 'sas_42', + bidId: 'abcd1234', + sizes: [ + [300, 250], + [300, 200] + ], + bidder: 'smartadserver', + params: { + domain: 'http://prg.smartadserver.com', + siteId: '1234', + pageId: '5678', + formatId: '90', + target: 'test=prebid', + bidfloor: 0.420 + }, + requestId: 'efgh5678', + transactionId: 'zsfgzzg' }; var DEFAULT_PARAMS_WO_OPTIONAL = { - bidderCode: 'smartadserver', - bids: [{ - bidId: 'abcd1234', - sizes: [[300, 250], [300, 200]], - bidder: 'smartadserver', - params: { - domain: 'http://www.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90' - }, - requestId: 'efgh5678', - placementCode: 'sas_42' - } - ] + adUnitCode: 'sas_42', + bidId: 'abcd1234', + sizes: [ + [300, 250], + [300, 200] + ], + bidder: 'smartadserver', + params: { + domain: 'http://prg.smartadserver.com', + siteId: '1234', + pageId: '5678', + formatId: '90' + }, + requestId: 'efgh5678' }; var BID_RESPONSE = { - cpm: 0.42, - ad: 'fake ad content', + cpm: 12, width: 300, - height: 250 + height: 250, + creativeId: 'zioeufg', + currency: 'GBP', + isNetCpm: true, + ttl: 300, + ad: '< --- awesome script --- >' }; - it('set url parameters', function () { - var stubLoadScript = sinon.stub(adLoader, 'loadScript'); - - adapter().callBids(DEFAULT_PARAMS); - - var smartCallback; - for (var k in $$PREBID_GLOBAL$$) { - if (k.lastIndexOf('sas_', 0) === 0) { - smartCallback = k; - break; - } - } - - var bidUrl = stubLoadScript.getCall(0).args[0]; - var parsedBidUrl = urlParse(bidUrl); - var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - - expect(parsedBidUrl.hostname).to.equal('www.smartadserver.com'); - expect(parsedBidUrl.pathname).to.equal('/prebid'); - - expect(parsedBidUrlQueryString).to.have.property('pbjscbk').and.to.equal('$$PREBID_GLOBAL$$.' + smartCallback); - expect(parsedBidUrlQueryString).to.have.property('siteid').and.to.equal('1234'); - expect(parsedBidUrlQueryString).to.have.property('pgid').and.to.equal('5678'); - expect(parsedBidUrlQueryString).to.have.property('fmtid').and.to.equal('90'); - expect(parsedBidUrlQueryString).to.have.property('tgt').and.to.equal('test=prebid'); - expect(parsedBidUrlQueryString).to.have.property('ccy').and.to.equal('EUR'); - expect(parsedBidUrlQueryString).to.have.property('bidfloor').and.to.equal('0.42'); - expect(parsedBidUrlQueryString).to.have.property('tag').and.to.equal('sas_42'); - expect(parsedBidUrlQueryString).to.have.property('sizes').and.to.equal('300x250,300x200'); - expect(parsedBidUrlQueryString).to.have.property('async').and.to.equal('1'); - - stubLoadScript.restore(); + it('Verify build request', () => { + config.setConfig({ + 'currency': 'EUR' + }); + const request = spec.buildRequests(DEFAULT_PARAMS); + expect(request).to.have.property('url').and.to.equal('http://prg.smartadserver.com/prebid/v1'); + expect(request).to.have.property('method').and.to.equal('POST'); + const requestContent = JSON.parse(request.data); + expect(requestContent).to.have.property('siteid').and.to.equal('1234'); + expect(requestContent).to.have.property('pageid').and.to.equal('5678'); + expect(requestContent).to.have.property('formatid').and.to.equal('90'); + expect(requestContent).to.have.property('currencyCode').and.to.equal('EUR'); + expect(requestContent).to.have.property('bidfloor').and.to.equal(0.42); + expect(requestContent).to.have.property('targeting').and.to.equal('test=prebid'); + expect(requestContent).to.have.property('tagId').and.to.equal('sas_42'); + expect(requestContent).to.have.property('sizes'); + expect(requestContent.sizes[0]).to.have.property('w').and.to.equal(300); + expect(requestContent.sizes[0]).to.have.property('h').and.to.equal(250); + expect(requestContent.sizes[1]).to.have.property('w').and.to.equal(300); + expect(requestContent.sizes[1]).to.have.property('h').and.to.equal(200); + expect(requestContent).to.have.property('pageDomain').and.to.equal(utils.getTopWindowUrl()); + expect(requestContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; }); - it('test optional parameters default value', function () { - var stubLoadScript = sinon.stub(adLoader, 'loadScript'); - - adapter().callBids(DEFAULT_PARAMS_WO_OPTIONAL); - - var bidUrl = stubLoadScript.getCall(0).args[0]; - var parsedBidUrl = urlParse(bidUrl); - var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - - expect(parsedBidUrlQueryString).to.have.property('tgt').and.to.equal(''); - expect(parsedBidUrlQueryString).to.have.property('ccy').and.to.equal('USD'); - - stubLoadScript.restore(); + it('Verify parse response', () => { + const request = spec.buildRequests(DEFAULT_PARAMS); + const bids = spec.interpretResponse(BID_RESPONSE, request); + expect(bids).to.have.lengthOf(1); + const bid = bids[0]; + expect(bid.cpm).to.equal(12); + expect(bid.ad).to.equal('< --- awesome script --- >'); + expect(bid.width).to.equal(300); + expect(bid.height).to.equal(250); + expect(bid.creativeId).to.equal('zioeufg'); + expect(bid.currency).to.equal('GBP'); + expect(bid.netRevenue).to.equal(true); + expect(bid.ttl).to.equal(300); + expect(bid.requestId).to.equal(request.bidId); + expect(bid.bidderCode).to.equal('smartadserver'); + expect(bid.referrer).to.equal(utils.getTopWindowUrl()); }); - it('creates an empty bid response if no bids', function() { - var stubLoadScript = sinon.stub(adLoader, 'loadScript', function(url) { - var bidUrl = stubLoadScript.getCall(0).args[0]; - var parsedBidUrl = urlParse(bidUrl); - var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - - $$PREBID_GLOBAL$$[parsedBidUrlQueryString.pbjscbk.split('.')[1]](null); - }); - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - - adapter().callBids(DEFAULT_PARAMS); - - var bidResponsePlacementCode = stubAddBidResponse.getCall(0).args[0]; - var bidResponseAd = stubAddBidResponse.getCall(0).args[1]; - - expect(bidResponsePlacementCode).to.equal(DEFAULT_PARAMS.bids[0].placementCode); - expect(bidResponseAd.getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID); - expect(bidResponseAd).to.have.property('bidderCode').and.to.equal('smartadserver'); - - stubLoadScript.restore(); - stubAddBidResponse.restore(); + it('Verifies bidder code', () => { + expect(spec.code).to.equal('smartadserver'); }); - it('creates a bid response if bid is returned', function() { - var stubLoadScript = sinon.stub(adLoader, 'loadScript', function(url) { - var bidUrl = stubLoadScript.getCall(0).args[0]; - var parsedBidUrl = urlParse(bidUrl); - var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query); - - $$PREBID_GLOBAL$$[parsedBidUrlQueryString.pbjscbk.split('.')[1]](BID_RESPONSE); - }); - var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); - - adapter().callBids(DEFAULT_PARAMS); - - var bidResponsePlacementCode = stubAddBidResponse.getCall(0).args[0]; - var bidResponseAd = stubAddBidResponse.getCall(0).args[1]; + it('Verifies bidder aliases', () => { + expect(spec.aliases).to.have.lengthOf(1); + expect(spec.aliases[0]).to.equal('smart'); + }); - expect(bidResponsePlacementCode).to.equal(DEFAULT_PARAMS.bids[0].placementCode); - expect(bidResponseAd.getStatusCode()).to.equal(CONSTANTS.STATUS.GOOD); - expect(bidResponseAd).to.have.property('bidderCode').and.to.equal('smartadserver'); - expect(bidResponseAd).to.have.property('cpm').and.to.equal(BID_RESPONSE.cpm); - expect(bidResponseAd).to.have.property('ad').and.to.equal(BID_RESPONSE.ad); - expect(bidResponseAd).to.have.property('width').and.to.equal(BID_RESPONSE.width); - expect(bidResponseAd).to.have.property('height').and.to.equal(BID_RESPONSE.height); + it('Verifies if bid request valid', () => { + expect(spec.isBidRequestValid(DEFAULT_PARAMS)).to.equal(true); + expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL)).to.equal(true); + expect(spec.isBidRequestValid({})).to.equal(false); + expect(spec.isBidRequestValid({ + params: {} + })).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + pageid: 123 + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + siteid: 123 + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + formatid: 123, + pageid: 234 + } + })).to.equal(false); + expect(spec.isBidRequestValid({ + params: { + domain: 'www.test.com', + pageid: 234 + } + })).to.equal(false); + }); - stubLoadScript.restore(); - stubAddBidResponse.restore(); + it('Verifies sync options', () => { + expect(spec.getUserSyncs({})).to.be.undefined; + expect(spec.getUserSyncs({ + iframeEnabled: false + })).to.be.undefined; + expect(spec.getUserSyncs({ + iframeEnabled: true + })).to.be.undefined; }); }); From 2e8686140a0348e2cf80cc0be5673d34a8564c9e Mon Sep 17 00:00:00 2001 From: gcarnec Date: Wed, 6 Dec 2017 11:46:26 +0100 Subject: [PATCH 2/8] corrected some things following pullrequest review --- modules/smartadserverBidAdapter.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index d39ff9198c8..04341f46985 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -31,15 +31,12 @@ export const spec = { // to find which one the ad server needs // pull requested transaction ID from bidderRequest.bids[].transactionId - if (!Array.isArray(validBidRequests)) { - validBidRequests = [validBidRequests]; - } var bid = validBidRequests[0]; const payload = { siteid: bid.params.siteId, pageid: bid.params.pageId, formatid: bid.params.formatId, - currencyCode: config.getConfig('currency'), + currencyCode: config.getConfig('currency').adServerCurrency, bidfloor: bid.params.bidfloor || 0.0, targeting: bid.params.target && bid.params.target != '' ? bid.params.target : undefined, tagId: bid.adUnitCode, @@ -66,28 +63,25 @@ export const spec = { */ interpretResponse: function (serverResponse, bidRequest) { const bidResponses = []; - if (serverResponse) { + var response = serverResponse.body; + if (response) { const bidResponse = { requestId: bidRequest.bidId, bidderCode: spec.code, - cpm: serverResponse.cpm, - width: serverResponse.width, - height: serverResponse.height, - creativeId: serverResponse.creativeId, - dealId: serverResponse.dealId, - currency: serverResponse.currency, - netRevenue: serverResponse.isNetCpm, - ttl: serverResponse.ttl, + cpm: response.cpm, + width: response.width, + height: response.height, + creativeId: response.creativeId, + dealId: response.dealId, + currency: response.currency, + netRevenue: response.isNetCpm, + ttl: response.ttl, referrer: utils.getTopWindowUrl(), - ad: serverResponse.ad + ad: response.ad }; bidResponses.push(bidResponse); } return bidResponses; - }, - getUserSyncs: function (syncOptions) { - // iframe || image - return undefined; } } registerBidder(spec); From 35b3ec6dcbd38990e1935a9d4c49daa40219f9b9 Mon Sep 17 00:00:00 2001 From: gcarnec Date: Mon, 11 Dec 2017 10:31:11 +0100 Subject: [PATCH 3/8] slight change to avoid potential error --- modules/smartadserverBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index 04341f46985..033a280af88 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -36,7 +36,7 @@ export const spec = { siteid: bid.params.siteId, pageid: bid.params.pageId, formatid: bid.params.formatId, - currencyCode: config.getConfig('currency').adServerCurrency, + currencyCode: config.getConfig('currency.adServerCurrency'), bidfloor: bid.params.bidfloor || 0.0, targeting: bid.params.target && bid.params.target != '' ? bid.params.target : undefined, tagId: bid.adUnitCode, From aea62dc63517bd24cc2c349b98c375174fbc344a Mon Sep 17 00:00:00 2001 From: gcarnec Date: Wed, 20 Dec 2017 10:58:13 +0100 Subject: [PATCH 4/8] added the maintainer email --- modules/smartadserverBidAdapter.md | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/smartadserverBidAdapter.md b/modules/smartadserverBidAdapter.md index 6fe79527c3d..a5efc0cff11 100644 --- a/modules/smartadserverBidAdapter.md +++ b/modules/smartadserverBidAdapter.md @@ -3,6 +3,7 @@ ``` Module Name: Smart Ad Server Bidder Adapter Module Type: Bidder Adapter +Maintainer: gcarnec@smartadserver.com ``` # Description From fea1e24c94a28d15b49611f8282d3006bef0ebf7 Mon Sep 17 00:00:00 2001 From: gcarnec Date: Wed, 20 Dec 2017 14:15:44 +0100 Subject: [PATCH 5/8] Updated the tests to fit changes --- .../modules/smartadserverBidAdapter_spec.js | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index a7e29186893..e5bacbf5500 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -16,7 +16,7 @@ import { import * as utils from 'src/utils'; describe('Smart ad server bid adapter tests', () => { - var DEFAULT_PARAMS = { + var DEFAULT_PARAMS = [{ adUnitCode: 'sas_42', bidId: 'abcd1234', sizes: [ @@ -34,9 +34,9 @@ describe('Smart ad server bid adapter tests', () => { }, requestId: 'efgh5678', transactionId: 'zsfgzzg' - }; + }]; - var DEFAULT_PARAMS_WO_OPTIONAL = { + var DEFAULT_PARAMS_WO_OPTIONAL = [{ adUnitCode: 'sas_42', bidId: 'abcd1234', sizes: [ @@ -51,22 +51,26 @@ describe('Smart ad server bid adapter tests', () => { formatId: '90' }, requestId: 'efgh5678' - }; + }]; var BID_RESPONSE = { - cpm: 12, - width: 300, - height: 250, - creativeId: 'zioeufg', - currency: 'GBP', - isNetCpm: true, - ttl: 300, - ad: '< --- awesome script --- >' + body: { + cpm: 12, + width: 300, + height: 250, + creativeId: 'zioeufg', + currency: 'GBP', + isNetCpm: true, + ttl: 300, + ad: '< --- awesome script --- >' + } }; it('Verify build request', () => { config.setConfig({ - 'currency': 'EUR' + 'currency': { + 'adServerCurrency': 'EUR' + } }); const request = spec.buildRequests(DEFAULT_PARAMS); expect(request).to.have.property('url').and.to.equal('http://prg.smartadserver.com/prebid/v1'); @@ -116,8 +120,8 @@ describe('Smart ad server bid adapter tests', () => { }); it('Verifies if bid request valid', () => { - expect(spec.isBidRequestValid(DEFAULT_PARAMS)).to.equal(true); - expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL)).to.equal(true); + expect(spec.isBidRequestValid(DEFAULT_PARAMS[0])).to.equal(true); + expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL[0])).to.equal(true); expect(spec.isBidRequestValid({})).to.equal(false); expect(spec.isBidRequestValid({ params: {} @@ -147,12 +151,6 @@ describe('Smart ad server bid adapter tests', () => { }); it('Verifies sync options', () => { - expect(spec.getUserSyncs({})).to.be.undefined; - expect(spec.getUserSyncs({ - iframeEnabled: false - })).to.be.undefined; - expect(spec.getUserSyncs({ - iframeEnabled: true - })).to.be.undefined; + expect(spec.getUserSyncs).to.be.undefined; }); }); From 55056e7ef98b5ad716606eebcc654f1c7c8f494e Mon Sep 17 00:00:00 2001 From: gcarnec Date: Thu, 4 Jan 2018 15:54:41 +0100 Subject: [PATCH 6/8] Updated the doc, removed the bidderCode, added adUrl --- modules/smartadserverBidAdapter.js | 2 +- modules/smartadserverBidAdapter.md | 6 +++--- test/spec/modules/smartadserverBidAdapter_spec.js | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index 033a280af88..a9a762784f2 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -67,7 +67,6 @@ export const spec = { if (response) { const bidResponse = { requestId: bidRequest.bidId, - bidderCode: spec.code, cpm: response.cpm, width: response.width, height: response.height, @@ -77,6 +76,7 @@ export const spec = { netRevenue: response.isNetCpm, ttl: response.ttl, referrer: utils.getTopWindowUrl(), + adUrl: response.adUrl, ad: response.ad }; bidResponses.push(bidResponse); diff --git a/modules/smartadserverBidAdapter.md b/modules/smartadserverBidAdapter.md index a5efc0cff11..f904aa40b3a 100644 --- a/modules/smartadserverBidAdapter.md +++ b/modules/smartadserverBidAdapter.md @@ -24,9 +24,9 @@ Please reach out to your Technical account manager for more information. bidder: "smart", params: { domain: 'http://prg.smartadserver.com', - siteId: 32216, - pageId: 881291, - formatId: 13695, + siteId: 207435, + pageId: 896536, + formatId: 62913 } } ] diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index e5bacbf5500..06a50333e5f 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -62,6 +62,7 @@ describe('Smart ad server bid adapter tests', () => { currency: 'GBP', isNetCpm: true, ttl: 300, + adUrl: 'http://awesome.fake.url', ad: '< --- awesome script --- >' } }; @@ -98,6 +99,7 @@ describe('Smart ad server bid adapter tests', () => { expect(bids).to.have.lengthOf(1); const bid = bids[0]; expect(bid.cpm).to.equal(12); + expect(bid.adUrl).to.equal('http://awesome.fake.url'); expect(bid.ad).to.equal('< --- awesome script --- >'); expect(bid.width).to.equal(300); expect(bid.height).to.equal(250); @@ -106,7 +108,6 @@ describe('Smart ad server bid adapter tests', () => { expect(bid.netRevenue).to.equal(true); expect(bid.ttl).to.equal(300); expect(bid.requestId).to.equal(request.bidId); - expect(bid.bidderCode).to.equal('smartadserver'); expect(bid.referrer).to.equal(utils.getTopWindowUrl()); }); From cd90cc8e3b1f00198338214ee136eb1c21515dfd Mon Sep 17 00:00:00 2001 From: gcarnec Date: Fri, 5 Jan 2018 11:54:18 +0100 Subject: [PATCH 7/8] fix adapter --- modules/smartadserverBidAdapter.js | 5 +++-- test/spec/modules/smartadserverBidAdapter_spec.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index a9a762784f2..d5534a45261 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -46,7 +46,8 @@ export const spec = { })), pageDomain: utils.getTopWindowUrl(), transactionId: bid.transactionId, - timeout: config.getConfig('bidderTimeout') + timeout: config.getConfig('bidderTimeout'), + bidId: bid.bidId }; const payloadString = JSON.stringify(payload); return { @@ -66,7 +67,7 @@ export const spec = { var response = serverResponse.body; if (response) { const bidResponse = { - requestId: bidRequest.bidId, + requestId: JSON.parse(bidRequest.data).bidId, cpm: response.cpm, width: response.width, height: response.height, diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js index 06a50333e5f..5cb4a1277fb 100644 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ b/test/spec/modules/smartadserverBidAdapter_spec.js @@ -107,7 +107,7 @@ describe('Smart ad server bid adapter tests', () => { expect(bid.currency).to.equal('GBP'); expect(bid.netRevenue).to.equal(true); expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(request.bidId); + expect(bid.requestId).to.equal(DEFAULT_PARAMS[0].bidId); expect(bid.referrer).to.equal(utils.getTopWindowUrl()); }); From 9e3a814fd80546e651037c9bbae29e736999e5d2 Mon Sep 17 00:00:00 2001 From: gcarnec Date: Tue, 23 Jan 2018 10:53:57 +0100 Subject: [PATCH 8/8] Added try catch around JSON.parse --- modules/smartadserverBidAdapter.js | 36 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index d5534a45261..4828f3a36a8 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -65,22 +65,26 @@ export const spec = { interpretResponse: function (serverResponse, bidRequest) { const bidResponses = []; var response = serverResponse.body; - if (response) { - const bidResponse = { - requestId: JSON.parse(bidRequest.data).bidId, - cpm: response.cpm, - width: response.width, - height: response.height, - creativeId: response.creativeId, - dealId: response.dealId, - currency: response.currency, - netRevenue: response.isNetCpm, - ttl: response.ttl, - referrer: utils.getTopWindowUrl(), - adUrl: response.adUrl, - ad: response.ad - }; - bidResponses.push(bidResponse); + try { + if (response) { + const bidResponse = { + requestId: JSON.parse(bidRequest.data).bidId, + cpm: response.cpm, + width: response.width, + height: response.height, + creativeId: response.creativeId, + dealId: response.dealId, + currency: response.currency, + netRevenue: response.isNetCpm, + ttl: response.ttl, + referrer: utils.getTopWindowUrl(), + adUrl: response.adUrl, + ad: response.ad + }; + bidResponses.push(bidResponse); + } + } catch (error) { + console.log('Error while parsing smart server response'); } return bidResponses; }