The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update e2e for analytics endpoints
Kiran Kb15bfa59df78
diff --git a/apps/web/tests/analytics/clicks.test.ts b/apps/web/tests/analytics/clicks.test.tsindex 710e3a7517..0beaa189f2 100644--- a/apps/web/tests/analytics/clicks.test.ts+++ b/apps/web/tests/analytics/clicks.test.ts@@ -1,19 +1,158 @@-import { expect, test } from "vitest";+import z from "@/lib/zod";+import { getClickAnalyticsResponse } from "@/lib/zod/schemas";+import { describe, expect, test } from "vitest";import { env } from "../utils/env";import { IntegrationHarness } from "../utils/integration";import { filter } from "./utils";-test.runIf(env.CI)("GET /analytics/clicks", async (ctx) => {- const h = new IntegrationHarness(ctx);+describe.runIf(env.CI).sequential("GET /analytics/clicks", async () => {+ const h = new IntegrationHarness();const { workspace, http } = await h.init();const { workspaceId } = workspace;- const { status, data: clicks } = await http.get<number>({- path: "/analytics/clicks",- query: { workspaceId, ...filter },+ test("clicks count", async () => {+ const { status, data: clicks } = await http.get<number>({+ path: "/analytics/clicks",+ query: { workspaceId, ...filter },+ });++ expect(status).toEqual(200);+ expect(clicks).toEqual(expect.any(Number));+ expect(clicks).toBeGreaterThanOrEqual(0);+ });++ test("by timeseries", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "timeseries", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["timeseries"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by country", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "country", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["country"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by city", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "city", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["city"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by device", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "device", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["device"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by browser", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "browser", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["browser"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by os", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "os", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["os"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by referer", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "referer", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["referer"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();});- expect(status).toEqual(200);- expect(clicks).toEqual(expect.any(Number));- expect(clicks).toBeGreaterThanOrEqual(0);+ test("by top_links", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "top_links", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["top_links"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });++ test("by top_urls", async () => {+ const { status, data } = await http.get<any[]>({+ path: "/analytics/clicks",+ query: { workspaceId, groupBy: "top_urls", ...filter },+ });++ const parsed = z+ .array(getClickAnalyticsResponse["top_urls"].strict())+ .safeParse(data);++ expect(status).toEqual(200);+ expect(data.length).toBeGreaterThanOrEqual(0);+ expect(parsed.success).toBeTruthy();+ });});diff --git a/apps/web/tests/analytics/browser.test.ts b/apps/web/tests/analytics/deprecated/browser.test.tssimilarity index 65%rename from apps/web/tests/analytics/browser.test.tsrename to apps/web/tests/analytics/deprecated/browser.test.tsindex 18d87e845c..b9f237da84 100644--- a/apps/web/tests/analytics/browser.test.ts+++ b/apps/web/tests/analytics/deprecated/browser.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/browser", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/browser", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["browser"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["browser"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/city.test.ts b/apps/web/tests/analytics/deprecated/city.test.tssimilarity index 65%rename from apps/web/tests/analytics/city.test.tsrename to apps/web/tests/analytics/deprecated/city.test.tsindex 0c45311d01..e60250aaa4 100644--- a/apps/web/tests/analytics/city.test.ts+++ b/apps/web/tests/analytics/deprecated/city.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/city", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/city", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["city"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["city"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/country.test.ts b/apps/web/tests/analytics/deprecated/country.test.tssimilarity index 65%rename from apps/web/tests/analytics/country.test.tsrename to apps/web/tests/analytics/deprecated/country.test.tsindex 9d892f8e4a..60db5694e5 100644--- a/apps/web/tests/analytics/country.test.ts+++ b/apps/web/tests/analytics/deprecated/country.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/country", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/country", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["country"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["country"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/device.test.ts b/apps/web/tests/analytics/deprecated/device.test.tssimilarity index 65%rename from apps/web/tests/analytics/device.test.tsrename to apps/web/tests/analytics/deprecated/device.test.tsindex e03cde76fa..8ae7778283 100644--- a/apps/web/tests/analytics/device.test.ts+++ b/apps/web/tests/analytics/deprecated/device.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/device", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/device", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["device"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["device"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/os.test.ts b/apps/web/tests/analytics/deprecated/os.test.tssimilarity index 65%rename from apps/web/tests/analytics/os.test.tsrename to apps/web/tests/analytics/deprecated/os.test.tsindex 1a3b4bfa6f..938fd0e098 100644--- a/apps/web/tests/analytics/os.test.ts+++ b/apps/web/tests/analytics/deprecated/os.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/os", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/os", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["os"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["os"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/referer.test.ts b/apps/web/tests/analytics/deprecated/referer.test.tssimilarity index 65%rename from apps/web/tests/analytics/referer.test.tsrename to apps/web/tests/analytics/deprecated/referer.test.tsindex 003fbf0524..017d2dafb5 100644--- a/apps/web/tests/analytics/referer.test.ts+++ b/apps/web/tests/analytics/deprecated/referer.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/referer", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/referer", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["referer"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["referer"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/timeseries.test.ts b/apps/web/tests/analytics/deprecated/timeseries.test.tssimilarity index 65%rename from apps/web/tests/analytics/timeseries.test.tsrename to apps/web/tests/analytics/deprecated/timeseries.test.tsindex e5f1b127d7..5596ecbcf5 100644--- a/apps/web/tests/analytics/timeseries.test.ts+++ b/apps/web/tests/analytics/deprecated/timeseries.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/timeseries", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/timeseries", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["timeseries"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["timeseries"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/top-links.test.ts b/apps/web/tests/analytics/deprecated/top-links.test.tssimilarity index 65%rename from apps/web/tests/analytics/top-links.test.tsrename to apps/web/tests/analytics/deprecated/top-links.test.tsindex 44165b97f3..f3fb1cc0a4 100644--- a/apps/web/tests/analytics/top-links.test.ts+++ b/apps/web/tests/analytics/deprecated/top-links.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/top_links", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/top_links", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["top_links"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["top_links"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});diff --git a/apps/web/tests/analytics/top-urls.test.ts b/apps/web/tests/analytics/deprecated/top-urls.test.tssimilarity index 65%rename from apps/web/tests/analytics/top-urls.test.tsrename to apps/web/tests/analytics/deprecated/top-urls.test.tsindex 1fb5485d66..cf0ed7cd5d 100644--- a/apps/web/tests/analytics/top-urls.test.ts+++ b/apps/web/tests/analytics/deprecated/top-urls.test.ts@@ -1,9 +1,9 @@import z from "@/lib/zod";import { getClickAnalyticsResponse } from "@/lib/zod/schemas";import { expect, test } from "vitest";-import { env } from "../utils/env";-import { IntegrationHarness } from "../utils/integration";-import { filter } from "./utils";+import { env } from "../../utils/env";+import { IntegrationHarness } from "../../utils/integration";+import { filter } from "../utils";test.runIf(env.CI)("GET /analytics/top_urls", async (ctx) => {const h = new IntegrationHarness(ctx);@@ -15,9 +15,11 @@ test.runIf(env.CI)("GET /analytics/top_urls", async (ctx) => {query: { workspaceId, ...filter },});+ const parsed = z+ .array(getClickAnalyticsResponse["top_urls"].strict())+ .safeParse(data);+expect(status).toEqual(200);expect(data.length).toBeGreaterThanOrEqual(0);- expect(- z.array(getClickAnalyticsResponse["top_urls"].strict()).safeParse(data),- ).toBeTruthy();+ expect(parsed.success).toBeTruthy();});