Skip to content

Commit

Permalink
Custom granularity fix (prebid#1546)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jaiminpanchal27 authored and philipwatson committed Sep 18, 2017
1 parent 4a42e25 commit 6b618be
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/spec/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
90 changes: 89 additions & 1 deletion test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 6b618be

Please sign in to comment.