Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use a configurable vendor preset for s2sConfig #2073

Merged
merged 8 commits into from
Feb 12, 2018
55 changes: 48 additions & 7 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,38 @@ const DEFAULT_S2S_CURRENCY = 'USD';
const DEFAULT_S2S_NETREVENUE = true;

let _s2sConfig;

const s2sDefaultConfig = {
enabled: false,
timeout: 1000,
maxBids: 1,
adapter: 'prebidServer'
};

config.setDefaults({
's2sConfig': {
enabled: false,
timeout: 1000,
maxBids: 1,
adapter: 'prebidServer'
}
's2sConfig': s2sDefaultConfig
});

// accountId and bidders params are not included here, should be configured by end-user
const availVendorDefaults = {
'appnexus': {
adapter: 'prebidServer',
cookieSet: false,
enabled: true,
endpoint: '//prebid.adnxs.com/pbs/v1/auction',
syncEndpoint: '//prebid.adnxs.com/pbs/v1/cookie_sync',
timeout: 1000
},
'rubicon': {
adapter: 'prebidServer',
cookieSet: false,
enabled: true,
endpoint: '//prebid-server.rubiconproject.com/auction',
syncEndpoint: '//prebid-server.rubiconproject.com/cookie_sync',
timeout: 500
}
};

/**
* Set config for server to server header bidding
* @typedef {Object} options - required
Expand All @@ -42,6 +65,24 @@ config.setDefaults({
* @property {string} [cookieSetUrl] url for cookie set library, if passed then cookieSet is enabled
*/
function setS2sConfig(options) {
if (options.defaultVendor) {
let vendor = options.defaultVendor;
let optionKeys = Object.keys(options);

if (availVendorDefaults.hasOwnProperty(vendor)) {
// vendor keys will be set if either: the key was not specified by user
// or if the user did not set their own distinct value (ie using the system default) to override the vendor
Object.keys(availVendorDefaults[vendor]).forEach(function(vendorKey) {
if (s2sDefaultConfig[vendorKey] === options[vendorKey] || !includes(optionKeys, vendorKey)) {
options[vendorKey] = availVendorDefaults[vendor][vendorKey];
}
});
} else {
utils.logError('Incorrect or unavailable prebid server default vendor option: ' + vendor);
return false;
}
}

let keys = Object.keys(options);

if (['accountId', 'bidders', 'endpoint'].filter(key => {
Expand Down Expand Up @@ -320,7 +361,7 @@ export function PrebidServer() {
});
}
}
if (result.status === 'no_cookie' && typeof _s2sConfig.cookieSetUrl === 'string') {
if (result.status === 'no_cookie' && _s2sConfig.cookieSet && typeof _s2sConfig.cookieSetUrl === 'string') {
// cookie sync
cookieSet(_s2sConfig.cookieSetUrl);
}
Expand Down
75 changes: 73 additions & 2 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ describe('S2S Adapter', () => {
it('calls cookieSet cookie sync when no_cookie response && opted in', () => {
server.respondWith(JSON.stringify(RESPONSE_NO_PBS_COOKIE));
let myConfig = Object.assign({
cookieSet: true,
cookieSetUrl: 'https://acdn.adnxs.com/cookieset/cs.js'
}, CONFIG);

Expand All @@ -450,7 +451,7 @@ describe('S2S Adapter', () => {
utils.logError.restore();
});

it('should log error when accountId is missing', () => {
it('should log an error when accountId is missing', () => {
const options = {
enabled: true,
bidders: ['appnexus'],
Expand All @@ -463,7 +464,7 @@ describe('S2S Adapter', () => {
sinon.assert.calledOnce(logErrorSpy);
});

it('should log error when bidders is missing', () => {
it('should log an error when bidders is missing', () => {
const options = {
accountId: '1',
enabled: true,
Expand All @@ -475,5 +476,75 @@ describe('S2S Adapter', () => {
config.setConfig({ s2sConfig: options });
sinon.assert.calledOnce(logErrorSpy);
});

it('should log an error when endpoint is missing', () => {
const options = {
accountId: '1',
bidders: ['appnexus'],
timeout: 1000,
enabled: true,
adapter: 'prebidServer'
};

config.setConfig({ s2sConfig: options});
sinon.assert.calledOnce(logErrorSpy);
});

it('should log an error when using an unknown vendor', () => {
const options = {
accountId: '1',
bidders: ['appnexus'],
defaultVendor: 'mytest'
};

config.setConfig({ s2sConfig: options });
sinon.assert.calledOnce(logErrorSpy);
});

it('should configure the s2sConfig object with appnexus vendor defaults unless specified by user', () => {
const options = {
accountId: '123',
bidders: ['appnexus'],
defaultVendor: 'appnexus',
timeout: 750
};

config.setConfig({ s2sConfig: options });
sinon.assert.notCalled(logErrorSpy);

let vendorConfig = config.getConfig('s2sConfig');
expect(vendorConfig).to.have.property('accountId', '123');
expect(vendorConfig).to.have.property('adapter', 'prebidServer');
expect(vendorConfig.bidders).to.deep.equal(['appnexus']);
expect(vendorConfig.cookieSet).to.be.false;
expect(vendorConfig.cookieSetUrl).to.be.undefined;
expect(vendorConfig.enabled).to.be.true;
expect(vendorConfig).to.have.property('endpoint', '//prebid.adnxs.com/pbs/v1/auction');
expect(vendorConfig).to.have.property('syncEndpoint', '//prebid.adnxs.com/pbs/v1/cookie_sync');
expect(vendorConfig).to.have.property('timeout', 750);
});

it('should configure the s2sConfig object with rubicon vendor defaults unless specified by user', () => {
const options = {
accountId: 'abc',
bidders: ['rubicon'],
defaultVendor: 'rubicon',
timeout: 750
};

config.setConfig({ s2sConfig: options });
sinon.assert.notCalled(logErrorSpy);

let vendorConfig = config.getConfig('s2sConfig');
expect(vendorConfig).to.have.property('accountId', 'abc');
expect(vendorConfig).to.have.property('adapter', 'prebidServer');
expect(vendorConfig.bidders).to.deep.equal(['rubicon']);
expect(vendorConfig.cookieSet).to.be.false;
expect(vendorConfig.cookieSetUrl).to.be.undefined;
expect(vendorConfig.enabled).to.be.true;
expect(vendorConfig).to.have.property('endpoint', '//prebid-server.rubiconproject.com/auction');
expect(vendorConfig).to.have.property('syncEndpoint', '//prebid-server.rubiconproject.com/cookie_sync');
expect(vendorConfig).to.have.property('timeout', 750);
});
});
});