From 9b47b1aaac6a15ba166349b020274d8f6f2122e2 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Wed, 2 Jan 2019 12:33:57 -0800 Subject: [PATCH] pbs adapter support bidder specifc options (#3394) * inprogress * add support for s2sConfig bidderOptions * merged missing updates from origin * changed arrow function in spec mocha tests to standard functions * fixed missing closing bracket and paren * updated incorrect spec expected values for s2sConfig tests * removed rubicon specific s2s configuration default value for sra * deleted unnecessary test and revised a test description since the rubicon specific defaults were removed * removed jsdoc for deprecated cookieSetUrl --- modules/prebidServerBidAdapter/index.js | 33 +++++++- .../modules/prebidServerBidAdapter_spec.js | 75 +++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index 4519a657345..7ecf61088d4 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -21,11 +21,39 @@ const DEFAULT_S2S_NETREVENUE = true; let _s2sConfig; +/** + * @typedef {Object} AdapterOptions + * @summary s2sConfig parameter that adds arguments to resulting OpenRTB payload that goes to Prebid Server + * @example + * // example of multiple bidder configuration + * pbjs.setConfig({ + * s2sConfig: { + * adapterOptions: { + * rubicon: {singleRequest: false} + * appnexus: {key: "value"} + * } + * } + * }); + */ + +/** + * @typedef {Object} S2SDefaultConfig + * @property {boolean} enabled + * @property {number} timeout + * @property {number} maxBids + * @property {string} adapter + * @property {AdapterOptions} adapterOptions + */ + +/** + * @type {S2SDefaultConfig} + */ const s2sDefaultConfig = { enabled: false, timeout: 1000, maxBids: 1, - adapter: 'prebidServer' + adapter: 'prebidServer', + adapterOptions: {} }; config.setDefaults({ @@ -43,6 +71,7 @@ config.setDefaults({ * @property {boolean} [cacheMarkup] whether to cache the adm result * @property {string} [adapter] adapter code to use for S2S * @property {string} [syncEndpoint] endpoint URL for syncing cookies + * @property {AdapterOptions} [adapterOptions] adds arguments to resulting OpenRTB payload to Prebid Server */ function setS2sConfig(options) { if (options.defaultVendor) { @@ -420,7 +449,7 @@ const OPEN_RTB_PROTOCOL = { if (adapter && adapter.getSpec().transformBidParams) { bid.params = adapter.getSpec().transformBidParams(bid.params, isOpenRtb()); } - acc[bid.bidder] = bid.params; + acc[bid.bidder] = (_s2sConfig.adapterOptions && _s2sConfig.adapterOptions[bid.bidder]) ? Object.assign({}, bid.params, _s2sConfig.adapterOptions[bid.bidder]) : bid.params; return acc; }, {}); diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index af568788bd8..cf0e9fafef1 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -780,6 +780,28 @@ describe('S2S Adapter', function () { expect(requestBid.account).is.equal('1'); expect(requestBid.limit).is.undefined; }); + + it('adds s2sConfig adapterOptions to request for ORTB', function () { + const s2sConfig = Object.assign({}, CONFIG, { + endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction', + adapterOptions: { + appnexus: { + key: 'value' + } + } + }); + const _config = { + s2sConfig: s2sConfig, + device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, + app: { bundle: 'com.test.app' }, + }; + + config.setConfig(_config); + adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); + const requestBid = JSON.parse(requests[0].requestBody); + expect(requestBid.imp[0].ext.appnexus).to.haveOwnProperty('key'); + expect(requestBid.imp[0].ext.appnexus.key).to.be.equal('value') + }); }); describe('response handler', function () { @@ -1138,5 +1160,58 @@ describe('S2S Adapter', function () { expect(vendorConfig).to.have.property('syncEndpoint', '//prebid-server.rubiconproject.com/cookie_sync'); expect(vendorConfig).to.have.property('timeout', 750); }); + + it('should return proper defaults', function () { + expect(config.getConfig('s2sConfig')).to.deep.equal({ + 'accountId': 'abc', + 'adapter': 'prebidServer', + 'bidders': ['rubicon'], + 'defaultVendor': 'rubicon', + 'enabled': true, + 'endpoint': '//prebid-server.rubiconproject.com/openrtb2/auction', + 'syncEndpoint': '//prebid-server.rubiconproject.com/cookie_sync', + 'timeout': 750 + }) + }); + + it('should return default adapterOptions if not set', function () { + config.setConfig({ + s2sConfig: { + accountId: 'abc', + bidders: ['rubicon'], + defaultVendor: 'rubicon', + timeout: 750 + } + }); + expect(config.getConfig('s2sConfig')).to.deep.equal({ + enabled: true, + timeout: 750, + adapter: 'prebidServer', + accountId: 'abc', + bidders: ['rubicon'], + defaultVendor: 'rubicon', + endpoint: '//prebid-server.rubiconproject.com/openrtb2/auction', + syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync' + }) + }); + + it('should set adapterOptions', function () { + config.setConfig({ + s2sConfig: { + adapterOptions: { + rubicon: { + singleRequest: true, + foo: 'bar' + } + } + } + }); + expect(config.getConfig('s2sConfig').adapterOptions).to.deep.equal({ + rubicon: { + singleRequest: true, + foo: 'bar' + } + }) + }); }); });