Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(web): mock OpenPanel server analytics in billing tests

Richie McIlroya59495608f42
diff --git a/apps/web/__tests__/unit/developer-credits-webhook.test.ts b/apps/web/__tests__/unit/developer-credits-webhook.test.ts
index 51362a9f7..f379b56c8 100644
--- a/apps/web/__tests__/unit/developer-credits-webhook.test.ts
+++ b/apps/web/__tests__/unit/developer-credits-webhook.test.ts
@@ -45,10 +45,7 @@ vi.mock("@cap/database/schema", () => ({
}));
vi.mock("@cap/env", () => ({
- buildEnv: {
- NEXT_PUBLIC_POSTHOG_KEY: "",
- NEXT_PUBLIC_POSTHOG_HOST: "",
- },
+ buildEnv: {},
serverEnv: () => ({
STRIPE_WEBHOOK_SECRET: "whsec_test",
}),
@@ -86,11 +83,8 @@ vi.mock("drizzle-orm", () => ({
eq: vi.fn((a: unknown, b: unknown) => ({ eq: [a, b] })),
}));
-vi.mock("posthog-node", () => ({
- PostHog: vi.fn().mockImplementation(() => ({
- capture: vi.fn(),
- shutdown: vi.fn().mockResolvedValue(undefined),
- })),
+vi.mock("@/lib/server-analytics", () => ({
+ trackServerEvent: vi.fn().mockResolvedValue(undefined),
}));
function makeWebhookRequest(body = "{}") {
diff --git a/apps/web/__tests__/unit/mobile-checkout.test.ts b/apps/web/__tests__/unit/mobile-checkout.test.ts
index dee16ab7e..5eecd2e22 100644
--- a/apps/web/__tests__/unit/mobile-checkout.test.ts
+++ b/apps/web/__tests__/unit/mobile-checkout.test.ts
@@ -7,16 +7,12 @@ import {
} from "@/lib/mobile-checkout";
const checkoutMocks = vi.hoisted(() => ({
- capture: vi.fn(),
create: vi.fn(),
- shutdown: vi.fn(() => Promise.resolve()),
+ track: vi.fn(() => Promise.resolve()),
}));
vi.mock("@cap/env", () => ({
- buildEnv: {
- NEXT_PUBLIC_POSTHOG_HOST: "https://posthog.test",
- NEXT_PUBLIC_POSTHOG_KEY: "test-key",
- },
+ buildEnv: {},
serverEnv: () => ({ WEB_URL: "https://cap.so" }),
}));
@@ -28,11 +24,8 @@ vi.mock("@cap/utils", () => ({
}),
}));
-vi.mock("posthog-node", () => ({
- PostHog: class {
- capture = checkoutMocks.capture;
- shutdown = checkoutMocks.shutdown;
- },
+vi.mock("@/lib/server-analytics", () => ({
+ trackServerEvent: checkoutMocks.track,
}));
const makeGuestCheckoutRequest = (body: Record<string, unknown>) =>