Skip to content

Commit

Permalink
Update logic for #148 don't inherit bidderSettings unless they aren't…
Browse files Browse the repository at this point in the history
… including in the configuration for the bidder
  • Loading branch information
mkendall07 committed Jan 6, 2016
1 parent ba37238 commit 84f4990
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 15 deletions.
34 changes: 21 additions & 13 deletions src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,29 @@ exports.createEmptyBidResponseObj = function() {
};
};

function setDefaultAdServerTargeting (){


}

exports.getKeyValueTargetingPairs = function(bidderCode, custBidObj) {
var keyValues = {};
var bidder_settings = pbjs.bidderSettings || {};

//1) set the keys from prebid defaults
if (custBidObj && bidder_settings) {
//1) set keys from specific bidder setting if they exist
if (bidderCode && custBidObj && bidder_settings && bidder_settings[bidderCode] && bidder_settings[bidderCode][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) {
setKeys(keyValues, bidder_settings[bidderCode], custBidObj);
custBidObj.alwaysUseBid = bidder_settings[bidderCode].alwaysUseBid;
}

//2) set keys from standard setting. NOTE: this API doesn't seeem to be in use by any Adapter currently
else if (defaultBidderSettingsMap[bidderCode]) {
setKeys(keyValues, defaultBidderSettingsMap[bidderCode], custBidObj);
custBidObj.alwaysUseBid = defaultBidderSettingsMap[bidderCode].alwaysUseBid;
}

//3) set the keys from "standard" setting or from prebid defaults
else if (custBidObj && bidder_settings) {
if (!bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD]) {
bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD] = {
adserverTargeting: [{
Expand Down Expand Up @@ -248,17 +265,8 @@ exports.getKeyValueTargetingPairs = function(bidderCode, custBidObj) {
setKeys(keyValues, bidder_settings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD], custBidObj);
}

//2) set keys from inherited setting
if (defaultBidderSettingsMap[bidderCode]) {
setKeys(keyValues, defaultBidderSettingsMap[bidderCode], custBidObj);
custBidObj.alwaysUseBid = defaultBidderSettingsMap[bidderCode].alwaysUseBid;
}
//3) set keys from specific bidder setting
if (bidderCode && custBidObj && bidder_settings && bidder_settings[bidderCode]) {
//
setKeys(keyValues, bidder_settings[bidderCode], custBidObj);
custBidObj.alwaysUseBid = bidder_settings[bidderCode].alwaysUseBid;
}



return keyValues;
};
Expand Down
58 changes: 56 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ var bidmanager = require('../src/bidmanager');

});

it('Custom configuration for one bidder and inherit standard', function() {
it('Custom bidCpmAdjustment for one bidder and inherit standard', function() {
pbjs.bidderSettings =
{
appnexus: {
Expand All @@ -199,7 +199,61 @@ var bidmanager = require('../src/bidmanager');
//change default here
return 10.00;
}
}]

}
};

var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": 10.0 };
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid);
assert.deepEqual(response, expected);

});

it('Custom bidCpmAdjustment AND custom configuration for one bidder and do NOT inherit standard', function() {
pbjs.bidderSettings =
{
appnexus: {
bidCpmAdjustment : function(bidCpm){
return bidCpm * 0.7;
},
adserverTargeting: [{
key: "hb_bidder",
val: function(bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: "hb_adid",
val: function(bidResponse) {
return bidResponse.adId;
}
}, {
key: "hb_pb",
val: function(bidResponse) {
//change default here
return 15.00;
}
}]
},
standard: {
adserverTargeting: [{
key: "hb_bidder",
val: function(bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: "hb_adid",
val: function(bidResponse) {
return bidResponse.adId;
}
}, {
key: "hb_pb",
val: function(bidResponse) {
//change default here
return 10.00;
},
},
{
key: "hb_size",
val: function(bidResponse) {
return bidResponse.size;
Expand All @@ -210,7 +264,7 @@ var bidmanager = require('../src/bidmanager');
}
};

var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": 10.0 ,"hb_size": size};
var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": 15.0 };
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid);
assert.deepEqual(response, expected);

Expand Down

0 comments on commit 84f4990

Please sign in to comment.