Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
eastandwestwind committed Dec 5, 2023
1 parent 60b1c7b commit 297a33c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
51 changes: 36 additions & 15 deletions clients/fides-js/__tests__/lib/consent-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {getWindowObjFromPath, isPrivacyExperience} from "../../src/lib/consent-utils";
import {
getWindowObjFromPath,
isPrivacyExperience,
} from "../../src/lib/consent-utils";

const MOCK_EXPERIENCE = {
id: "132345243",
Expand Down Expand Up @@ -115,22 +118,40 @@ describe("getWindowObjFromPath", () => {
});
const windowMock1 = {
fides_overrides: {
hello: "something"
}
}
hello: "something",
},
};
const windowMock2 = {
overrides: {
fides: {
hello: "something-else"
}
}
}
hello: "something-else",
},
},
};
it.each([
{ label: "path does not exist", path: ["window","nonexistent-path"], window: windowMock1, expected: undefined },
{ label: "path is one level deep", path: ["window","fides_overrides"], window: windowMock1, expected: {hello: "something"} },
{ label: "path is two levels deep", path: ["window","overrides","fides"], window: windowMock2, expected: {hello: "something-else"} },
])("returns $expected when path is $path and window is $window", ({ path, window, expected }) => {
windowSpy.mockImplementation(() => (window));
expect(getWindowObjFromPath(path as any)).toStrictEqual(expected);
});
{
label: "path does not exist",
path: ["window", "nonexistent-path"],
window: windowMock1,
expected: undefined,
},
{
label: "path is one level deep",
path: ["window", "fides_overrides"],
window: windowMock1,
expected: { hello: "something" },
},
{
label: "path is two levels deep",
path: ["window", "overrides", "fides"],
window: windowMock2,
expected: { hello: "something-else" },
},
])(
"returns $expected when path is $path and window is $window",
({ path, window, expected }) => {
windowSpy.mockImplementation(() => window);
expect(getWindowObjFromPath(path as any)).toStrictEqual(expected);
}
);
});
7 changes: 5 additions & 2 deletions clients/fides-js/src/lib/consent-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
ConsentMechanism,
EmptyExperience,
FidesOptions,
GpcStatus, OverrideOptions,
GpcStatus,
OverrideOptions,
PrivacyExperience,
PrivacyNotice,
UserConsentPreference,
Expand Down Expand Up @@ -258,7 +259,9 @@ export const shouldResurfaceConsent = (
/**
* Get fides override options from a custom path
*/
export const getWindowObjFromPath = (path: string[]): OverrideOptions | undefined => {
export const getWindowObjFromPath = (
path: string[]
): OverrideOptions | undefined => {
if (path[0] === "window") {
path.shift();
}
Expand Down

0 comments on commit 297a33c

Please sign in to comment.