Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): give the flag tests a consent answer after the master back-merge (#14854)

Reinier van der Leerdc3aeb32d3bc
diff --git a/autogpt_platform/frontend/src/providers/posthog/__tests__/posthog-user-tracker.test.tsx b/autogpt_platform/frontend/src/providers/posthog/__tests__/posthog-user-tracker.test.tsx
index 920bf95267..2e0eb027c6 100644
--- a/autogpt_platform/frontend/src/providers/posthog/__tests__/posthog-user-tracker.test.tsx
+++ b/autogpt_platform/frontend/src/providers/posthog/__tests__/posthog-user-tracker.test.tsx
@@ -1,5 +1,10 @@
+import {
+ installCookiebot,
+ removeCookiebot,
+ TEST_COOKIEBOT_CBID,
+} from "@/tests/integrations/cookiebot";
import { render } from "@testing-library/react";
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
const posthog = vi.hoisted(() => ({
identify: vi.fn(),
@@ -23,7 +28,10 @@ vi.mock("@/lib/auth/hooks/useAuth", () => ({
}));
vi.mock("@/services/environment", () => ({
- environment: { isPostHogEnabled: () => true },
+ environment: {
+ isPostHogEnabled: () => true,
+ getCookiebotCBID: () => TEST_COOKIEBOT_CBID,
+ },
}));
vi.mock("@/services/feature-flags/flag-backend", () => ({
@@ -34,6 +42,11 @@ describe("PostHogUserTracker", () => {
beforeEach(() => {
posthog.identify.mockClear();
posthog.setPersonPropertiesForFlags.mockClear();
+ installCookiebot({ statistics: true });
+ });
+
+ afterEach(() => {
+ removeCookiebot();
});
it.each([false, true])(
@@ -72,4 +85,16 @@ describe("PostHogUserTracker", () => {
expect(posthog.setPersonPropertiesForFlags).not.toHaveBeenCalled();
});
+
+ it("hands PostHog neither identity nor flag properties without analytics consent", async () => {
+ flags.usesPostHog = true;
+ removeCookiebot();
+ installCookiebot({ statistics: false });
+ const { PostHogUserTracker } = await import("../posthog-provider");
+
+ render(<PostHogUserTracker />);
+
+ expect(posthog.identify).not.toHaveBeenCalled();
+ expect(posthog.setPersonPropertiesForFlags).not.toHaveBeenCalled();
+ });
});
diff --git a/autogpt_platform/frontend/src/services/feature-flags/__tests__/ld-init-timeout.test.tsx b/autogpt_platform/frontend/src/services/feature-flags/__tests__/ld-init-timeout.test.tsx
index bcb4bf9c11..41626fb3a6 100644
--- a/autogpt_platform/frontend/src/services/feature-flags/__tests__/ld-init-timeout.test.tsx
+++ b/autogpt_platform/frontend/src/services/feature-flags/__tests__/ld-init-timeout.test.tsx
@@ -47,6 +47,7 @@ vi.mock("@/services/environment", () => ({
environment: {
areFeatureFlagsEnabled: () => true,
getLaunchDarklyClientId: () => "test-client-id",
+ getCookiebotCBID: () => undefined,
},
}));