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

Test File Consolidation and Naming Standardization #5865

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { CmpApi } from "@iabgpp/cmpapi";

import {
decodeFidesString,
formatFidesStringWithGpp,
idsFromAcString,
} from "../../../src/lib/fidesString";
} from "../../src/lib/fides-string";

describe("fidesString", () => {
beforeAll(() => {
window.Fides = {
options: { tcfEnabled: false },
fides_string: undefined,
} as any;
window.fidesDebugger = () => {};
// eslint-disable-next-line no-underscore-dangle
window.__gpp = () => {};
});

beforeEach(() => {
window.Fides.options.tcfEnabled = false;
window.Fides.fides_string = undefined;
});

describe("decodeFidesString", () => {
it.each([
// Empty string
Expand Down Expand Up @@ -131,4 +146,61 @@ describe("fidesString", () => {
},
);
});

describe("formatFidesStringWithGpp", () => {
describe("in a non-TCF experience", () => {
beforeEach(() => {
window.Fides.options.tcfEnabled = false;
});

it("formats GPP string with empty TC and AC parts", () => {
const cmpApi = new CmpApi(1, 1);
// Mock the GPP string
jest
.spyOn(cmpApi, "getGppString")
.mockReturnValue("DBABLA~BVAUAAAAAWA.QA");

const result = formatFidesStringWithGpp(cmpApi);
expect(result).toBe(",,DBABLA~BVAUAAAAAWA.QA");
});
});

describe("in a TCF experience", () => {
beforeEach(() => {
window.Fides.options.tcfEnabled = true;
});

it("appends GPP string to existing TC and AC strings", () => {
const cmpApi = new CmpApi(1, 1);
window.Fides.fides_string = "CPzvOIA.IAAA,1~2.3.4";
jest
.spyOn(cmpApi, "getGppString")
.mockReturnValue("DBABLA~BVAUAAAAAWA.QA");

const result = formatFidesStringWithGpp(cmpApi);
expect(result).toBe("CPzvOIA.IAAA,1~2.3.4,DBABLA~BVAUAAAAAWA.QA");
});

it("appends GPP string to TC string when AC string is empty", () => {
const cmpApi = new CmpApi(1, 1);
window.Fides.fides_string = "CPzvOIA.IAAA,";
jest
.spyOn(cmpApi, "getGppString")
.mockReturnValue("DBABLA~BVAUAAAAAWA.QA");

const result = formatFidesStringWithGpp(cmpApi);
expect(result).toBe("CPzvOIA.IAAA,,DBABLA~BVAUAAAAAWA.QA");
});

it("appends GPP string when no existing fides_string", () => {
const cmpApi = new CmpApi(1, 1);
jest
.spyOn(cmpApi, "getGppString")
.mockReturnValue("DBABLA~BVAUAAAAAWA.QA");

const result = formatFidesStringWithGpp(cmpApi);
expect(result).toBe(",,DBABLA~BVAUAAAAAWA.QA");
});
});
});
});
75 changes: 0 additions & 75 deletions clients/fides-js/__tests__/lib/fidesString.test.ts

This file was deleted.

2 changes: 2 additions & 0 deletions clients/fides-js/__tests__/lib/gpp/decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getGppField,
hasGppSection,
} from "../../../src/lib/gpp/decoder";
import { makeStub } from "../../../src/lib/gpp/stub";
import mockDecodedTCFJSON from "../../__fixtures__/mock_decoded_tcf.json";

// Mock fidesDebugger
Expand All @@ -11,6 +12,7 @@ import mockDecodedTCFJSON from "../../__fixtures__/mock_decoded_tcf.json";
describe("GPP Decoder", () => {
describe("decodeGppString", () => {
it("should decode a US National GPP string", () => {
makeStub();
const gppString = "DBABLA~BVAoAAAAAABk.QA";
const decoded = decodeGppString(gppString);
expect(decoded).toHaveLength(1);
Expand Down
2 changes: 1 addition & 1 deletion clients/fides-js/src/fides-ext-gpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
shouldResurfaceConsent,
} from "./lib/consent-utils";
import { saveFidesCookie } from "./lib/cookie";
import { formatFidesStringWithGpp } from "./lib/fidesString";
import { formatFidesStringWithGpp } from "./lib/fides-string";
import {
CMP_VERSION,
FIDES_US_REGION_TO_GPP_SECTION,
Expand Down
2 changes: 1 addition & 1 deletion clients/fides-js/src/fides-tcf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from "./lib/consent-types";
import { initializeDebugger } from "./lib/debugger";
import { dispatchFidesEvent, onFidesEvent } from "./lib/events";
import { DecodedFidesString, decodeFidesString } from "./lib/fidesString";
import { DecodedFidesString, decodeFidesString } from "./lib/fides-string";
import type { GppFunction } from "./lib/gpp/types";
import { DEFAULT_LOCALE, DEFAULT_MODAL_LINK_LABEL } from "./lib/i18n";
import {
Expand Down
2 changes: 1 addition & 1 deletion clients/fides-js/src/lib/gpp/string-to-consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
constructFidesRegionString,
createConsentPreferencesToSave,
} from "../consent-utils";
import { DecodedFidesString, decodeFidesString } from "../fidesString";
import { DecodedFidesString, decodeFidesString } from "../fides-string";
import { areLocalesEqual } from "../i18n/i18n-utils";
import { updateConsentPreferences } from "../preferences";
import { EMPTY_ENABLED_IDS } from "../tcf/constants";
Expand Down
2 changes: 1 addition & 1 deletion clients/fides-js/src/lib/tcf/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
DecodedFidesString,
decodeFidesString,
idsFromAcString,
} from "../fidesString";
} from "../fides-string";
import {
transformConsentToFidesUserPreference,
transformUserPreferenceToBoolean,
Expand Down