diff --git a/clients/privacy-center/cypress/e2e/consent-banner-tcf.cy.ts b/clients/privacy-center/cypress/e2e/consent-banner-tcf.cy.ts index ef93ac15c4..7db136329f 100644 --- a/clients/privacy-center/cypress/e2e/consent-banner-tcf.cy.ts +++ b/clients/privacy-center/cypress/e2e/consent-banner-tcf.cy.ts @@ -3113,4 +3113,170 @@ describe("Fides-js TCF", () => { }); }); }); + + describe("Automatically set preferences", () => { + beforeEach(() => { + cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); + }); + describe("Reject all", () => { + const validateRejectAll = (interception: any) => { + const { body } = interception.request; + // check a few to see they are empty arrays + expect(body.purpose_consent_preferences).to.eql([]); + expect(body.purpose_legitimate_interests_preferences).to.eql([]); + expect(body.method).to.eql(ConsentMethod.REJECT); + }; + it("rejects all notices automatically when set", () => { + stubTCFExperience({ + stubOptions: { fidesRejectAll: true }, + }); + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateRejectAll(interception); + }); + }); + }); + + it("rejects all notices automatically when set via cookie", () => { + cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); + cy.getCookie("fides_reject_all").should("not.exist"); + cy.setCookie("fides_reject_all", "true"); + stubTCFExperience({}); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateRejectAll(interception); + }); + }); + }); + + it("rejects all notices automatically when set via query param", () => { + cy.getCookie("fides_string").should("not.exist"); + stubTCFExperience({ + demoPageQueryParams: { fides_reject_all: "true" }, + }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateRejectAll(interception); + }); + }); + }); + + it("rejects all notices automatically when set via window obj", () => { + cy.getCookie("fides_string").should("not.exist"); + stubTCFExperience({ + demoPageWindowParams: { fides_reject_all: "true" }, + }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateRejectAll(interception); + }); + }); + }); + }); + + describe("Accept all", () => { + const validateAcceptAll = (interception: any) => { + const { body } = interception.request; + expect(body.purpose_consent_preferences).to.eql([ + { + id: 1, + preference: "opt_in", + }, + { + id: 2, + preference: "opt_in", + }, + { + id: 3, + preference: "opt_in", + }, + { + id: 4, + preference: "opt_in", + }, + { + id: 5, + preference: "opt_in", + }, + { + id: 6, + preference: "opt_in", + }, + { + id: 7, + preference: "opt_in", + }, + { + id: 8, + preference: "opt_in", + }, + { + id: 9, + preference: "opt_in", + }, + { + id: 10, + preference: "opt_in", + }, + { + id: 11, + preference: "opt_in", + }, + ]); + expect(body.method).to.eql(ConsentMethod.ACCEPT); + }; + it("accepts all notices automatically when set", () => { + stubTCFExperience({ + stubOptions: { fidesAcceptAll: true }, + }); + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateAcceptAll(interception); + }); + }); + }); + + it("accepts all notices automatically when set via cookie", () => { + cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); + cy.getCookie("fides_accept_all").should("not.exist"); + cy.setCookie("fides_accept_all", "true"); + stubTCFExperience({}); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateAcceptAll(interception); + }); + }); + }); + + it("accepts all notices automatically when set via query param", () => { + cy.getCookie("fides_string").should("not.exist"); + stubTCFExperience({ + demoPageQueryParams: { fides_accept_all: "true" }, + }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateAcceptAll(interception); + }); + }); + }); + + it("accepts all notices automatically when set via window obj", () => { + cy.getCookie("fides_string").should("not.exist"); + stubTCFExperience({ + demoPageWindowParams: { fides_accept_all: "true" }, + }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + validateAcceptAll(interception); + }); + }); + }); + }); + }); }); diff --git a/clients/privacy-center/cypress/e2e/consent-banner.cy.ts b/clients/privacy-center/cypress/e2e/consent-banner.cy.ts index fcc7bf5a6d..f4179b8c4f 100644 --- a/clients/privacy-center/cypress/e2e/consent-banner.cy.ts +++ b/clients/privacy-center/cypress/e2e/consent-banner.cy.ts @@ -178,6 +178,27 @@ describe("Consent overlay", () => { }); }); + it("should not render the banner if fidesDisableBanner is true", () => { + stubConfig({ + options: { + isOverlayEnabled: true, + fidesDisableBanner: true, + }, + }); + cy.waitUntilFidesInitialized().then(() => { + // The banner has a delay, so in order to assert its non-existence, we have + // to give it a chance to come up first. Otherwise, the following gets will + // pass regardless. + // eslint-disable-next-line cypress/no-unnecessary-waiting + cy.wait(500); + cy.get("@FidesUIShown").should("not.have.been.called"); + cy.get("div#fides-banner").should("not.exist"); + // can still open the modal + cy.get("#fides-modal-link").click(); + cy.getByTestId("consent-modal").should("be.visible"); + }); + }); + describe("modal", () => { it("should open modal when experience component = OVERLAY", () => { cy.contains("button", "Manage preferences").click(); @@ -317,6 +338,107 @@ describe("Consent overlay", () => { }); }); }); + + describe("saving preferences", () => { + it("skips saving preferences to API when disable save is set", () => { + stubConfig({ + options: { + fidesDisableSaveApi: true, + }, + }); + cy.waitUntilFidesInitialized().then(() => { + cy.get("#fides-modal-link").click(); + cy.getByTestId("consent-modal").within(() => { + cy.get("button").contains("Opt out of all").click(); + // timeout means API call not made, which is expected + cy.on("fail", (error) => { + if (error.message.indexOf("Timed out retrying") !== 0) { + throw error; + } + }); + // check that preferences aren't sent to Fides API + cy.wait("@patchPrivacyPreference", { + requestTimeout: 100, + }).then((xhr) => { + assert.isNull(xhr?.response?.body); + }); + }); + }); + }); + + it("skips saving preferences to API when disable save is set via cookie", () => { + cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); + cy.getCookie("fides_disable_save_api").should("not.exist"); + cy.setCookie("fides_disable_save_api", "true"); + stubConfig({}); + cy.waitUntilFidesInitialized().then(() => { + cy.get("#fides-modal-link").click(); + cy.getByTestId("consent-modal").within(() => { + cy.get("button").contains("Opt out of all").click(); + // timeout means API call not made, which is expected + cy.on("fail", (error) => { + if (error.message.indexOf("Timed out retrying") !== 0) { + throw error; + } + }); + // check that preferences aren't sent to Fides API + cy.wait("@patchPrivacyPreference", { + requestTimeout: 100, + }).then((xhr) => { + assert.isNull(xhr?.response?.body); + }); + }); + }); + }); + + it("skips saving preferences to API when disable save is set via query param", () => { + cy.getCookie("fides_string").should("not.exist"); + stubConfig({}, null, null, { fides_disable_save_api: "true" }); + cy.waitUntilFidesInitialized().then(() => { + cy.get("#fides-modal-link").click(); + cy.getByTestId("consent-modal").within(() => { + cy.get("button").contains("Opt out of all").click(); + // timeout means API call not made, which is expected + cy.on("fail", (error) => { + if (error.message.indexOf("Timed out retrying") !== 0) { + throw error; + } + }); + // check that preferences aren't sent to Fides API + cy.wait("@patchPrivacyPreference", { + requestTimeout: 100, + }).then((xhr) => { + assert.isNull(xhr?.response?.body); + }); + }); + }); + }); + + it("skips saving preferences to API when disable save is set via window obj", () => { + cy.getCookie("fides_string").should("not.exist"); + stubConfig({}, null, null, null, { + fides_disable_save_api: "true", + }); + cy.waitUntilFidesInitialized().then(() => { + cy.get("#fides-modal-link").click(); + cy.getByTestId("consent-modal").within(() => { + cy.get("button").contains("Opt out of all").click(); + // timeout means API call not made, which is expected + cy.on("fail", (error) => { + if (error.message.indexOf("Timed out retrying") !== 0) { + throw error; + } + }); + // check that preferences aren't sent to Fides API + cy.wait("@patchPrivacyPreference", { + requestTimeout: 100, + }).then((xhr) => { + assert.isNull(xhr?.response?.body); + }); + }); + }); + }); + }); }); describe("experience descriptions", () => { @@ -1672,6 +1794,256 @@ describe("Consent overlay", () => { cy.get("div#fides-banner").should("be.visible"); }); }); + + describe("Automatically set preferences", () => { + describe("Reject all", () => { + it("rejects all notices automatically when set", () => { + stubConfig({ + options: { + fidesRejectAll: true, + }, + }); + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.REJECT); + }); + }); + }); + + it("rejects all notices automatically when set via cookie", () => { + cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); + cy.getCookie("fides_reject_all").should("not.exist"); + cy.setCookie("fides_reject_all", "true"); + stubConfig({}); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.REJECT); + }); + }); + }); + + it("rejects all notices automatically when set via query param", () => { + cy.getCookie("fides_string").should("not.exist"); + stubConfig({}, null, null, { fides_reject_all: "true" }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.REJECT); + }); + }); + }); + + it("rejects all notices automatically when set via window obj", () => { + cy.getCookie("fides_string").should("not.exist"); + stubConfig({}, null, null, null, { + fides_reject_all: "true", + }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_out", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.REJECT); + }); + }); + }); + }); + + describe("Accept all", () => { + it("accepts all notices automatically when set", () => { + stubConfig({ + options: { + fidesAcceptAll: true, + }, + }); + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.ACCEPT); + }); + }); + }); + + it("accepts all notices automatically when set via cookie", () => { + cy.getCookie(CONSENT_COOKIE_NAME).should("not.exist"); + cy.getCookie("fides_accept_all").should("not.exist"); + cy.setCookie("fides_accept_all", "true"); + stubConfig({}); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.ACCEPT); + }); + }); + }); + + it("accepts all notices automatically when set via query param", () => { + cy.getCookie("fides_string").should("not.exist"); + stubConfig({}, null, null, { fides_accept_all: "true" }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.ACCEPT); + }); + }); + }); + + it("accepts all notices automatically when set via window obj", () => { + cy.getCookie("fides_string").should("not.exist"); + stubConfig({}, null, null, null, { + fides_accept_all: "true", + }); + + cy.waitUntilFidesInitialized().then(() => { + cy.wait("@patchPrivacyPreference").then((interception) => { + const { body } = interception.request; + expect(body.preferences).to.eql([ + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-advertising-en-000", + }, + { + preference: "opt_in", + privacy_notice_history_id: + "pri_notice-history-analytics-en-000", + }, + { + preference: "acknowledge", + privacy_notice_history_id: + "pri_notice-history-essential-en-000", + }, + ]); + expect(body.method).to.eql(ConsentMethod.ACCEPT); + }); + }); + }); + }); + }); }); describe("when listening for fides.js events", () => { diff --git a/clients/privacy-center/cypress/fixtures/consent/experience_tcf_minimal.json b/clients/privacy-center/cypress/fixtures/consent/experience_tcf_minimal.json index 46e75319b3..9e62ca06c6 100644 --- a/clients/privacy-center/cypress/fixtures/consent/experience_tcf_minimal.json +++ b/clients/privacy-center/cypress/fixtures/consent/experience_tcf_minimal.json @@ -89,6 +89,221 @@ "geolocation": { "location": "eea", "country": "eea" + }, + "gvl": { + "gvlSpecificationVersion": 3, + "vendorListVersion": 81, + "tcfPolicyVersion": 5, + "lastUpdated": "2024-11-21T16:07:54Z", + "purposes": { + "1": { + "id": 1, + "name": "", + "description": "", + "illustrations": [] + }, + "2": { + "id": 2, + "name": "", + "description": "", + "illustrations": [] + }, + "3": { + "id": 3, + "name": "", + "description": "", + "illustrations": [] + }, + "4": { + "id": 4, + "name": "", + "description": "", + "illustrations": [] + }, + "5": { + "id": 5, + "name": "", + "description": "", + "illustrations": [] + }, + "6": { + "id": 6, + "name": "", + "description": "", + "illustrations": [] + }, + "7": { + "id": 7, + "name": "", + "description": "", + "illustrations": [] + }, + "8": { + "id": 8, + "name": "", + "description": "", + "illustrations": [] + }, + "9": { + "id": 9, + "name": "", + "description": "", + "illustrations": [] + }, + "10": { + "id": 10, + "name": "", + "description": "", + "illustrations": [] + }, + "11": { + "id": 11, + "name": "", + "description": "", + "illustrations": [] + } + }, + "specialPurposes": { + "1": { + "id": 1, + "name": "", + "description": "", + "illustrations": [] + }, + "2": { + "id": 2, + "name": "", + "description": "", + "illustrations": [] + }, + "3": { + "id": 3, + "name": "", + "description": "", + "illustrations": [] + } + }, + "features": { + "1": { + "id": 1, + "name": "", + "description": "", + "illustrations": [] + }, + "2": { + "id": 2, + "name": "", + "description": "", + "illustrations": [] + }, + "3": { + "id": 3, + "name": "", + "description": "", + "illustrations": [] + } + }, + "specialFeatures": { + "1": { + "id": 1, + "name": "", + "description": "", + "illustrations": [] + }, + "2": { + "id": 2, + "name": "", + "description": "", + "illustrations": [] + } + }, + "stacks": {}, + "dataCategories": { + "1": { + "id": 1, + "name": "", + "description": "" + }, + "2": { + "id": 2, + "name": "", + "description": "" + }, + "3": { + "id": 3, + "name": "", + "description": "" + }, + "4": { + "id": 4, + "name": "", + "description": "" + }, + "5": { + "id": 5, + "name": "", + "description": "" + }, + "6": { + "id": 6, + "name": "", + "description": "" + }, + "7": { + "id": 7, + "name": "", + "description": "" + }, + "8": { + "id": 8, + "name": "", + "description": "" + }, + "9": { + "id": 9, + "name": "", + "description": "" + }, + "10": { + "id": 10, + "name": "", + "description": "" + }, + "11": { + "id": 11, + "name": "", + "description": "" + } + }, + "vendors": { + "755": { + "id": 755, + "name": "", + "purposes": [1, 3, 4], + "legIntPurposes": [2, 7, 9, 10], + "flexiblePurposes": [2, 7, 9, 10], + "specialPurposes": [1, 2, 3], + "features": [1, 2], + "specialFeatures": [], + "cookieMaxAgeSeconds": 34190000, + "usesCookies": true, + "cookieRefresh": false, + "urls": [], + "usesNonCookieAccess": true, + "dataRetention": { + "stdRetention": 548, + "purposes": { + "3": 180, + "4": 180 + }, + "specialPurposes": { + "1": 1096 + } + }, + "dataDeclaration": [1, 2, 3, 5, 6, 7, 8, 10, 11], + "deviceStorageDisclosureUrl": "" + } + } } } ]