Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

priceFloors: fix bug where default does not work on adUnit-level floors #10475

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
do not require adUnits to repeat the same schema
  • Loading branch information
dgirardi committed Sep 13, 2023
commit 1d11cf233b95c58b57c51feb0b7d5cfdeba84ae3
9 changes: 6 additions & 3 deletions modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,17 @@ function normalizeRulesForAuction(floorData, adUnitCode) {
* Only called if no set config or fetch level data has returned
*/
export function getFloorDataFromAdUnits(adUnits) {
let schemaDef;
return adUnits.reduce((accum, adUnit) => {
if (isFloorsDataValid(adUnit.floors)) {
if (schemaDef == null) schemaDef = adUnit.floors;
const floors = Object.assign({}, schemaDef, adUnit.floors)
if (isFloorsDataValid(floors)) {
// if values already exist we want to not overwrite them
if (!accum.values) {
accum = getFloorsDataForAuction(adUnit.floors, adUnit.code);
accum = getFloorsDataForAuction(floors, adUnit.code);
accum.location = 'adUnit';
} else {
let newRules = getFloorsDataForAuction(adUnit.floors, adUnit.code).values;
let newRules = getFloorsDataForAuction(floors, adUnit.code).values;
// copy over the new rules into our values object
Object.assign(accum.values, newRules);
}
Expand Down
25 changes: 19 additions & 6 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,22 @@ describe('the price floors module', function () {
adUnits[0].floors = {default: 1};
adUnits[1].floors = {default: 2};
expectFloors([1, 2])
});
it('on an adUnit with hidden schema', () => {
handleSetFloorsConfig({
...basicFloorConfig,
data: undefined
});
adUnits[0].floors = {
schema: {
fields: ['mediaType', 'gptSlot'],
},
default: 1
}
adUnits[1].floors = {
default: 2
}
expectFloors([1, 2]);
})
});
describe('should NOT be used when a star rule exists', () => {
Expand All @@ -756,19 +772,16 @@ describe('the price floors module', function () {
});
adUnits[0].floors = {
schema: {
fields: ['mediaType'],
fields: ['mediaType', 'gptSlot'],
},
values: {
'*': 1
'*|*': 1
},
default: 3
};
adUnits[1].floors = {
schema: {
fields: ['gptSlot'],
},
values: {
'*': 2
'*|*': 2
},
default: 4
}
Expand Down