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 flaky create-link user-defined key 422s

Cursor Agent04692e9e11c5
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index 6956858084..17ac416a33 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -4,7 +4,7 @@ import { Link, Tag } from "@prisma/client";
import { IntegrationHarnessOld } from "tests/utils/integration-old";
import { describe, expect, onTestFinished, test } from "vitest";
import * as z from "zod/v4";
-import { randomId, randomTagName } from "../utils/helpers";
+import { randomId, randomKey, randomTagName } from "../utils/helpers";
import { IntegrationHarness } from "../utils/integration";
import { E2E_LINK, E2E_WEBHOOK_ID } from "../utils/resource";
import { LinkSchema, expectedLink } from "../utils/schema";
@@ -82,7 +82,7 @@ describe.sequential("POST /links", async () => {
});
test("user defined key", async ({ onTestFinished }) => {
- const key = randomId();
+ const key = randomKey();
onTestFinished(async () => {
await h.deleteLink(link.id);
diff --git a/apps/web/tests/links/retrieve-link.test.ts b/apps/web/tests/links/retrieve-link.test.ts
index a717c90dae..a416c783a9 100644
--- a/apps/web/tests/links/retrieve-link.test.ts
+++ b/apps/web/tests/links/retrieve-link.test.ts
@@ -2,7 +2,7 @@ import { normalizeWorkspaceId } from "@/lib/api/workspaces/workspace-id";
import { Link } from "@prisma/client";
import { expectedLink } from "tests/utils/schema";
import { afterAll, describe, expect, test } from "vitest";
-import { randomId } from "../utils/helpers";
+import { randomId, randomKey } from "../utils/helpers";
import { IntegrationHarness } from "../utils/integration";
import { E2E_LINK } from "../utils/resource";
@@ -14,7 +14,7 @@ describe.concurrent("GET /links/{linkId}", async () => {
const workspaceId = workspace.id;
const projectId = normalizeWorkspaceId(workspaceId);
const externalId = randomId();
- const key = randomId();
+ const key = randomKey();
const { data: newLink } = await http.post<Link>({
path: "/links",
@@ -65,7 +65,7 @@ describe.sequential("GET /links/info", async () => {
const workspaceId = workspace.id;
const projectId = normalizeWorkspaceId(workspaceId);
const externalId = randomId();
- const key = randomId();
+ const key = randomKey();
afterAll(async () => {
await h.deleteLink(newLink.id);
diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.ts
index e9b55f2bf3..9be4238694 100644
--- a/apps/web/tests/links/update-link.test.ts
+++ b/apps/web/tests/links/update-link.test.ts
@@ -1,7 +1,7 @@
import { normalizeWorkspaceId } from "@/lib/api/workspaces/workspace-id";
import { Link } from "@prisma/client";
import { afterAll, beforeAll, describe, expect, test } from "vitest";
-import { randomId } from "../utils/helpers";
+import { randomId, randomKey } from "../utils/helpers";
import { IntegrationHarness } from "../utils/integration";
import { E2E_LINK } from "../utils/resource";
import { expectedLink } from "../utils/schema";
@@ -25,7 +25,7 @@ describe.sequential("PATCH /links/{linkId}", async () => {
});
const toUpdate: Partial<Link> = {
- key: randomId(),
+ key: randomKey(),
url: "https://github.com/dubinc/dub",
title: "Dub Inc",
description: "Open-source link management infrastructure.",
@@ -393,7 +393,7 @@ describe.sequential(
});
const toUpdate: Partial<Link> = {
- key: randomId(),
+ key: randomKey(),
url: "https://github.com/dubinc/dub",
title: "Dub Inc",
description: "Open-source link management infrastructure.",
diff --git a/apps/web/tests/partners/upsert-partner-link.test.ts b/apps/web/tests/partners/upsert-partner-link.test.ts
index ebae974f22..a9fdcd41bb 100644
--- a/apps/web/tests/partners/upsert-partner-link.test.ts
+++ b/apps/web/tests/partners/upsert-partner-link.test.ts
@@ -1,6 +1,6 @@
import { nanoid } from "@dub/utils";
import { Link } from "@prisma/client";
-import { randomId } from "tests/utils/helpers";
+import { randomKey } from "tests/utils/helpers";
import { afterAll, describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
import { E2E_PARTNER, E2E_PARTNER_GROUP, E2E_PROGRAM } from "../utils/resource";
@@ -37,7 +37,7 @@ describe.sequential("PUT /partners/links/upsert", async () => {
});
test("Existing link", async () => {
- const key = randomId();
+ const key = randomKey();
const { data: updatedLink, status } = await http.put<Link>({
path: "/partners/links/upsert",
diff --git a/apps/web/tests/utils/helpers.ts b/apps/web/tests/utils/helpers.ts
index 4ea82ad397..b225a535a9 100644
--- a/apps/web/tests/utils/helpers.ts
+++ b/apps/web/tests/utils/helpers.ts
@@ -1,9 +1,15 @@
import { generateRandomName } from "@/lib/names";
import { nanoid, randomValue } from "@dub/utils";
+import { customAlphabet } from "nanoid";
import { expect } from "vitest";
export const randomId = (length = 24) => nanoid(length);
+// Digits-only keys avoid flaky 422s on dub.sh/dub.link from isBlacklistedKey
+// substring matches against alphanumeric nanoids.
+export const randomKey = (length = 24) =>
+ customAlphabet("0123456789", length)();
+
// Generate random customer data
export const randomCustomer = ({
emailDomain = "example.com",