Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add analytics tests

Steven Teya95c974f2f81
diff --git a/apps/web/tests/analytics/index.test.ts b/apps/web/tests/analytics/index.test.ts
new file mode 100644
index 0000000000..bd41c2100b
--- /dev/null
+++ b/apps/web/tests/analytics/index.test.ts
@@ -0,0 +1,36 @@
+import { VALID_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
+import z from "@/lib/zod";
+import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
+import { describe, expect, test } from "vitest";
+import { env } from "../utils/env";
+import { IntegrationHarness } from "../utils/integration";
+
+const filter = {
+ domain: "dub.sh",
+ key: "checkly-check",
+ interval: "30d",
+};
+describe.runIf(env.CI).sequential("GET /analytics", async () => {
+ const h = new IntegrationHarness();
+ const { workspace, http } = await h.init();
+ const workspaceId = workspace.id;
+
+ VALID_ANALYTICS_ENDPOINTS.map((groupBy) => {
+ test(`by ${groupBy}`, async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: { event: "composite", groupBy, workspaceId, ...filter },
+ });
+
+ const responseSchema =
+ groupBy === "count"
+ ? analyticsResponse[groupBy].strict()
+ : z.array(analyticsResponse[groupBy].strict());
+
+ const parsed = responseSchema.safeParse(data);
+
+ expect(status).toEqual(200);
+ expect(parsed.success).toBeTruthy();
+ });
+ });
+});
diff --git a/apps/web/tests/analytics/index.ts b/apps/web/tests/analytics/index.ts
deleted file mode 100644
index 8d477a38d5..0000000000
--- a/apps/web/tests/analytics/index.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { VALID_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
-import z from "@/lib/zod";
-import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
-import { describe, expect, test } from "vitest";
-import { env } from "../utils/env";
-import { IntegrationHarness } from "../utils/integration";
-
-const filter = {
- domain: "dub.sh",
- key: "checkly-check",
- interval: "30d",
-};
-describe
- .runIf(env.CI)
- .sequential("GET /analytics?event=composite", async () => {
- const h = new IntegrationHarness();
- const { workspace, http } = await h.init();
- const workspaceId = workspace.id;
-
- VALID_ANALYTICS_ENDPOINTS.map((groupBy) => {
- test(`by ${groupBy}`, async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: { event: "composite", groupBy, workspaceId, ...filter },
- });
-
- const responseSchema =
- groupBy === "count"
- ? analyticsResponse[groupBy].strict()
- : z.array(analyticsResponse[groupBy].strict());
-
- const parsed = responseSchema.safeParse(data);
-
- expect(status).toEqual(200);
- expect(parsed.success).toBeTruthy();
- });
- });
- });