mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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(-)
75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { buildTestApp, type TestApp } from "../test-server.js";
|
|
|
|
let testApp: TestApp;
|
|
|
|
beforeAll(async () => {
|
|
testApp = await buildTestApp();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await testApp.cleanup();
|
|
});
|
|
|
|
describe("GET /api/v1/config/analytics", () => {
|
|
it("returns 200 without auth (public endpoint)", async () => {
|
|
const res = await testApp.app.inject({
|
|
method: "GET",
|
|
url: "/api/v1/config/analytics",
|
|
});
|
|
expect(res.statusCode).toBe(200);
|
|
});
|
|
|
|
it("returns correct AnalyticsConfig shape", async () => {
|
|
const res = await testApp.app.inject({
|
|
method: "GET",
|
|
url: "/api/v1/config/analytics",
|
|
});
|
|
const config = JSON.parse(res.body);
|
|
|
|
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");
|
|
});
|
|
|
|
it("instanceId is consistent across requests", async () => {
|
|
const res1 = await testApp.app.inject({ method: "GET", url: "/api/v1/config/analytics" });
|
|
const res2 = await testApp.app.inject({ method: "GET", url: "/api/v1/config/analytics" });
|
|
const c1 = JSON.parse(res1.body);
|
|
const c2 = JSON.parse(res2.body);
|
|
expect(c1.instanceId).toBe(c2.instanceId);
|
|
});
|
|
|
|
it("config values come from build-time bake (dev defaults to disabled)", async () => {
|
|
const res = await testApp.app.inject({ method: "GET", url: "/api/v1/config/analytics" });
|
|
const config = JSON.parse(res.body);
|
|
// In dev/test the committed baked.ts has enabled: false
|
|
expect(config.enabled).toBe(false);
|
|
expect(config.posthogApiKey).toBe("");
|
|
expect(config.posthogHost).toBe("");
|
|
expect(config.sentryDsn).toBe("");
|
|
expect(config.sampleRate).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe("PUT /api/v1/user/analytics (removed)", () => {
|
|
it("returns 404 (endpoint no longer exists)", async () => {
|
|
const res = await testApp.app.inject({
|
|
method: "PUT",
|
|
url: "/api/v1/user/analytics",
|
|
payload: { enabled: true },
|
|
});
|
|
expect(res.statusCode).toBe(404);
|
|
});
|
|
});
|