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 tests for folder public analytics

Steven Tey14d1dd5d8fdc
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index aea0a82b8f..624b381e40 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -210,6 +210,7 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
url: true,
title: true,
comments: true,
+ folderId: true,
partnerId: true,
createdAt: true,
},
@@ -228,18 +229,13 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
});
return analyticsResponse[groupBy].parse({
- id: link.id,
+ ...link,
link: link.id,
- domain: link.domain,
key: punyEncode(link.key),
- url: link.url,
shortLink: linkConstructor({
domain: link.domain,
key: punyEncode(link.key),
}),
- title: link.title || null,
- comments: link.comments,
- partnerId: link.partnerId,
createdAt: link.createdAt.toISOString(),
...item,
});
diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.ts
index a87d0581ad..455315f9ad 100644
--- a/apps/web/lib/zod/schemas/analytics-response.ts
+++ b/apps/web/lib/zod/schemas/analytics-response.ts
@@ -275,6 +275,12 @@ export const analyticsResponse = {
.nullish()
.describe("The custom link preview title (og:title)"),
comments: z.string().nullish().describe("The comments of the short link"),
+ folderId: z
+ .string()
+ .nullish()
+ .describe(
+ "The ID of the folder that the link belongs to (if applicable)",
+ ),
partnerId: z
.string()
.nullish()
diff --git a/apps/web/tests/analytics/get-analytics-advanced.test.ts b/apps/web/tests/analytics/get-analytics-advanced.test.ts
index 791bbc3b3c..ce08e32dd2 100644
--- a/apps/web/tests/analytics/get-analytics-advanced.test.ts
+++ b/apps/web/tests/analytics/get-analytics-advanced.test.ts
@@ -19,7 +19,7 @@ describe
describe("groupBy country / device", () => {
test("single country filter", async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "countries",
@@ -41,7 +41,7 @@ describe
test("multiple countries filter (IS ONE OF)", async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "countries",
@@ -67,7 +67,7 @@ describe
test("exclude country (IS NOT)", async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "countries",
@@ -89,7 +89,7 @@ describe
test("exclude multiple countries (IS NOT ONE OF)", async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "countries",
@@ -113,7 +113,7 @@ describe
test("multiple devices filter", async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "devices",
@@ -139,7 +139,7 @@ describe
test("backward compatibility - old format still works", async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "countries",
@@ -163,7 +163,7 @@ describe
describe("filter by partnerId", () => {
test("single partnerId filter (count)", async () => {
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_partners",
@@ -186,7 +186,7 @@ describe
test("multiple partnerIds filter (IS ONE OF)", async () => {
const partnerIds = E2E_PARTNERS.map((p) => p.id);
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_partners",
@@ -210,7 +210,7 @@ describe
test("exclude partnerId (IS NOT)", async () => {
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_partners",
@@ -233,7 +233,7 @@ describe
test("exclude multiple partnerIds (IS NOT ONE OF)", async () => {
const partnerIds = E2E_PARTNERS.map((p) => p.id);
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_partners",
@@ -257,7 +257,7 @@ describe
test("backward compatibility - single partnerId still works", async () => {
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_partners",
@@ -281,7 +281,7 @@ describe
describe("filter by groupId", () => {
test("single groupId filter (count)", async () => {
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_groups",
@@ -303,7 +303,7 @@ describe
test("exclude groupId (IS NOT)", async () => {
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_groups",
@@ -325,7 +325,7 @@ describe
test("backward compatibility - single groupId still works", async () => {
const { status, data } = await http.get<any>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "clicks",
groupBy: "top_groups",
diff --git a/apps/web/tests/analytics/get-analytics.test.ts b/apps/web/tests/analytics/get-analytics.test.ts
index 13f17a0e80..5febad631b 100644
--- a/apps/web/tests/analytics/get-analytics.test.ts
+++ b/apps/web/tests/analytics/get-analytics.test.ts
@@ -13,7 +13,7 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
VALID_ANALYTICS_ENDPOINTS.map((groupBy) => {
test(`by ${groupBy}`, async () => {
const { status, data } = await http.get<any[]>({
- path: `/analytics`,
+ path: "/analytics",
query: {
event: "composite",
groupBy,
@@ -42,7 +42,7 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
test("filter events by metadata.productId", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "sales",
workspaceId,
diff --git a/apps/web/tests/analytics/get-events.test.ts b/apps/web/tests/analytics/get-events.test.ts
index c586ff688b..07cba0776b 100644
--- a/apps/web/tests/analytics/get-events.test.ts
+++ b/apps/web/tests/analytics/get-events.test.ts
@@ -27,7 +27,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("get click events", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -45,7 +45,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("get lead events", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "leads",
workspaceId,
@@ -61,7 +61,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("get sale events", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "sales",
workspaceId,
@@ -78,7 +78,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
describe("Advanced Filters", () => {
test("filter events by country", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -101,7 +101,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("filter events by multiple countries (IS ONE OF)", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -123,7 +123,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("exclude country (IS NOT)", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -145,7 +145,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("filter events by metadata query", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "sales",
workspaceId,
@@ -165,7 +165,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("filter events by single partnerId", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "leads",
workspaceId,
@@ -188,7 +188,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("filter events by multiple partnerIds (IS ONE OF)", async () => {
const partnerIds = E2E_PARTNERS.map((p) => p.id);
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "leads",
workspaceId,
@@ -209,7 +209,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("exclude events by partnerId (IS NOT)", async () => {
const partnerIds = E2E_PARTNERS.map((p) => p.id);
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -228,7 +228,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("filter events by partnerId combined with country", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -249,7 +249,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("filter events by single tenantId", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
@@ -268,7 +268,7 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
test("exclude events by tenantId (IS NOT)", async () => {
const { status, data } = await http.get<any[]>({
- path: `/events`,
+ path: "/events",
query: {
event: "clicks",
workspaceId,
diff --git a/apps/web/tests/analytics/public-analytics-dashboard.test.ts b/apps/web/tests/analytics/public-analytics-dashboard.test.ts
new file mode 100644
index 0000000000..4f67485e8a
--- /dev/null
+++ b/apps/web/tests/analytics/public-analytics-dashboard.test.ts
@@ -0,0 +1,33 @@
+import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
+import { E2E_PUBLIC_ANALYTICS_FOLDER_ID } from "tests/utils/resource";
+import { describe, expect, test } from "vitest";
+import * as z from "zod/v4";
+import { env } from "../utils/env";
+import { IntegrationHarness } from "../utils/integration";
+
+describe.runIf(env.CI).sequential("GET /analytics/dashboard", async () => {
+ const h = new IntegrationHarness();
+ const { http } = await h.init();
+
+ test("public analytics dashboard (folder)", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: "/analytics/dashboard",
+ query: {
+ event: "clicks",
+ groupBy: "top_links",
+ folderId: E2E_PUBLIC_ANALYTICS_FOLDER_ID,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_links.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every(
+ (item) => item.folderId === E2E_PUBLIC_ANALYTICS_FOLDER_ID,
+ ),
+ ).toBe(true);
+ });
+});
diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts
index 97a412bd20..417aa68e31 100644
--- a/apps/web/tests/utils/resource.ts
+++ b/apps/web/tests/utils/resource.ts
@@ -34,6 +34,7 @@ export const E2E_READ_ONLY_FOLDER_ID = "fold_1JP8FN462884CA6JJCVPAHAD4"; // Fold
export const E2E_NO_ACCESS_FOLDER_ID = "fold_1JRZXGNNYWDA5QTT8CVDB3M23"; // Folder with no access
export const E2E_READ_ONLY_FOLDER_LINK_ID = "link_1KAESR5Z733716RTT4E1RSTW6"; // A link in read-only folder
export const E2E_NO_ACCESS_FOLDER_LINK_ID = "link_1KAESQ2Z6Q35WDV5NGSEVPFB0"; // A link in no access folder
+export const E2E_PUBLIC_ANALYTICS_FOLDER_ID = "fold_1JP8FXWM7PECSA4SA7FMGHDWE"; // Folder with public analytics dashboard
// Different customer external IDs for different reward conditions
export const E2E_CUSTOMER_ID = "cm25onzuv0001s1bbxchrc0ae";