Skip to content

Commit

Permalink
gppControl: accept flat section data
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Nov 14, 2024
1 parent 62307a3 commit 87d46df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libraries/mspa/activityControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../src/activities/activities.js';
import {gppDataHandler} from '../../src/adapterManager.js';
import {logInfo} from '../../src/utils.js';
import {isPlainObject} from "lodash/lang.js";

// default interpretation for MSPA consent(s):
// https://docs.prebid.org/features/mspa-usnat.html
Expand Down Expand Up @@ -105,7 +106,7 @@ export function mspaRule(sids, getConsent, denies, applicableSids = () => gppDat
}

function flatSection(subsections) {
if (subsections == null) return subsections;
if (!Array.isArray(subsections)) return subsections;
return subsections.reduceRight((subsection, consent) => {
return Object.assign(consent, subsection);
}, {});
Expand Down
7 changes: 7 additions & 0 deletions test/spec/libraries/mspa/activityControls_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ describe('setupRules', () => {
sinon.assert.calledWith(rules.mockActivity, {mock: 'consent'})
});

it('should accept already flattened section data', () => {
consent.parsedSections.mockApi = {flat: 'consent'};
runSetup('mockApi', [1]);
isAllowed('mockActivity', {});
sinon.assert.calledWith(rules.mockActivity, {flat: 'consent'})
})

it('should not choke when no consent data is available', () => {
consent = null;
runSetup('mockApi', [1]);
Expand Down

0 comments on commit 87d46df

Please sign in to comment.