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 metadata.productId filter test

Steven Teyc9ee2b9f0e25
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index 1d34e46cf1..ba41488cfe 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -212,13 +212,16 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
},
});
- return topPartnersData.map((item) => {
- const partner = partners.find((p) => p.id === item.partnerId);
- return {
- ...item,
- partner,
- };
- });
+ return topPartnersData
+ .map((item) => {
+ const partner = partners.find((p) => p.id === item.partnerId);
+ if (!partner) return null;
+ return {
+ ...item,
+ partner,
+ };
+ })
+ .filter((d) => d !== null);
}
// Return array for other endpoints
diff --git a/apps/web/tests/analytics/index.test.ts b/apps/web/tests/analytics/index.test.ts
index f32f0ca79d..4a2e3f01ae 100644
--- a/apps/web/tests/analytics/index.test.ts
+++ b/apps/web/tests/analytics/index.test.ts
@@ -39,4 +39,23 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
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/misc/analytics-query-parser.test.ts b/apps/web/tests/analytics/query-parser.test.ts
similarity index 100%
rename from apps/web/tests/misc/analytics-query-parser.test.ts
rename to apps/web/tests/analytics/query-parser.test.ts