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

UOE 7234: Create s2sConfig object with required parameters for PrebidServerBidAdapater #326

Open
wants to merge 4 commits into
base: nightly5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src_new/adapters/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,10 @@ function setPrebidConfig(){
refThis.assignCurrencyConfigIfRequired(prebidConfig);
refThis.assignSchainConfigIfRequired(prebidConfig);
refThis.assignSingleRequestConfigForBidders(prebidConfig);
// if usePBSAdapatar is 1 then add s2sConfig
if(CONF.pwt.usePBSAdapatar == "1") {
refThis.gets2sConfig(prebidConfig);
}
// Adding a hook for publishers to modify the Prebid Config we have generated
util.handleHook(CONSTANTS.HOOKS.PREBID_SET_CONFIG, [ prebidConfig ]);
//todo: stop supporting this hook let pubs use pbjs.requestBids hook
Expand All @@ -959,6 +963,22 @@ function setPrebidConfig(){

exports.setPrebidConfig = setPrebidConfig;

function gets2sConfig(prebidConfig){
var s2sBidders = CONFIG.getServerEnabledAdaptars();

prebidConfig["s2sConfig"] = {
accountId: CONSTANTS.PBSPARAMS.accountId,
adapter: CONSTANTS.PBSPARAMS.adapter,
enabled: true,
bidders: s2sBidders,
endpoint: CONSTANTS.PBSPARAMS.endpoint,
syncEndpoint: CONSTANTS.PBSPARAMS.syncEndpoint,
timeout: CONFIG.getTimeoutForPBSRequest()
}
}

exports.gets2sConfig = gets2sConfig;

function getFloorsConfiguration(prebidConfig){
if(CONFIG.isFloorPriceModuleEnabled() == true){
prebidConfig["floors"]={
Expand Down
21 changes: 21 additions & 0 deletions src_new/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,25 @@ exports.getAdapterNameForAlias = function(aliasName){

exports.isSSOEnabled = function() {
return parseInt(config[CONSTANTS.CONFIG.COMMON][CONSTANTS.CONFIG.SSO_ENABLED]) === 1;
}

exports.getServerEnabledAdaptars = function() {
var s2sBidders = Object.keys(config.adapters).filter(function(adapter){
if(config.adapters[adapter]['serverSideEnabled'] == "1") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Strings must use doublequote.

Suggested change
if(config.adapters[adapter]['serverSideEnabled'] == "1") {
if(config.adapters[adapter]["serverSideEnabled"] == "1") {

return adapter;
}
});
return s2sBidders;
}

exports.getTimeoutForPBSRequest = function() {
var ssTimeOut = parseInt(config.pwt.ssTimeout);
var maxTimeout = CONSTANTS.TIMEOUT_CONFIG.MaxTimeout;
var minTimeout = CONSTANTS.TIMEOUT_CONFIG.MinTimeout;
if(ssTimeOut >= minTimeout && ssTimeOut <= maxTimeout) {
return ssTimeOut;
} else if(ssTimeOut >= minTimeout) {
return maxTimeout;
}
return minTimeout;
}
13 changes: 13 additions & 0 deletions src_new/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,16 @@ exports.BID_STATUS = {
}
// Add list of PubMatic aliases here.
exports.PUBMATIC_ALIASES = ["pubmatic2"];

exports.PBSPARAMS = {
accountId: "1",
adapter: "prebidServer",
// endpoint: "http://prebid-server.pubmatic.com/prebidserver/auction",
endpoint: "https://ow.pubmatic.com/pbs/openrtb2/auction",
syncEndpoint: "https://ow.pubmatic.com/cookie_sync/?sec=1"
}

exports.TIMEOUT_CONFIG = {
MaxTimeout: 500,
MinTimeout: 200
}
39 changes: 39 additions & 0 deletions test/adapters/prebid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,45 @@ describe('ADAPTER: Prebid', function() {
});
})

// Test cases to generate s2sConfig
describe('generates2sConfig',function(){
var prebidConfig = {};
var expectedResult = {};
beforeEach(function(done){
CONF.adapters['rubicon']['serverSideEnabled'] = "1";
CONF.pwt['ssTimeout'] = "500";

expectedResult = {
accountId: "1",
adapter: "prebidServer",
enabled: true,
bidders: ['rubicon'],
endpoint: "https://ow.pubmatic.com/pbs/openrtb2/auction",
syncEndpoint: "https://ow.pubmatic.com/cookie_sync/?sec=1",
timeout: 500,
};
done();
});

afterEach(function(done){
CONF.adapters['rubicon']['serverSideEnabled'] = "0";
delete CONF.pwt['ssTimeout'];
prebidConfig = {};
done();
});

it('should be a functiion',function(done){
PREBID.gets2sConfig.should.be.a('function');
done();
});

it('should set s2sConfig properties',function(done){
PREBID.gets2sConfig(prebidConfig);
expect(prebidConfig.s2sConfig).to.be.deep.equal(expectedResult);
done();
});
})

describe('#addOnBidRequestHandler',function(){
beforeEach(function(done) {
sinon.stub(UTIL, 'isFunction');
Expand Down