Skip to content

Commit

Permalink
Price Floors: Fix bug when caching floor lookup (#5673)
Browse files Browse the repository at this point in the history
* Cannot pass cached floor by reference, adjustments break it!

* fix typo

Co-authored-by: Leif Wickland <[email protected]>

Co-authored-by: Leif Wickland <[email protected]>
  • Loading branch information
robertrmartinez and leifwickland authored Sep 2, 2020
1 parent cb3a3b3 commit bb18807
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {})
// if we already have gotten the matching rule from this matching input then use it! No need to look again
let previousMatch = utils.deepAccess(floorData, `matchingInputs.${matchingInput}`);
if (previousMatch) {
return previousMatch;
return {...previousMatch};
}
let allPossibleMatches = generatePossibleEnumerations(fieldValues, utils.deepAccess(floorData, 'schema.delimiter') || '|');
let matchingRule = find(allPossibleMatches, hashValue => floorData.values.hasOwnProperty(hashValue));
Expand Down
14 changes: 14 additions & 0 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ describe('the price floors module', function () {
matchingRule: '*'
});
});
it('does not alter cached matched input if conversion occurs', function () {
let inputData = {...basicFloorData};
[0.2, 0.4, 0.6, 0.8].forEach(modifier => {
let result = getFirstMatchingFloor(inputData, basicBidRequest, {mediaType: 'banner', size: '*'});
// result should always be the same
expect(result).to.deep.equal({
matchingFloor: 1.0,
matchingData: 'banner',
matchingRule: 'banner'
});
// make sure a post retrieval adjustment does not alter the cached floor
result.matchingFloor = result.matchingFloor * modifier;
});
});
it('selects the right floor for different sizes', function () {
let inputFloorData = {
currency: 'USD',
Expand Down

0 comments on commit bb18807

Please sign in to comment.