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.

Fix partner analytics NOT IN + add tests

Steven Tey3b3a57b1abc5
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/export/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/export/route.ts
index 5de4ef4e9a..f4ffff82e7 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/export/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/export/route.ts
@@ -53,14 +53,6 @@ export const GET = withPartnerProfile(
const { linkId, domain, key } = parsedParams;
- if (linkId?.sqlOperator === "NOT IN") {
- throw new DubApiError({
- code: "bad_request",
- message:
- "The 'is not' filter is not supported for partner analytics export.",
- });
- }
-
if (linkId) {
// check to make sure all of the linkId.values are in the links
if (
@@ -71,6 +63,19 @@ export const GET = withPartnerProfile(
message: "One or more links are not found",
});
}
+
+ if (linkId.sqlOperator === "NOT IN") {
+ // if using NOT IN operator, we need to include all links except the ones in the linkId.values
+ const finalIncludedLinkIds = links
+ .filter((link) => !linkId.values.includes(link.id))
+ .map((link) => link.id);
+
+ parsedParams.linkId = {
+ operator: "IS",
+ sqlOperator: "IN",
+ values: finalIncludedLinkIds,
+ };
+ }
} else if (domain && key) {
const link = links.find(
(link) =>
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
index b6bbf9e2b4..d22ba8e813 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
@@ -34,13 +34,6 @@ export const GET = withPartnerProfile(
const { linkId, domain, key } = parsedParams;
- if (linkId?.sqlOperator === "NOT IN") {
- throw new DubApiError({
- code: "bad_request",
- message: "The 'is not' filter is not supported for partner analytics.",
- });
- }
-
if (linkId) {
// check to make sure all of the linkId.values are in the links
if (
@@ -51,6 +44,19 @@ export const GET = withPartnerProfile(
message: "One or more links are not found",
});
}
+
+ if (linkId.sqlOperator === "NOT IN") {
+ // if using NOT IN operator, we need to include all links except the ones in the linkId.values
+ const finalIncludedLinkIds = links
+ .filter((link) => !linkId.values.includes(link.id))
+ .map((link) => link.id);
+
+ parsedParams.linkId = {
+ operator: "IS",
+ sqlOperator: "IN",
+ values: finalIncludedLinkIds,
+ };
+ }
} else if (domain && key) {
const link = links.find(
(link) =>
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/export/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/export/route.ts
index ef97cd6821..958c0f0b74 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/export/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/export/route.ts
@@ -96,14 +96,6 @@ export const GET = withPartnerProfile(
const { linkId, domain, key } = parsedParams;
- if (linkId?.sqlOperator === "NOT IN") {
- throw new DubApiError({
- code: "bad_request",
- message:
- "The 'is not' filter is not supported for partner events export.",
- });
- }
-
if (linkId) {
// check to make sure all of the linkId.values are in the links
if (
@@ -114,6 +106,19 @@ export const GET = withPartnerProfile(
message: "One or more links are not found",
});
}
+
+ if (linkId.sqlOperator === "NOT IN") {
+ // if using NOT IN operator, we need to include all links except the ones in the linkId.values
+ const finalIncludedLinkIds = links
+ .filter((link) => !linkId.values.includes(link.id))
+ .map((link) => link.id);
+
+ parsedParams.linkId = {
+ operator: "IS",
+ sqlOperator: "IN",
+ values: finalIncludedLinkIds,
+ };
+ }
} else if (domain && key) {
const link = links.find(
(link) =>
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
index 416f310446..23ffdcf885 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
@@ -48,13 +48,6 @@ export const GET = withPartnerProfile(
const parsedParams = partnerProfileEventsQuerySchema.parse(searchParams);
const { linkId, domain, key } = parsedParams;
- if (linkId?.sqlOperator === "NOT IN") {
- throw new DubApiError({
- code: "bad_request",
- message: "The 'is not' filter is not supported for partner events.",
- });
- }
-
if (linkId) {
// check to make sure all of the linkId.values are in the links
if (
@@ -65,6 +58,19 @@ export const GET = withPartnerProfile(
message: "One or more links are not found",
});
}
+
+ if (linkId.sqlOperator === "NOT IN") {
+ // if using NOT IN operator, we need to include all links except the ones in the linkId.values
+ const finalIncludedLinkIds = links
+ .filter((link) => !linkId.values.includes(link.id))
+ .map((link) => link.id);
+
+ parsedParams.linkId = {
+ operator: "IS",
+ sqlOperator: "IN",
+ values: finalIncludedLinkIds,
+ };
+ }
} else if (domain && key) {
const link = links.find(
(link) =>
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index b98c46b686..4d5106a844 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -209,8 +209,9 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
domain: true,
key: true,
url: true,
- comments: true,
title: true,
+ comments: true,
+ partnerId: true,
createdAt: true,
},
});
@@ -237,8 +238,9 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
domain: link.domain,
key: punyEncode(link.key),
}),
- comments: link.comments,
title: link.title || null,
+ comments: link.comments,
+ partnerId: link.partnerId,
createdAt: link.createdAt.toISOString(),
...item,
});
diff --git a/apps/web/lib/auth/partner.ts b/apps/web/lib/auth/partner.ts
index 1c011ca2fa..6860351244 100644
--- a/apps/web/lib/auth/partner.ts
+++ b/apps/web/lib/auth/partner.ts
@@ -4,10 +4,15 @@ import { PartnerProps } from "@/lib/types";
import { prisma } from "@dub/prisma";
import { PartnerUser } from "@dub/prisma/client";
import { getSearchParams, PARTNERS_DOMAIN } from "@dub/utils";
+import { waitUntil } from "@vercel/functions";
+import { headers } from "next/headers";
+import { ratelimit } from "../upstash";
import { partnerPlatformSchema } from "../zod/schemas/partners";
+import { hashToken } from "./hash-token";
import { Permission } from "./partner-users/partner-user-permissions";
import { throwIfNoPermission } from "./partner-users/throw-if-no-permission";
import { rateLimitRequest } from "./rate-limit-request";
+import { tokenCache, TokenCacheItem } from "./token-cache";
import { getSession, Session } from "./utils";
interface WithPartnerProfileHandler {
@@ -55,16 +60,120 @@ export const withPartnerProfile = (
{ params: initialParams }: { params: Promise<Record<string, string>> },
) => {
const params = (await initialParams) || {};
+
+ let apiKey: string | undefined;
+ let requestHeaders = await headers();
let responseHeaders = new Headers();
try {
- const session = await getSession();
+ const authorizationHeader = requestHeaders.get("Authorization");
+ if (authorizationHeader) {
+ if (!authorizationHeader.includes("Bearer ")) {
+ throw new DubApiError({
+ code: "bad_request",
+ message:
+ "Misconfigured authorization header. Did you forget to add 'Bearer '? Learn more: https://d.to/auth",
+ });
+ }
+ apiKey = authorizationHeader.replace("Bearer ", "");
+ }
- if (!session?.user?.id) {
- throw new DubApiError({
- code: "unauthorized",
- message: "Unauthorized: Login required.",
+ let session: Session | undefined;
+ let token: TokenCacheItem | null = null;
+
+ if (apiKey) {
+ const hashedKey = await hashToken(apiKey);
+
+ const cachedToken = await tokenCache.get({
+ hashedKey,
});
+
+ if (!cachedToken) {
+ token = await prisma.token.findUnique({
+ where: {
+ hashedKey,
+ },
+ select: {
+ user: {
+ select: {
+ id: true,
+ name: true,
+ email: true,
+ isMachine: true,
+ defaultPartnerId: true,
+ },
+ },
+ },
+ });
+ }
+
+ token = cachedToken || token;
+
+ if (!token || !token.user) {
+ throw new DubApiError({
+ code: "unauthorized",
+ message: "Unauthorized: Invalid API key.",
+ });
+ }
+
+ if (token.expires && token.expires < new Date()) {
+ throw new DubApiError({
+ code: "unauthorized",
+ message: "Unauthorized: Access token expired.",
+ });
+ }
+
+ if (!cachedToken) {
+ waitUntil(
+ tokenCache.set({
+ hashedKey,
+ token,
+ }),
+ );
+ }
+
+ waitUntil(
+ // update last used time for the token (only once every minute)
+ (async () => {
+ try {
+ const { success } = await ratelimit(1, "1 m").limit(
+ `last-used-${hashedKey}`,
+ );
+
+ if (success) {
+ await prisma.token.update({
+ where: {
+ hashedKey,
+ },
+ data: {
+ lastUsed: new Date(),
+ },
+ });
+ }
+ } catch (error) {
+ console.error(error);
+ }
+ })(),
+ );
+
+ session = {
+ user: {
+ id: token.user.id,
+ name: token.user.name || "",
+ email: token.user.email || "",
+ isMachine: token.user.isMachine,
+ defaultPartnerId: token.user.defaultPartnerId || undefined,
+ },
+ };
+ } else {
+ session = await getSession();
+
+ if (!session?.user?.id) {
+ throw new DubApiError({
+ code: "unauthorized",
+ message: "Unauthorized: Login required.",
+ });
+ }
}
const searchParams = getSearchParams(req.url);
diff --git a/apps/web/lib/auth/token-cache.ts b/apps/web/lib/auth/token-cache.ts
index 5c81759b6f..4d8deba1dc 100644
--- a/apps/web/lib/auth/token-cache.ts
+++ b/apps/web/lib/auth/token-cache.ts
@@ -14,6 +14,7 @@ const tokenCacheItemSchema = z.object({
name: z.string().nullable(),
email: z.string().nullable(),
isMachine: z.boolean(),
+ defaultPartnerId: z.string().nullish(),
}),
project: z
.object({
diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.ts
index e1ac279985..a87d0581ad 100644
--- a/apps/web/lib/zod/schemas/analytics-response.ts
+++ b/apps/web/lib/zod/schemas/analytics-response.ts
@@ -270,11 +270,17 @@ export const analyticsResponse = {
key: z.string().describe("The key of the short link"),
shortLink: z.string().describe("The short link URL"),
url: z.string().describe("The destination URL of the short link"),
- comments: z.string().nullish().describe("The comments of the short link"),
title: z
.string()
.nullish()
.describe("The custom link preview title (og:title)"),
+ comments: z.string().nullish().describe("The comments of the short link"),
+ partnerId: z
+ .string()
+ .nullish()
+ .describe(
+ "The ID of the partner that the link belongs to (if applicable)",
+ ),
createdAt: z.string().describe("The creation timestamp of the short link"),
clicks: z
.number()
diff --git a/apps/web/tests/analytics/advanced-filters.test.ts b/apps/web/tests/analytics/advanced-filter-helpers.test.ts
similarity index 100%
rename from apps/web/tests/analytics/advanced-filters.test.ts
rename to apps/web/tests/analytics/advanced-filter-helpers.test.ts
diff --git a/apps/web/tests/analytics/get-analytics-advanced.test.ts b/apps/web/tests/analytics/get-analytics-advanced.test.ts
new file mode 100644
index 0000000000..e4146c5dbe
--- /dev/null
+++ b/apps/web/tests/analytics/get-analytics-advanced.test.ts
@@ -0,0 +1,346 @@
+import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
+import { describe, expect, test } from "vitest";
+import * as z from "zod/v4";
+import { env } from "../utils/env";
+import { IntegrationHarness } from "../utils/integration";
+import {
+ E2E_PARTNER,
+ E2E_PARTNERS,
+ E2E_PARTNER_GROUP,
+} from "../utils/resource";
+
+describe
+ .runIf(env.CI)
+ .sequential("GET /analytics (advanced filters)", async () => {
+ const h = new IntegrationHarness();
+ const { workspace, http } = await h.init();
+ const workspaceId = workspace.id;
+
+ describe("groupBy country / device", () => {
+ test("single country filter", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "countries",
+ workspaceId,
+ interval: "30d",
+ domain: "dub.sh",
+ key: "checkly-check",
+ country: "US",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.countries.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(parsed.data?.every((item) => item.country === "US")).toBe(true);
+ });
+
+ test("multiple countries filter (IS ONE OF)", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "countries",
+ workspaceId,
+ interval: "30d",
+ domain: "dub.sh",
+ key: "checkly-check",
+ country: "US,CA,GB",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.countries.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) =>
+ ["US", "CA", "GB"].includes(item.country),
+ ),
+ ).toBe(true);
+ });
+
+ test("exclude country (IS NOT)", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "countries",
+ workspaceId,
+ interval: "30d",
+ domain: "dub.sh",
+ key: "checkly-check",
+ country: "-US",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.countries.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(parsed.data?.every((item) => item.country !== "US")).toBe(true);
+ });
+
+ test("exclude multiple countries (IS NOT ONE OF)", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "countries",
+ workspaceId,
+ interval: "30d",
+ domain: "dub.sh",
+ key: "checkly-check",
+ country: "-US,GB",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.countries.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => !["US", "GB"].includes(item.country)),
+ ).toBe(true);
+ });
+
+ test("multiple devices filter", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "devices",
+ workspaceId,
+ interval: "30d",
+ domain: "dub.sh",
+ key: "checkly-check",
+ device: "mobile,desktop",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.devices.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) =>
+ ["Mobile", "Desktop"].includes(item.device),
+ ),
+ ).toBe(true);
+ });
+
+ test("backward compatibility - old format still works", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "countries",
+ workspaceId,
+ interval: "30d",
+ domain: "dub.sh",
+ key: "checkly-check",
+ country: "US",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.countries.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(parsed.data?.every((item) => item.country === "US")).toBe(true);
+ });
+ });
+
+ describe("filter by partnerId", () => {
+ test("single partnerId filter (count)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_partners",
+ workspaceId,
+ interval: "all",
+ partnerId: E2E_PARTNER.id,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_partners.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.partner.id === E2E_PARTNER.id),
+ ).toBe(true);
+ });
+
+ test("multiple partnerIds filter (IS ONE OF)", async () => {
+ const partnerIds = E2E_PARTNERS.map((p) => p.id).join(",");
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_partners",
+ workspaceId,
+ interval: "all",
+ partnerId: partnerIds,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_partners.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => partnerIds.includes(item.partner.id)),
+ ).toBe(true);
+ });
+
+ test("exclude partnerId (IS NOT)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_partners",
+ workspaceId,
+ interval: "all",
+ partnerId: `-${E2E_PARTNER.id}`,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_partners.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.partner.id !== E2E_PARTNER.id),
+ ).toBe(true);
+ });
+
+ test("exclude multiple partnerIds (IS NOT ONE OF)", async () => {
+ const partnerIds = E2E_PARTNERS.map((p) => p.id).join(",");
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_partners",
+ workspaceId,
+ interval: "all",
+ partnerId: `-${partnerIds}`,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_partners.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every(
+ (item: any) => !partnerIds.includes(item.partner.id),
+ ),
+ ).toBe(true);
+ });
+
+ test("backward compatibility - single partnerId still works", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_partners",
+ workspaceId,
+ interval: "all",
+ partnerId: E2E_PARTNER.id,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_partners.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.partner.id === E2E_PARTNER.id),
+ ).toBe(true);
+ });
+ });
+
+ describe("filter by groupId", () => {
+ test("single groupId filter (count)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_groups",
+ workspaceId,
+ interval: "all",
+ groupId: E2E_PARTNER_GROUP.id,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_groups.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.group.id === E2E_PARTNER_GROUP.id),
+ ).toBe(true);
+ });
+
+ test("exclude groupId (IS NOT)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_groups",
+ workspaceId,
+ interval: "all",
+ groupId: `-${E2E_PARTNER_GROUP.id}`,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_groups.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.group.id !== E2E_PARTNER_GROUP.id),
+ ).toBe(true);
+ });
+
+ test("backward compatibility - single groupId still works", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/analytics`,
+ query: {
+ event: "clicks",
+ groupBy: "top_groups",
+ workspaceId,
+ interval: "all",
+ groupId: E2E_PARTNER_GROUP.id,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_groups.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.group.id === E2E_PARTNER_GROUP.id),
+ ).toBe(true);
+ });
+ });
+ });
diff --git a/apps/web/tests/analytics/get-analytics.test.ts b/apps/web/tests/analytics/get-analytics.test.ts
new file mode 100644
index 0000000000..13f17a0e80
--- /dev/null
+++ b/apps/web/tests/analytics/get-analytics.test.ts
@@ -0,0 +1,61 @@
+import { VALID_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
+import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
+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", 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,
+ interval: "30d",
+ ...(groupBy !== "top_partners"
+ ? {
+ domain: "dub.sh",
+ key: "checkly-check",
+ }
+ : {}),
+ },
+ });
+
+ 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();
+ });
+ });
+
+ test("filter events by metadata.productId", async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/events`,
+ query: {
+ event: "sales",
+ workspaceId,
+ interval: "30d",
+ query: "metadata['productId']:premiumProductId",
+ },
+ });
+
+ expect(status).toEqual(200);
+
+ // check to make sure all events have metadata.productId equal to premiumProductId
+ expect(
+ data.every((event) => event.metadata?.productId === "premiumProductId"),
+ ).toBe(true);
+ });
+});
diff --git a/apps/web/tests/analytics/get-events.test.ts b/apps/web/tests/analytics/get-events.test.ts
index 393ab7f8ff..c586ff688b 100644
--- a/apps/web/tests/analytics/get-events.test.ts
+++ b/apps/web/tests/analytics/get-events.test.ts
@@ -112,9 +112,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
// expect all events to have country US, CA, or GB
parsed.data?.forEach((event) => {
@@ -135,9 +134,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
// expect all events to not have country US
parsed.data?.forEach((event) => {
@@ -156,9 +154,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(saleEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(saleEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
// expect all events to have metadata.productId equal to premiumProductId
parsed.data?.forEach((event) => {
@@ -177,9 +174,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(leadEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(leadEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
parsed.data?.forEach((event) => {
// expect all events to have partnerId equal to E2E_PARTNER.id
@@ -201,9 +197,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(leadEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(leadEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
// expect all events to have partnerId equal to E2E_PARTNER.id
parsed.data?.forEach((event) => {
@@ -223,9 +218,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
parsed.data?.forEach((event) => {
expect(partnerIds).not.toContain(event.link.partnerId);
@@ -244,9 +238,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
parsed.data?.forEach((event) => {
expect(event.click.country).toBe("US");
@@ -265,9 +258,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
parsed.data?.forEach((event) => {
expect(event.link.tenantId).toBe(E2E_PARTNER.tenantId);
@@ -285,9 +277,8 @@ describe.runIf(env.CI).sequential("GET /events", async () => {
},
});
- const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
-
expect(status).toEqual(200);
+ const parsed = z.array(clickEventResponseSchema.strict()).safeParse(data);
expect(parsed.success).toBeTruthy();
parsed.data?.forEach((event) => {
expect(event.link.tenantId).not.toBe(E2E_PARTNER.tenantId);
diff --git a/apps/web/tests/analytics/index.test.ts b/apps/web/tests/analytics/index.test.ts
deleted file mode 100644
index 765b834029..0000000000
--- a/apps/web/tests/analytics/index.test.ts
+++ /dev/null
@@ -1,535 +0,0 @@
-import { VALID_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
-import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
-import { describe, expect, test } from "vitest";
-import * as z from "zod/v4";
-import { env } from "../utils/env";
-import { IntegrationHarness } from "../utils/integration";
-import {
- E2E_PARTNER,
- E2E_PARTNERS,
- E2E_PARTNER_GROUP,
-} from "../utils/resource";
-
-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,
- interval: "30d",
- ...(groupBy !== "top_partners"
- ? {
- domain: "dub.sh",
- key: "checkly-check",
- }
- : {}),
- },
- });
-
- 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();
- });
- });
-
- test("filter events by metadata.productId", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/events`,
- query: {
- event: "sales",
- workspaceId,
- interval: "30d",
- query: "metadata['productId']:premiumProductId",
- },
- });
-
- expect(status).toEqual(200);
-
- // check to make sure all events have metadata.productId equal to premiumProductId
- expect(
- data.every((event) => event.metadata?.productId === "premiumProductId"),
- ).toBe(true);
- });
-
- describe("Advanced Filters", () => {
- test("single country filter", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "US",
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- });
-
- test("multiple countries filter (IS ONE OF)", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "countries",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "US,CA,GB",
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
-
- // All returned countries should be in the filter
- data.forEach((item: any) => {
- expect(["US", "CA", "GB"]).toContain(item.country);
- });
- });
-
- test("exclude country (IS NOT)", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "countries",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "-US",
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
-
- // No country should be US
- data.forEach((item: any) => {
- expect(item.country).not.toBe("US");
- });
- });
-
- test("exclude multiple countries (IS NOT ONE OF)", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "countries",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "-US,GB",
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
-
- // No country should be US or GB
- data.forEach((item: any) => {
- expect(["US", "GB"]).not.toContain(item.country);
- });
- });
-
- test("multiple devices filter", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "devices",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- device: "mobile,desktop",
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
-
- // All returned devices should be in the filter
- data.forEach((item: any) => {
- expect(["Mobile", "Desktop"]).toContain(item.device);
- });
- });
-
- test("country AND device filters combined", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "US",
- device: "desktop",
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- // Should return clicks that are both from US AND desktop
- });
-
- test("timeseries with country filter", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "timeseries",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "US",
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
- // Timeseries should only include US data
- });
-
- test("backward compatibility - old format still works", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "30d",
- domain: "dub.sh",
- key: "checkly-check",
- country: "US",
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- // Old single-value format should still work
- });
- });
-
- describe("partnerId Filters", () => {
- test("single partnerId filter (count)", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- partnerId: E2E_PARTNER.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("multiple partnerIds filter (IS ONE OF)", async () => {
- const partnerIds = E2E_PARTNERS.map((p) => p.id).join(",");
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- partnerId: partnerIds,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("exclude partnerId (IS NOT)", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- partnerId: `-${E2E_PARTNER.id}`,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("exclude multiple partnerIds (IS NOT ONE OF)", async () => {
- const partnerIds = E2E_PARTNERS.map((p) => p.id).join(",");
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- partnerId: `-${partnerIds}`,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("partnerId with timeseries groupBy", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "timeseries",
- workspaceId,
- interval: "30d",
- partnerId: E2E_PARTNER.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
- });
-
- test("partnerId with top_links groupBy", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "top_links",
- workspaceId,
- interval: "all",
- partnerId: E2E_PARTNER.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
- });
-
- test("partnerId combined with country filter", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "all",
- partnerId: E2E_PARTNER.id,
- country: "US",
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- });
-
- test("backward compatibility - single partnerId still works", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "all",
- partnerId: E2E_PARTNER.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- });
- });
-
- describe("groupId Filters", () => {
- test("single groupId filter (count)", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- groupId: E2E_PARTNER_GROUP.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("exclude groupId (IS NOT)", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- groupId: `-${E2E_PARTNER_GROUP.id}`,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("groupId with timeseries groupBy", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "timeseries",
- workspaceId,
- interval: "30d",
- groupId: E2E_PARTNER_GROUP.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
- });
-
- test("groupId combined with partnerId filter", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "all",
- groupId: E2E_PARTNER_GROUP.id,
- partnerId: E2E_PARTNER.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- });
-
- test("backward compatibility - single groupId still works", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "all",
- groupId: E2E_PARTNER_GROUP.id,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- });
- });
-
- describe("tenantId Filters", () => {
- test("single tenantId filter (count)", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- tenantId: E2E_PARTNER.tenantId,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("exclude tenantId (IS NOT)", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "composite",
- groupBy: "count",
- workspaceId,
- interval: "all",
- tenantId: `-${E2E_PARTNER.tenantId}`,
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- expect(data).toHaveProperty("leads");
- expect(data).toHaveProperty("sales");
- });
-
- test("tenantId with timeseries groupBy", async () => {
- const { status, data } = await http.get<any[]>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "timeseries",
- workspaceId,
- interval: "30d",
- tenantId: E2E_PARTNER.tenantId,
- },
- });
-
- expect(status).toEqual(200);
- expect(Array.isArray(data)).toBe(true);
- });
-
- test("tenantId combined with country filter", async () => {
- const { status, data } = await http.get<any>({
- path: `/analytics`,
- query: {
- event: "clicks",
- groupBy: "count",
- workspaceId,
- interval: "all",
- tenantId: E2E_PARTNER.tenantId,
- country: "US",
- },
- });
-
- expect(status).toEqual(200);
- expect(data).toHaveProperty("clicks");
- });
- });
-});
diff --git a/apps/web/tests/analytics/partner-analytics.test.ts b/apps/web/tests/analytics/partner-analytics.test.ts
new file mode 100644
index 0000000000..f10e72c038
--- /dev/null
+++ b/apps/web/tests/analytics/partner-analytics.test.ts
@@ -0,0 +1,99 @@
+import { analyticsResponse } from "@/lib/zod/schemas/analytics-response";
+import { IntegrationHarnessOld } from "tests/utils/integration-old";
+import { describe, expect, test } from "vitest";
+import * as z from "zod/v4";
+import { env } from "../utils/env";
+import { E2E_PARTNER, E2E_PROGRAM } from "../utils/resource";
+
+describe
+ .runIf(env.CI)
+ .sequential(
+ "GET /partner-profile/programs/[programId]/analytics",
+ async () => {
+ const h = new IntegrationHarnessOld();
+ const { http } = await h.init();
+
+ test("get top links for partner", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/partner-profile/programs/${E2E_PROGRAM.id}/analytics`,
+ query: {
+ groupBy: "top_links",
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_links.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.partnerId === E2E_PARTNER.id),
+ ).toBe(true);
+ });
+
+ test("get top links for partner (filtered by linkId)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/partner-profile/programs/${E2E_PROGRAM.id}/analytics`,
+ query: {
+ groupBy: "top_links",
+ linkId: E2E_PARTNER.link.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.partnerId === E2E_PARTNER.id),
+ ).toBe(true);
+ expect(
+ parsed.data?.every((item) => item.id === E2E_PARTNER.link.id),
+ ).toBe(true);
+ });
+
+ test("get top links for partner (filtered by domain and key)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/partner-profile/programs/${E2E_PROGRAM.id}/analytics`,
+ query: {
+ groupBy: "top_links",
+ domain: E2E_PARTNER.link.domain,
+ key: E2E_PARTNER.link.key,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_links.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ expect(
+ parsed.data?.every((item) => item.partnerId === E2E_PARTNER.id),
+ ).toBe(true);
+ expect(
+ parsed.data?.every((item) => item.id === E2E_PARTNER.link.id),
+ ).toBe(true);
+ });
+
+ test("get top links for partner (negative filter by linkId)", async () => {
+ const { status, data } = await http.get<any>({
+ path: `/partner-profile/programs/${E2E_PROGRAM.id}/analytics`,
+ query: {
+ groupBy: "top_links",
+ linkId: `-${E2E_PARTNER.link.id}`,
+ },
+ });
+
+ expect(status).toEqual(200);
+ const parsed = z
+ .array(analyticsResponse.top_links.strict())
+ .safeParse(data);
+ expect(parsed.success).toBeTruthy();
+ // need to make sure all returned links still belong to the partner
+ expect(
+ parsed.data?.every((item) => item.partnerId === E2E_PARTNER.id),
+ ).toBe(true);
+ });
+ },
+ );
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index 42e8dcf72e..81e9bde245 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -584,6 +584,7 @@ describe.sequential("POST /links?workspaceId=xxx", async () => {
const { status, data: link } = await http.post<Link>({
path: "/links",
+ query: { workspaceId },
body: {
url,
domain,
diff --git a/apps/web/tests/utils/integration-old.ts b/apps/web/tests/utils/integration-old.ts
index b7af69d205..c999ef4c03 100644
--- a/apps/web/tests/utils/integration-old.ts
+++ b/apps/web/tests/utils/integration-old.ts
@@ -3,7 +3,7 @@ import { type TestContext } from "vitest";
import * as z from "zod/v4";
import { env, integrationTestEnv } from "./env";
import { HttpClient } from "./http";
-import { E2E_USER_ID, E2E_WORKSPACE_ID } from "./resource";
+import { E2E_USER_ID_MEMBER, E2E_WORKSPACE_ID } from "./resource";
interface Resources {
user: Pick<User, "id">;
@@ -25,14 +25,14 @@ export class IntegrationHarnessOld {
this.http = new HttpClient({
baseUrl: `${this.baseUrl}/api`,
headers: {
- Authorization: `Bearer ${this.env.E2E_TOKEN}`,
+ Authorization: `Bearer ${this.env.E2E_TOKEN_OLD}`,
},
});
}
async init() {
const user = {
- id: E2E_USER_ID,
+ id: E2E_USER_ID_MEMBER,
};
const apiKey = {
diff --git a/apps/web/tests/utils/integration.ts b/apps/web/tests/utils/integration.ts
index a4141cea25..0e86585bcf 100644
--- a/apps/web/tests/utils/integration.ts
+++ b/apps/web/tests/utils/integration.ts
@@ -1,12 +1,13 @@
-import { Project, User } from "@dub/prisma/client";
+import { Partner, Project, User } from "@dub/prisma/client";
import { type TestContext } from "vitest";
import * as z from "zod/v4";
import { HttpClient } from "../utils/http";
import { env, integrationTestEnv } from "./env";
-import { E2E_USER_ID, E2E_WORKSPACE_ID } from "./resource";
+import { E2E_PARTNER, E2E_USER_ID, E2E_WORKSPACE_ID } from "./resource";
interface Resources {
user: Pick<User, "id">;
+ partner: Pick<Partner, "id">;
workspace: Pick<Project, "id" | "slug" | "name" | "webhookEnabled">;
apiKey: { token: string };
}
@@ -35,8 +36,8 @@ export class IntegrationHarness {
id: E2E_USER_ID,
};
- const apiKey = {
- token: this.env.E2E_TOKEN,
+ const partner = {
+ id: E2E_PARTNER.id,
};
const workspace = {
@@ -46,10 +47,15 @@ export class IntegrationHarness {
webhookEnabled: true,
};
+ const apiKey = {
+ token: this.env.E2E_TOKEN,
+ };
+
this.resources = {
user,
- apiKey,
+ partner,
workspace,
+ apiKey,
};
return {
diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts
index 4b553e0b70..97a412bd20 100644
--- a/apps/web/tests/utils/resource.ts
+++ b/apps/web/tests/utils/resource.ts
@@ -1,5 +1,5 @@
export const E2E_USER_ID = "clxz1q7c7000hbqx5ckv4r82h";
-export const E2E_USER_ID_MEMBER = "user_1KAERYAJ10MDM56EB9XPX4ZZ8"; // for member user tests
+export const E2E_USER_ID_MEMBER = "user_1KAERYAJ10MDM56EB9XPX4ZZ8"; // for member user tests + old personal token tests
export const E2E_WORKSPACE_ID = "ws_clrei1gld0002vs9mzn93p8ik";
export const E2E_LINK = {
@@ -175,8 +175,13 @@ export const E2E_PROGRAM = {
export const E2E_PARTNER = {
id: "pn_H4TB2V5hDIjpqB7PwrxESoY3",
- email: "[email protected]",
+ email: "[email protected]",
tenantId: "4149092f-7265-4002-98d9-da9f8e67e1fb",
+ link: {
+ id: "cm0lcuvtz000xcutmqw4a7wi3",
+ domain: "dub.sh",
+ key: "track-test",
+ },
};
export const E2E_PARTNER_GROUP = {