Files
SnapOtter/tests/e2e-docker/analytics-api.spec.ts
T
SnapOtterandGitHub 5d36ac06d8 feat(analytics): build-time bake + telemetry depth (#336)
Bake PostHog + Sentry into the published Docker image (SNAPOTTER_ANALYTICS
build arg, codegen script). Delete entire consent system. Move event emission
to BullMQ worker. Add cross-tier identity stitching, Sentry performance
tracing on both tiers, frontend funnel events. Fix stateful regex bug.

86 files changed, 1593 insertions(+), 3747 deletions(-)
2026-06-24 11:05:39 +08:00

56 lines
2.0 KiB
TypeScript

import { expect, test } from "@playwright/test";
// Tests for the analytics config endpoint.
// These run against the Docker container at localhost:1349.
const BASE_URL = "http://localhost:1349";
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
test.describe("GET /api/v1/config/analytics (public)", () => {
test("returns 200 without auth token", async () => {
const res = await fetch(`${BASE_URL}/api/v1/config/analytics`);
expect(res.status).toBe(200);
});
test("response has correct analytics config shape", async () => {
const res = await fetch(`${BASE_URL}/api/v1/config/analytics`);
const config = await res.json();
expect(config).toHaveProperty("enabled");
expect(config).toHaveProperty("posthogApiKey");
expect(config).toHaveProperty("posthogHost");
expect(config).toHaveProperty("sentryDsn");
expect(config).toHaveProperty("sampleRate");
expect(config).toHaveProperty("instanceId");
expect(typeof config.enabled).toBe("boolean");
expect(typeof config.posthogApiKey).toBe("string");
expect(typeof config.posthogHost).toBe("string");
expect(typeof config.sentryDsn).toBe("string");
expect(typeof config.sampleRate).toBe("number");
expect(typeof config.instanceId).toBe("string");
});
test("instanceId is a valid UUID when analytics enabled", async () => {
const res = await fetch(`${BASE_URL}/api/v1/config/analytics`);
const config = await res.json();
if (config.enabled) {
expect(config.instanceId).toMatch(UUID_REGEX);
} else {
// When disabled, instanceId is empty string
expect(config.instanceId).toBe("");
}
});
test("instanceId is consistent across multiple fetches", async () => {
const res1 = await fetch(`${BASE_URL}/api/v1/config/analytics`);
const config1 = await res1.json();
const res2 = await fetch(`${BASE_URL}/api/v1/config/analytics`);
const config2 = await res2.json();
expect(config1.instanceId).toBe(config2.instanceId);
});
});