Skip to content

Commit

Permalink
pbs adapter support bidder specifc options (prebid#3394)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
idettman authored and olafbuitelaar committed Jan 3, 2019
1 parent fa66cba commit c5c8a13
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
33 changes: 31 additions & 2 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}, {});

Expand Down
75 changes: 75 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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'
}
})
});
});
});

0 comments on commit c5c8a13

Please sign in to comment.