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.

Clear tenantId on empty string and move clear tests to update-link

Kiran Kee1007116e8a
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index bfa5b0344d..f79ac5bc0e 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -346,9 +346,10 @@ export const createLinkBodySchema = z.object({
tenantId: z
.string()
.max(255)
+ .transform((v) => (v === "" ? null : v))
.nullish()
.describe(
- "The ID of the tenant that created the link inside your system. If set, it can be used to fetch all links for a tenant.",
+ "The ID of the tenant that created the link inside your system. If set, it can be used to fetch all links for a tenant. Pass `null` or an empty string to remove it.",
),
programId: z
.string()
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index f7db30dd7a..6956858084 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -81,66 +81,6 @@ describe.sequential("POST /links", async () => {
expect(LinkSchema.strict().parse(link)).toBeTruthy();
});
- test("clear externalId with empty string", async ({ onTestFinished }) => {
- const externalId = randomId();
-
- const { data: link } = await http.post<Link>({
- path: "/links",
- body: {
- url,
- domain,
- externalId,
- },
- });
-
- onTestFinished(async () => {
- await h.deleteLink(link.id);
- });
-
- expect(link.externalId).toEqual(externalId);
-
- const { status, data: updated } = await http.patch<Link>({
- path: `/links/${link.id}`,
- body: { externalId: "" },
- });
-
- expect(status).toEqual(200);
- expect(updated.externalId).toEqual(null);
-
- const { data: fetched } = await http.get<Link>({
- path: `/links/${link.id}`,
- });
-
- expect(fetched.externalId).toEqual(null);
- });
-
- test("clear externalId with null", async ({ onTestFinished }) => {
- const externalId = randomId();
-
- const { data: link } = await http.post<Link>({
- path: "/links",
- body: {
- url,
- domain,
- externalId,
- },
- });
-
- onTestFinished(async () => {
- await h.deleteLink(link.id);
- });
-
- expect(link.externalId).toEqual(externalId);
-
- const { status, data: updated } = await http.patch<Link>({
- path: `/links/${link.id}`,
- body: { externalId: null },
- });
-
- expect(status).toEqual(200);
- expect(updated.externalId).toEqual(null);
- });
-
test("user defined key", async ({ onTestFinished }) => {
const key = randomId();
diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.ts
index 3dd59b1e7f..e9b55f2bf3 100644
--- a/apps/web/tests/links/update-link.test.ts
+++ b/apps/web/tests/links/update-link.test.ts
@@ -285,6 +285,95 @@ describe.sequential("PATCH /links/{linkId} - UTM parameters", async () => {
});
});
+describe.sequential(
+ "PATCH /links/{linkId} - clear externalId and tenantId",
+ async () => {
+ const h = new IntegrationHarness();
+ const { http } = await h.init();
+
+ let link: Link;
+
+ beforeAll(async () => {
+ const { data } = await http.post<Link>({
+ path: "/links",
+ body: {
+ url,
+ domain,
+ externalId: randomId(),
+ tenantId: randomId(),
+ },
+ });
+ link = data;
+ });
+
+ afterAll(async () => {
+ await h.deleteLink(link.id);
+ });
+
+ test("clear externalId with empty string", async () => {
+ const { status, data: updated } = await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body: { externalId: "" },
+ });
+
+ expect(status).toEqual(200);
+ expect(updated.externalId).toEqual(null);
+
+ const { data: fetched } = await http.get<Link>({
+ path: `/links/${link.id}`,
+ });
+
+ expect(fetched.externalId).toEqual(null);
+ });
+
+ test("clear externalId with null", async () => {
+ await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body: { externalId: randomId() },
+ });
+
+ const { status, data: updated } = await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body: { externalId: null },
+ });
+
+ expect(status).toEqual(200);
+ expect(updated.externalId).toEqual(null);
+ });
+
+ test("clear tenantId with empty string", async () => {
+ const { status, data: updated } = await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body: { tenantId: "" },
+ });
+
+ expect(status).toEqual(200);
+ expect(updated.tenantId).toEqual(null);
+
+ const { data: fetched } = await http.get<Link>({
+ path: `/links/${link.id}`,
+ });
+
+ expect(fetched.tenantId).toEqual(null);
+ });
+
+ test("clear tenantId with null", async () => {
+ await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body: { tenantId: randomId() },
+ });
+
+ const { status, data: updated } = await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body: { tenantId: null },
+ });
+
+ expect(status).toEqual(200);
+ expect(updated.tenantId).toEqual(null);
+ });
+ },
+);
+
describe.sequential(
"PUT /links/{linkId} (backwards compatibility)",
async () => {