mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Lands five integrated branches: pipeline templates (#355), analytics opt-out (#354), 83 conversion presets bringing the catalog to 240 tools (#356), self-hosted positioning (#353), and e2e modernization (#351). Integration fixes: aligned stale web analytics tests with the opt-out/allow-list model, closed 3 CodeQL incomplete-sanitization alerts in the i18n generator, resolved settings/index/docs/format-matrix conflicts, and corrected tool counts to 240.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
// Proves the server-side invariant: trackEvent does not emit to PostHog when
|
|
// analytics is disabled by the runtime gate. Replaces the old source-string and
|
|
// denylist-regex assertions, which no longer match the gated implementation.
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
describe("Server-side analytics gating (behavioral)", () => {
|
|
const origEnv = process.env.NODE_ENV;
|
|
const origOverride = process.env.ANALYTICS_BAKED_OVERRIDE;
|
|
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
process.env.NODE_ENV = "test";
|
|
});
|
|
afterEach(() => {
|
|
process.env.NODE_ENV = origEnv;
|
|
if (origOverride === undefined) delete process.env.ANALYTICS_BAKED_OVERRIDE;
|
|
else process.env.ANALYTICS_BAKED_OVERRIDE = origOverride;
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("trackEvent does not capture when the gate is off", async () => {
|
|
process.env.ANALYTICS_BAKED_OVERRIDE = "off";
|
|
const capture = vi.fn();
|
|
vi.doMock("posthog-node", () => ({
|
|
PostHog: vi.fn(() => ({ capture, shutdown: vi.fn() })),
|
|
}));
|
|
const { trackEvent } = await import("../../../apps/api/src/lib/analytics.js");
|
|
await trackEvent("tool_used", { tool_id: "resize" }, "did-1");
|
|
expect(capture).not.toHaveBeenCalled();
|
|
});
|
|
});
|