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 some tests

Kiran Kc98a5b8616c7
diff --git a/apps/web/lib/analytics/leads.ts b/apps/web/lib/analytics/leads.ts
index 615e1a143a..cba6ff712d 100644
--- a/apps/web/lib/analytics/leads.ts
+++ b/apps/web/lib/analytics/leads.ts
@@ -73,8 +73,8 @@ export const getLeads = async (
const response = await pipe({
...props,
workspaceId,
- start: start.toISOString().split(".")[0],
- end: end.toISOString().split(".")[0],
+ start: start.toISOString().replace("T", " ").replace("Z", ""),
+ end: end.toISOString().replace("T", " ").replace("Z", ""),
granularity,
});
diff --git a/apps/web/lib/analytics/sales.ts b/apps/web/lib/analytics/sales.ts
index 70d1fbc37e..0d67ccb97c 100644
--- a/apps/web/lib/analytics/sales.ts
+++ b/apps/web/lib/analytics/sales.ts
@@ -73,8 +73,8 @@ export const getSales = async (
const response = await pipe({
...props,
workspaceId,
- start: start.toISOString().split(".")[0],
- end: end.toISOString().split(".")[0],
+ start: start.toISOString().replace("T", " ").replace("Z", ""),
+ end: end.toISOString().replace("T", " ").replace("Z", ""),
granularity,
});
diff --git a/apps/web/lib/zod/schemas/sales-analytics.ts b/apps/web/lib/zod/schemas/sales-analytics.ts
index 3824278182..e0fcdaabbf 100644
--- a/apps/web/lib/zod/schemas/sales-analytics.ts
+++ b/apps/web/lib/zod/schemas/sales-analytics.ts
@@ -9,6 +9,7 @@ export const saleAnalyticsResponse = {
timeseries: z.object({
start: z.string().describe("The starting timestamp of the interval"),
sales: z.number().describe("The number of sales in the interval"),
+ amount: z.number().describe("The total amount of sales in the interval"),
}),
countries: z
diff --git a/apps/web/tests/analytics/clicks.test.ts b/apps/web/tests/analytics/clicks.test.ts
index 0f5e6f27eb..d4266db3ac 100644
--- a/apps/web/tests/analytics/clicks.test.ts
+++ b/apps/web/tests/analytics/clicks.test.ts
@@ -4,7 +4,7 @@ import {
} from "@/lib/analytics/constants";
import { formatAnalyticsEndpoint } from "@/lib/analytics/utils";
import z from "@/lib/zod";
-import { getClickAnalyticsResponse } from "@/lib/zod/schemas/click-analytics";
+import { getClickAnalyticsResponse } from "@/lib/zod/schemas/clicks-analytics";
import { describe, expect, test } from "vitest";
import { env } from "../utils/env";
import { IntegrationHarness } from "../utils/integration";
diff --git a/apps/web/tests/analytics/leads.test.ts b/apps/web/tests/analytics/leads.test.ts
new file mode 100644
index 0000000000..b2389dd120
--- /dev/null
+++ b/apps/web/tests/analytics/leads.test.ts
@@ -0,0 +1,43 @@
+import {
+ DEPRECATED_ANALYTICS_ENDPOINTS,
+ VALID_ANALYTICS_ENDPOINTS,
+} from "@/lib/analytics/constants";
+import { formatAnalyticsEndpoint } from "@/lib/analytics/utils";
+import z from "@/lib/zod";
+import { leadAnalyticsResponse } from "@/lib/zod/schemas/leads-analytics";
+import { describe, expect, test } from "vitest";
+import { IntegrationHarness } from "../utils/integration";
+import { filter } from "./utils";
+
+describe.skip.sequential("GET /analytics/leads", async () => {
+ const h = new IntegrationHarness();
+ const { workspace, http } = await h.init();
+ const { workspaceId } = workspace;
+
+ VALID_ANALYTICS_ENDPOINTS.filter(
+ (endpoint) => !DEPRECATED_ANALYTICS_ENDPOINTS.includes(endpoint),
+ ).map((endpoint) => {
+ test(`by ${endpoint}`, async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics/leads/${endpoint}`,
+ query: { workspaceId, ...filter },
+ });
+
+ if (endpoint === "count") {
+ expect(status).toEqual(200);
+ expect(data).toEqual(expect.any(Number));
+ expect(data).toBeGreaterThanOrEqual(0);
+ return;
+ }
+
+ const schema = formatAnalyticsEndpoint(endpoint, "plural");
+ const parsed = z
+ .array(leadAnalyticsResponse[schema].strict())
+ .safeParse(data);
+
+ expect(status).toEqual(200);
+ expect(data.length).toBeGreaterThanOrEqual(0);
+ expect(parsed.success).toBeTruthy();
+ });
+ });
+});
diff --git a/apps/web/tests/analytics/sales.test.ts b/apps/web/tests/analytics/sales.test.ts
new file mode 100644
index 0000000000..282dae6e5c
--- /dev/null
+++ b/apps/web/tests/analytics/sales.test.ts
@@ -0,0 +1,43 @@
+import {
+ DEPRECATED_ANALYTICS_ENDPOINTS,
+ VALID_ANALYTICS_ENDPOINTS,
+} from "@/lib/analytics/constants";
+import { formatAnalyticsEndpoint } from "@/lib/analytics/utils";
+import z from "@/lib/zod";
+import { saleAnalyticsResponse } from "@/lib/zod/schemas/sales-analytics";
+import { describe, expect, test } from "vitest";
+import { IntegrationHarness } from "../utils/integration";
+import { filter } from "./utils";
+
+describe.skip.sequential("GET /analytics/sales", async () => {
+ const h = new IntegrationHarness();
+ const { workspace, http } = await h.init();
+ const { workspaceId } = workspace;
+
+ VALID_ANALYTICS_ENDPOINTS.filter(
+ (endpoint) => !DEPRECATED_ANALYTICS_ENDPOINTS.includes(endpoint),
+ ).map((endpoint) => {
+ test(`by ${endpoint}`, async () => {
+ const { status, data } = await http.get<any[]>({
+ path: `/analytics/sales/${endpoint}`,
+ query: { workspaceId, ...filter },
+ });
+
+ if (endpoint === "count") {
+ expect(status).toEqual(200);
+ expect(data).toEqual(expect.any(Number));
+ expect(data).toBeGreaterThanOrEqual(0);
+ return;
+ }
+
+ const schema = formatAnalyticsEndpoint(endpoint, "plural");
+ const parsed = z
+ .array(saleAnalyticsResponse[schema].strict())
+ .safeParse(data);
+
+ expect(status).toEqual(200);
+ expect(data.length).toBeGreaterThanOrEqual(0);
+ expect(parsed.success).toBeTruthy();
+ });
+ });
+});
diff --git a/packages/tinybird/datasources/dub_lead_events.datasource b/packages/tinybird/datasources/dub_lead_events.datasource
index 4e3006e869..97ec93bf67 100644
--- a/packages/tinybird/datasources/dub_lead_events.datasource
+++ b/packages/tinybird/datasources/dub_lead_events.datasource
@@ -1,5 +1,5 @@
SCHEMA >
- `timestamp` DateTime `json:$.timestamp` DEFAULT now(),
+ `timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
`event_id` String `json:$.event_id`,
`event_name` LowCardinality(String) `json:$.event_name`,
`metadata` String `json:$.metadata`,
diff --git a/packages/tinybird/datasources/dub_lead_events_mv.datasource b/packages/tinybird/datasources/dub_lead_events_mv.datasource
index d75e5d77e1..f4e2bb84ae 100644
--- a/packages/tinybird/datasources/dub_lead_events_mv.datasource
+++ b/packages/tinybird/datasources/dub_lead_events_mv.datasource
@@ -1,5 +1,5 @@
SCHEMA >
- `timestamp` DateTime,
+ `timestamp` DateTime64(3),
`event_id` String,
`click_id` String,
`link_id` String,
diff --git a/packages/tinybird/datasources/dub_sale_events.datasource b/packages/tinybird/datasources/dub_sale_events.datasource
index a8ee5da315..9da7cc56e8 100644
--- a/packages/tinybird/datasources/dub_sale_events.datasource
+++ b/packages/tinybird/datasources/dub_sale_events.datasource
@@ -1,5 +1,5 @@
SCHEMA >
- `timestamp` DateTime `json:$.timestamp` DEFAULT now(),
+ `timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
`event_id` String `json:$.event_id`,
`customer_id` String `json:$.customer_id`,
`payment_processor` LowCardinality(String) `json:$.payment_processor`,
diff --git a/packages/tinybird/datasources/dub_sale_events_mv.datasource b/packages/tinybird/datasources/dub_sale_events_mv.datasource
index 4f5c2fc7fa..57bc40a33f 100644
--- a/packages/tinybird/datasources/dub_sale_events_mv.datasource
+++ b/packages/tinybird/datasources/dub_sale_events_mv.datasource
@@ -1,5 +1,5 @@
SCHEMA >
- `timestamp` DateTime,
+ `timestamp` DateTime64(3),
`event_id` String,
`click_id` String,
`link_id` String,
diff --git a/packages/tinybird/endpoints/leads_timeseries.pipe b/packages/tinybird/endpoints/leads_timeseries.pipe
index ef6bddc5a1..af61eef685 100644
--- a/packages/tinybird/endpoints/leads_timeseries.pipe
+++ b/packages/tinybird/endpoints/leads_timeseries.pipe
@@ -108,8 +108,8 @@ SQL >
{% if defined(os) %} AND os = {{ os }} {% end %}
{% if defined(referer) %} AND referer = {{ referer }} {% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
- AND timestamp >= {{ DateTime(start, '2023-06-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2023-10-20 00:00:00') }}
+ AND timestamp >= {{ DateTime64(start, '2023-06-25 00:00:00.000') }}
+ AND timestamp < {{ DateTime64(end, '2023-10-20 00:00:00.000') }}
GROUP BY interval
ORDER BY interval
diff --git a/packages/tinybird/endpoints/sales_timeseries.pipe b/packages/tinybird/endpoints/sales_timeseries.pipe
index c6fc8e6c19..24b55a0897 100644
--- a/packages/tinybird/endpoints/sales_timeseries.pipe
+++ b/packages/tinybird/endpoints/sales_timeseries.pipe
@@ -108,8 +108,8 @@ SQL >
{% if defined(os) %} AND os = {{ os }} {% end %}
{% if defined(referer) %} AND referer = {{ referer }} {% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
- AND timestamp >= {{ DateTime(start, '2023-06-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2023-10-20 00:00:00') }}
+ AND timestamp >= {{ DateTime64(start, '2023-06-25 00:00:00.000') }}
+ AND timestamp < {{ DateTime64(end, '2023-10-20 00:00:00.000') }}
GROUP BY interval
ORDER BY interval