Skip to content

Commit

Permalink
FIDES-1606: Change BlueConic Consent Behavior (#5545)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvandort authored Nov 26, 2024
1 parent a54b430 commit e90b858
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 40 deletions.
112 changes: 74 additions & 38 deletions clients/fides-js/__tests__/integrations/blueconic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,87 @@ const setupFidesWithConsent = (key: string, optInStatus: boolean) => {
} as any as FidesGlobal;
};

const setupFidesWithoutConsent = () => {
window.Fides = {
consent: {},
} as any as FidesGlobal;
};

describe("blueconic", () => {
afterEach(() => {
window.blueConicClient = undefined;
window.Fides = undefined as any;
jest.resetAllMocks();
});

test("that other modes are not supported", () => {
expect(() => blueconic({ approach: "other mode" as "onetrust" })).toThrow();
describe("approaches", () => {
test("that other approaches are not supported", () => {
expect(() =>
blueconic({ approach: "other mode" as "onetrust" }),
).toThrow();
});

describe.each([undefined, "onetrust"] as const)(
"onetrust approach",
(approach) => {
test("when fides configures no consent, blueconic sets consent for all purposes", () => {
const { client, mockProfile } = setupBlueConicClient();
setupFidesWithoutConsent();

blueconic({ approach });

expect(mockProfile.setConsentedObjectives).toHaveBeenCalledWith([
"iab_purpose_1",
"iab_purpose_2",
"iab_purpose_3",
"iab_purpose_4",
]);
expect(mockProfile.setRefusedObjectives).toHaveBeenCalledWith([]);
expect(client.profile.updateProfile).toHaveBeenCalled();
});

describe.each(MARKETING_CONSENT_KEYS)(
"when consent is set via the %s key",
(key) => {
test.each([
[
"opted in",
true,
[
"iab_purpose_1",
"iab_purpose_2",
"iab_purpose_3",
"iab_purpose_4",
],
[],
],
[
"opted out",
false,
["iab_purpose_1"],
["iab_purpose_2", "iab_purpose_3", "iab_purpose_4"],
],
])(
"that a user who has %s gets the correct consented and refused objectives",
(_, optInStatus, consented, refused) => {
const { client, mockProfile } = setupBlueConicClient();
setupFidesWithConsent(key, optInStatus);

blueconic();

expect(mockProfile.setConsentedObjectives).toHaveBeenCalledWith(
consented,
);
expect(mockProfile.setRefusedObjectives).toHaveBeenCalledWith(
refused,
);
expect(client.profile.updateProfile).toHaveBeenCalled();
},
);
},
);
},
);
});

test("that nothing happens when blueconic and fides are not initialized", () => {
Expand All @@ -58,42 +130,6 @@ describe("blueconic", () => {
).not.toHaveBeenCalled();
});

describe.each(MARKETING_CONSENT_KEYS)(
"when consent is set via the %s key",
(key) => {
test.each([
[
"opted in",
true,
["iab_purpose_1", "iab_purpose_2", "iab_purpose_3", "iab_purpose_4"],
[],
],
[
"opted out",
false,
["iab_purpose_1"],
["iab_purpose_2", "iab_purpose_3", "iab_purpose_4"],
],
])(
"that a user who has %s gets the correct consented and refused objectives",
(_, optInStatus, consented, refused) => {
const { client, mockProfile } = setupBlueConicClient();
setupFidesWithConsent(key, optInStatus);

blueconic();

expect(mockProfile.setConsentedObjectives).toHaveBeenCalledWith(
consented,
);
expect(mockProfile.setRefusedObjectives).toHaveBeenCalledWith(
refused,
);
expect(client.profile.updateProfile).toHaveBeenCalled();
},
);
},
);

test.each(["FidesInitialized", "FidesUpdated", "onBlueConicLoaded"])(
"that %s event can cause objectives to be set",
(eventName) => {
Expand Down
9 changes: 7 additions & 2 deletions clients/fides-js/src/integrations/blueconic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ const configureObjectives = () => {
}

const profile = window.blueConicClient?.profile?.getProfile();

const { consent } = window.Fides;
const hasConsentFlags =
consent !== undefined && Object.entries(consent).length > 0;
const optedIn = MARKETING_CONSENT_KEYS.some((key) => consent[key]);
if (optedIn) {
if (!hasConsentFlags || optedIn) {
profile.setConsentedObjectives([
"iab_purpose_1",
"iab_purpose_2",
Expand All @@ -52,7 +55,9 @@ const configureObjectives = () => {
};

export const blueconic = (
{ approach }: { approach: "onetrust" } = { approach: "onetrust" },
{ approach = "onetrust" }: { approach: "onetrust" | undefined } = {
approach: "onetrust",
},
) => {
if (approach !== "onetrust") {
throw new Error("Unsupported approach");
Expand Down

0 comments on commit e90b858

Please sign in to comment.