diff --git a/gulpfile.js b/gulpfile.js index 1ce30bcb945..141cac6d585 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -104,7 +104,7 @@ gulp.task('codeQuality', ['jshint', 'jscs'], function() {}); gulp.task('default', ['build'], function() {}); -gulp.task('serve', ['build-dev', 'watch'], function () { +gulp.task('serve', ['build-dev', 'watch', 'browser-sync'], function () { var port = 9999; require('http').createServer(ecstatic({ root: __dirname @@ -112,7 +112,7 @@ gulp.task('serve', ['build-dev', 'watch'], function () { console.log('Server started at http://localhost:' + port + '/'); }); -gulp.task('build-dev', ['jscs', 'clean-dist', 'browserify', 'browser-sync', 'unit-tests'], function () { +gulp.task('build-dev', ['jscs', 'clean-dist', 'browserify', 'unit-tests'], function () { gulp.src(['src/prebid.js']) .pipe(gulpBrowserify({ debug: false diff --git a/src/bidmanager.js b/src/bidmanager.js index 27e12b9c4ab..f52062d08e4 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -168,7 +168,7 @@ exports.addBidResponse = function(adUnitCode, bid) { //if there is any key value pairs to map do here var keyValues = {}; if (bid.bidderCode && bid.cpm !== 0) { - keyValues = getKeyValueTargetingPairs(bid.bidderCode, bid); + keyValues = this.getKeyValueTargetingPairs(bid.bidderCode, bid); bid.adserverTargeting = keyValues; } @@ -213,7 +213,7 @@ exports.createEmptyBidResponseObj = function() { }; }; -function getKeyValueTargetingPairs(bidderCode, custBidObj) { +exports.getKeyValueTargetingPairs = function(bidderCode, custBidObj) { //retrive key value settings var keyValues = {}; var bidder_settings = pbjs.bidderSettings || {}; @@ -260,7 +260,7 @@ function getKeyValueTargetingPairs(bidderCode, custBidObj) { } return keyValues; -} +}; function setKeys(keyValues, bidderSettings, custBidObj) { var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]; diff --git a/test/automatedRunnner.html b/test/automatedRunnner.html index 51bdae3a3cf..2f82a9a36da 100644 --- a/test/automatedRunnner.html +++ b/test/automatedRunnner.html @@ -3,20 +3,27 @@ - TextChanger tests + Unit Tests for Prebid.js
+ + + + - + + \ No newline at end of file diff --git a/test/test.js b/test/test.js index 7b70fee0157..2806a7dc6e2 100644 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,7 @@ var assert = require("assert"); //TODO refactor to use the spec files var utils = require('../src/utils'); +var bidmanager = require('../src/bidmanager'); describe('replaceTokenInString', function(){ @@ -22,4 +23,159 @@ var utils = require('../src/utils'); 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); + + }); + + }); }); \ No newline at end of file