-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from prebid/unit_test_upgrade
Unit test upgrade
- Loading branch information
Showing
5 changed files
with
267 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<!-- Test runner HTML file for executing tests with PhantomJS & displaying results --> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>Unit Tests for Prebid.js</title> | ||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"/> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
<script src="../node_modules/mocha/mocha.js"></script> | ||
|
||
<!-- <script src="lib/blanket.js"></script> --> | ||
|
||
|
||
<script>mocha.setup('bdd')</script> | ||
<script src="tests-browserify.js" data-cover></script> | ||
|
||
<script> | ||
|
||
if (window.mochaPhantomJS) { | ||
mochaPhantomJS.run(); | ||
} else { | ||
mocha.run(); | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
var assert = require("assert"); | ||
|
||
/* use this method to test individual files instead of the whole prebid.js project */ | ||
|
||
//TODO refactor to use the spec files | ||
var utils = require('../src/utils'); | ||
var bidmanager = require('../src/bidmanager'); | ||
|
||
describe('replaceTokenInString', function(){ | ||
|
||
it('should replace all given tokens in a String', function() { | ||
var tokensToReplace = { | ||
'foo': 'bar', | ||
'zap': 'quux' | ||
}; | ||
|
||
var output = utils.replaceTokenInString("hello %FOO%, I am %ZAP%", tokensToReplace, "%"); | ||
assert.equal(output, "hello bar, I am quux"); | ||
}); | ||
|
||
it('should ignore tokens it does not see', function() { | ||
var output = utils.replaceTokenInString("hello %FOO%", {}, "%"); | ||
|
||
assert.equal(output, "hello %FOO%"); | ||
}); | ||
}); | ||
|
||
|
||
describe('bidmanager.js', function(){ | ||
|
||
|
||
|
||
describe('getKeyValueTargetingPairs', function(){ | ||
var bid = {}; | ||
var bidPriceCpm = 5.578; | ||
var bidPbLg = 5.50; | ||
var bidPbMg = 5.50; | ||
var bidPbHg = 5.57; | ||
var adUnitCode = '12345'; | ||
var bidderCode = 'appnexus'; | ||
var size = '300x250'; | ||
var adId = '1adId'; | ||
|
||
before(function() { | ||
console.log(pbjs); | ||
bid.cpm = bidPriceCpm; | ||
bid.pbLg = bidPbLg; | ||
bid.pbMg = bidPbMg; | ||
bid.pbHg = bidPbHg; | ||
bid.height = 300; | ||
bid.width = 250; | ||
bid.adUnitCode = adUnitCode; | ||
bid.getSize = function(){ | ||
return this.height + 'x' + this.width; | ||
}; | ||
bid.bidderCode = bidderCode; | ||
bid.adId = adId; | ||
|
||
}); | ||
|
||
|
||
it('No bidder level configuration defined - default', function() { | ||
var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": bidPbMg,"hb_size": size}; | ||
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid); | ||
assert.deepEqual(response, expected); | ||
|
||
}); | ||
|
||
it('Custom configuration for all bidders', function() { | ||
pbjs.bidderSettings = | ||
{ | ||
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 bidResponse.pbHg; | ||
} | ||
}, { | ||
key: "hb_size", | ||
val: function(bidResponse) { | ||
return bidResponse.size; | ||
|
||
} | ||
}] | ||
|
||
} | ||
}; | ||
|
||
var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": bidPbHg,"hb_size": size}; | ||
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid); | ||
assert.deepEqual(response, expected); | ||
|
||
}); | ||
|
||
it('Custom configuration for one bidder', function() { | ||
pbjs.bidderSettings = | ||
{ | ||
appnexus: { | ||
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 bidResponse.pbHg; | ||
} | ||
}, { | ||
key: "hb_size", | ||
val: function(bidResponse) { | ||
return bidResponse.size; | ||
|
||
} | ||
}] | ||
|
||
} | ||
}; | ||
|
||
var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": bidPbHg,"hb_size": size}; | ||
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid); | ||
assert.deepEqual(response, expected); | ||
|
||
}); | ||
|
||
it('Custom configuration for one bidder - not matched', function() { | ||
pbjs.bidderSettings = | ||
{ | ||
nonExistentBidder: { | ||
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 bidResponse.pbHg; | ||
} | ||
}, { | ||
key: "hb_size", | ||
val: function(bidResponse) { | ||
return bidResponse.size; | ||
|
||
} | ||
}] | ||
|
||
} | ||
}; | ||
|
||
var expected = {"hb_bidder": bidderCode, "hb_adid": adId,"hb_pb": bidPbMg,"hb_size": size}; | ||
var response = bidmanager.getKeyValueTargetingPairs(bidderCode, bid); | ||
assert.deepEqual(response, expected); | ||
|
||
}); | ||
|
||
}); | ||
}); |