From 354aaf046ec6962160c1e16d47a591645b8c8d54 Mon Sep 17 00:00:00 2001 From: Jaimin Panchal Date: Thu, 31 Aug 2017 10:54:40 -0400 Subject: [PATCH] Custom granularity fix (#1546) * priceGranularity should be custom when using custom price bucket * Unit test to check hb_pb when using custom price bucket * removed unwanted comment * updated unit test by testing all price range --- src/config.js | 2 +- test/spec/config_spec.js | 2 +- test/spec/unit/pbjs_api_spec.js | 90 ++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/src/config.js b/src/config.js index 66507db08478..f9c0e24e3341 100644 --- a/src/config.js +++ b/src/config.js @@ -86,7 +86,7 @@ export function newConfig() { this._priceGranularity = (hasGranularity(val)) ? val : GRANULARITY_OPTIONS.MEDIUM; } else if (typeof val === 'object') { this._customPriceBucket = val; - this._priceGranularity = GRANULARITY_OPTIONS.MEDIUM; + this._priceGranularity = GRANULARITY_OPTIONS.CUSTOM; utils.logMessage('Using custom price granularity'); } } diff --git a/test/spec/config_spec.js b/test/spec/config_spec.js index 77357df6d9e5..041be4591fc8 100644 --- a/test/spec/config_spec.js +++ b/test/spec/config_spec.js @@ -128,7 +128,7 @@ describe('config API', () => { }] }; setConfig({ priceGranularity: goodConfig }); - expect(getConfig('priceGranularity')).to.be.equal('medium'); + expect(getConfig('priceGranularity')).to.be.equal('custom'); expect(getConfig('customPriceBucket')).to.equal(goodConfig); }); diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index df8c070df977..ba322f23a1dc 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -339,6 +339,94 @@ describe('Unit: Prebid Module', function () { }); }); + describe('getAdserverTargeting', function() { + const customConfigObject = { + 'buckets': [ + { 'precision': 2, 'min': 0, 'max': 5, 'increment': 0.01 }, + { 'precision': 2, 'min': 5, 'max': 8, 'increment': 0.05}, + { 'precision': 2, 'min': 8, 'max': 20, 'increment': 0.5 }, + { 'precision': 2, 'min': 20, 'max': 25, 'increment': 1 } + ] + }; + let currentPriceBucket; + let bid; + + before(() => { + resetAuction(); + currentPriceBucket = configObj.getConfig('priceGranularity'); + configObj.setConfig({ priceGranularity: customConfigObject }); + bid = Object.assign({}, + bidfactory.createBid(2), + getBidResponses()[5] + ); + }); + + after(() => { + configObj.setConfig({ priceGranularity: currentPriceBucket }); + resetAuction(); + }) + + beforeEach(() => { + $$PREBID_GLOBAL$$._bidsReceived = []; + }) + + it('should get correct hb_pb when using bid.cpm is between 0 to 5', () => { + bid.cpm = 2.1234; + bidmanager.addBidResponse(bid.adUnitCode, bid); + var expected = { + '/19968336/header-bid-tag-0': { + hb_adid: '275bd666f5a5a5d', + hb_bidder: 'brealtime', + hb_pb: '2.12', + hb_size: '300x250' + } + } + expect($$PREBID_GLOBAL$$.getAdserverTargeting()).to.deep.equal(expected); + }); + + it('should get correct hb_pb when using bid.cpm is between 5 to 8', () => { + bid.cpm = 6.78; + bidmanager.addBidResponse(bid.adUnitCode, bid); + var expected = { + '/19968336/header-bid-tag-0': { + hb_adid: '275bd666f5a5a5d', + hb_bidder: 'brealtime', + hb_pb: '6.75', + hb_size: '300x250' + } + } + expect($$PREBID_GLOBAL$$.getAdserverTargeting()).to.deep.equal(expected); + }); + + it('should get correct hb_pb when using bid.cpm is between 8 to 20', () => { + bid.cpm = 19.5234; + bidmanager.addBidResponse(bid.adUnitCode, bid); + var expected = { + '/19968336/header-bid-tag-0': { + hb_adid: '275bd666f5a5a5d', + hb_bidder: 'brealtime', + hb_pb: '19.50', + hb_size: '300x250' + } + } + expect($$PREBID_GLOBAL$$.getAdserverTargeting()).to.deep.equal(expected); + }); + + it('should get correct hb_pb when using bid.cpm is between 20 to 25', () => { + bid.cpm = 21.5234; + bidmanager.addBidResponse(bid.adUnitCode, bid); + var expected = { + '/19968336/header-bid-tag-0': { + hb_adid: '275bd666f5a5a5d', + hb_bidder: 'brealtime', + hb_pb: '21.00', + hb_size: '300x250' + } + } + expect($$PREBID_GLOBAL$$.getAdserverTargeting()).to.deep.equal(expected); + }); + }); + describe('getBidResponses', function () { it('should return expected bid responses when not passed an adunitCode', function () { var result = $$PREBID_GLOBAL$$.getBidResponses(); @@ -1300,7 +1388,7 @@ describe('Unit: Prebid Module', function () { let priceGranularity = configObj.getConfig('priceGranularity'); let newCustomPriceBucket = configObj.getConfig('customPriceBucket'); expect(goodConfig).to.deep.equal(newCustomPriceBucket); - expect(priceGranularity).to.equal(CONSTANTS.GRANULARITY_OPTIONS.MEDIUM); + expect(priceGranularity).to.equal(CONSTANTS.GRANULARITY_OPTIONS.CUSTOM); }); });