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.

test improvements

Pedro Ladeira5abfecaae638
diff --git a/apps/web/playwright/api/links/links-bulk.spec.ts b/apps/web/playwright/api/links/links-bulk.spec.ts
index 0ce500c7fd..f40e3239c9 100644
--- a/apps/web/playwright/api/links/links-bulk.spec.ts
+++ b/apps/web/playwright/api/links/links-bulk.spec.ts
@@ -1,4 +1,4 @@
-import { nanoid } from "@dub/utils";
+import { nanoid, sleep } from "@dub/utils";
import { expect } from "@playwright/test";
import { apiError } from "../../utils";
import { test, type ApiClient } from "../fixtures";
@@ -25,6 +25,7 @@ function bulkLinkBody(overrides: Record<string, unknown> = {}) {
return {
url: `https://example.com/${nanoid()}`,
domain,
+ key: nanoid(12),
...overrides,
};
}
@@ -33,7 +34,25 @@ async function createBulkLinks(
api: ApiClient,
bodies: Record<string, unknown>[],
) {
- return api.post<(BulkLink | BulkLinkError)[]>("/api/links/bulk", bodies);
+ let response: { status: number; data: unknown } | undefined;
+
+ for (let attempt = 0; attempt < 3; attempt++) {
+ response = await api.post<unknown>("/api/links/bulk", bodies);
+
+ if (response.status !== 429 && response.status < 500) {
+ break;
+ }
+
+ await sleep(1000 * (attempt + 1));
+ }
+
+ expect(response?.status, JSON.stringify(response?.data)).toEqual(200);
+ expect(
+ Array.isArray(response?.data),
+ `Expected bulk create to return an array, got: ${JSON.stringify(response?.data)}`,
+ ).toBe(true);
+
+ return response as { status: number; data: (BulkLink | BulkLinkError)[] };
}
async function deleteLinks(api: ApiClient, ids: (string | undefined)[]) {
diff --git a/apps/web/tests/tracks/track-click.test.ts b/apps/web/tests/tracks/track-click.test.ts
index cd376cd279..110dca595a 100644
--- a/apps/web/tests/tracks/track-click.test.ts
+++ b/apps/web/tests/tracks/track-click.test.ts
@@ -19,7 +19,6 @@ const expectValidClickResponse = ({
partner: expect.objectContaining({
id: expect.any(String),
name: expect.any(String),
- image: expect.any(String),
}),
}),
...(hasDiscount && {
@@ -27,16 +26,13 @@ const expectValidClickResponse = ({
id: expect.any(String),
amount: expect.any(Number),
type: expect.any(String),
- maxDuration: expect.any(Number),
- couponId: expect.any(String),
- couponTestId: expect.any(String),
}),
}),
});
// Check nullish fields separately if partner exists
if (hasPartner && response.data.partner) {
- const { groupId, tenantId } = response.data.partner;
+ const { groupId, tenantId, image } = response.data.partner;
expect(
groupId === null || groupId === undefined || typeof groupId === "string",
).toBe(true);
@@ -45,6 +41,16 @@ const expectValidClickResponse = ({
tenantId === undefined ||
typeof tenantId === "string",
).toBe(true);
+ expect(image === null || typeof image === "string").toBe(true);
+ }
+
+ if (hasDiscount && response.data.discount) {
+ const { maxDuration, couponId, couponTestId } = response.data.discount;
+ expect(maxDuration === null || typeof maxDuration === "number").toBe(true);
+ expect(couponId === null || typeof couponId === "string").toBe(true);
+ expect(couponTestId === null || typeof couponTestId === "string").toBe(
+ true,
+ );
}
};