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.

update tests

Kiran Kc64a2712087d
diff --git a/apps/web/tests/links/create-link-error.test.ts b/apps/web/tests/links/create-link-error.test.ts
index 98f48140e6..93263796d3 100644
--- a/apps/web/tests/links/create-link-error.test.ts
+++ b/apps/web/tests/links/create-link-error.test.ts
@@ -60,42 +60,6 @@ const cases = [
},
},
},
- {
- name: "create link in folder that doesn't exist",
- body: {
- domain,
- url,
- folderId: "fold_xxx",
- },
- expected: {
- status: 404,
- data: {
- error: {
- code: "not_found",
- message: "Folder not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- },
- },
- },
- {
- name: "create link in folder without write access",
- body: {
- domain,
- url,
- folderId: "fold_0lo6YZoVBvAyFg62SKTgDXTT",
- },
- expected: {
- status: 403,
- data: {
- error: {
- code: "forbidden",
- message: "You are not allowed to perform this action on this folder.",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
- },
- },
- },
- },
];
cases.forEach(({ name, body, expected }) => {
diff --git a/apps/web/tests/links/folder-link-access.test.ts b/apps/web/tests/links/folder-link-access.test.ts
index eda799085c..d65aeae2a9 100644
--- a/apps/web/tests/links/folder-link-access.test.ts
+++ b/apps/web/tests/links/folder-link-access.test.ts
@@ -1,155 +1,274 @@
import { Link } from "@dub/prisma/client";
-import { env } from "tests/utils/env";
import { describe, expect, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
import {
E2E_LINK,
E2E_NO_ACCESS_FOLDER_ID,
+ E2E_NO_ACCESS_FOLDER_LINK_ID,
E2E_READ_ONLY_FOLDER_ID,
E2E_READ_ONLY_FOLDER_LINK_ID,
} from "../utils/resource";
const { domain, url } = E2E_LINK;
-// Most of the below tests would only run if you have write values set in the resource.ts file
-
-describe.runIf(env.CI).sequential("Folder access", async () => {
+describe.concurrent("Folder access permissions", async () => {
const h = new IntegrationHarness();
const { http } = await h.init();
- test("update link from a folder without write access", async () => {
- const { status, data } = await http.patch<Link>({
- path: `/links/${E2E_READ_ONLY_FOLDER_LINK_ID}`,
- body: {
- url: "https://google.com",
+ describe("create link in a folder", async () => {
+ const cases = [
+ {
+ name: "that doesn't exist",
+ body: {
+ domain,
+ url,
+ folderId: "fold_xxx",
+ },
+ expected: {
+ status: 404,
+ data: {
+ error: {
+ code: "not_found",
+ message: "Folder not found.",
+ doc_url: "https://dub.co/docs/api-reference/errors#not-found",
+ },
+ },
+ },
},
- });
-
- expect(status).toEqual(403);
- expect(data).toEqual({
- error: {
- code: "forbidden",
- message: "You are not allowed to perform this action on this folder.",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ {
+ name: "with read-only access",
+ body: {
+ domain,
+ url,
+ folderId: E2E_READ_ONLY_FOLDER_ID,
+ },
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
},
- });
- });
+ {
+ name: "with no access",
+ body: {
+ domain,
+ url,
+ folderId: E2E_NO_ACCESS_FOLDER_ID,
+ },
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
+ },
+ ];
- test("delete link from a folder without write access", async () => {
- const { status, data } = await http.delete({
- path: `/links/${E2E_READ_ONLY_FOLDER_LINK_ID}`,
- });
+ cases.forEach(({ name, body, expected }) => {
+ test(name, async () => {
+ const response = await http.post<Link>({
+ path: "/links",
+ body,
+ });
- expect(status).toEqual(403);
- expect(data).toEqual({
- error: {
- code: "forbidden",
- message: "You are not allowed to perform this action on this folder.",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
- },
+ expect(response).toEqual(expected);
+ });
});
});
- test("move link to a folder without write access", async ({
- onTestFinished,
- }) => {
- onTestFinished(async () => {
- await h.deleteLink(link.id);
- });
-
- const { data: link } = await http.post<Link>({
- path: "/links",
- body: {
- url,
- domain,
+ describe("update link in a folder", async () => {
+ const cases = [
+ {
+ name: "with read-only access",
+ path: `/links/${E2E_READ_ONLY_FOLDER_LINK_ID}`,
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
},
- });
-
- const { status, data } = await http.patch<Link>({
- path: `/links/${link.id}`,
- body: {
- folderId: E2E_READ_ONLY_FOLDER_ID,
+ {
+ name: "with no access",
+ path: `/links/${E2E_NO_ACCESS_FOLDER_LINK_ID}`,
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
},
- });
+ ];
- expect(status).toEqual(403);
- expect(data).toEqual({
- error: {
- code: "forbidden",
- message: "You are not allowed to perform this action on this folder.",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
- },
- });
- });
+ cases.forEach(({ name, path, expected }) => {
+ test(name, async () => {
+ const response = await http.patch<Link>({
+ path,
+ body: {
+ url: "https://google.com",
+ },
+ });
- test("move to an invalid folder", async ({ onTestFinished }) => {
- onTestFinished(async () => {
- await h.deleteLink(link.id);
+ expect(response).toEqual(expected);
+ });
});
+ });
- const { data: link } = await http.post<Link>({
- path: "/links",
- body: {
- url,
- domain,
+ describe("delete link from a folder", async () => {
+ const cases = [
+ {
+ name: "with read-only access",
+ path: `/links/${E2E_READ_ONLY_FOLDER_LINK_ID}`,
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
},
- });
-
- const { status, data } = await http.patch<Link>({
- path: `/links/${link.id}`,
- body: {
- folderId: "fold_invalid",
+ {
+ name: "with no access",
+ path: `/links/${E2E_NO_ACCESS_FOLDER_LINK_ID}`,
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
},
+ ];
+
+ cases.forEach(({ name, path, expected }) => {
+ test(name, async () => {
+ const response = await http.delete<Link>({
+ path,
+ });
+
+ expect(response).toEqual(expected);
+ });
});
+ });
- expect(status).toEqual(404);
- expect(data).toEqual({
- error: {
- code: "not_found",
- message: "Folder not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
+ describe("move link to a folder", async () => {
+ const cases = [
+ {
+ name: "with read-only access",
+ body: {
+ folderId: E2E_READ_ONLY_FOLDER_ID,
+ },
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
},
+ {
+ name: "with no access",
+ body: {
+ folderId: E2E_NO_ACCESS_FOLDER_ID,
+ },
+ expected: {
+ status: 403,
+ data: {
+ error: {
+ code: "forbidden",
+ message:
+ "You are not allowed to perform this action on this folder.",
+ doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
+ },
+ },
+ },
+ },
+ ];
+
+ cases.forEach(({ name, body, expected }) => {
+ test(name, async ({ onTestFinished }) => {
+ const { data: link } = await http.post<Link>({
+ path: "/links",
+ body: { url, domain },
+ });
+
+ onTestFinished(async () => {
+ await h.deleteLink(link.id);
+ });
+
+ const response = await http.patch<Link>({
+ path: `/links/${link.id}`,
+ body,
+ });
+
+ expect(response).toEqual(expected);
+ });
});
});
- test("bulk create links with invalid folder and folder without write access", async () => {
+ test("bulk create links in folders without write access", async () => {
const { status, data } = await http.post({
path: "/links/bulk",
body: [
- {
- url,
- folderId: "fold_invalid",
- },
- {
- url,
- folderId: E2E_READ_ONLY_FOLDER_ID,
- },
+ { url, folderId: E2E_READ_ONLY_FOLDER_ID },
+ { url, folderId: E2E_NO_ACCESS_FOLDER_ID },
],
});
expect(status).toEqual(200);
expect(data).toEqual([
{
- error: "Invalid folderId detected: fold_invalid",
- code: "unprocessable_entity",
+ error: `You don't have write access to the folder: ${E2E_READ_ONLY_FOLDER_ID}`,
+ code: "forbidden",
link: expect.any(Object),
},
{
- error: `You don't have write access to the folder: ${E2E_READ_ONLY_FOLDER_ID}`,
+ error: `You don't have write access to the folder: ${E2E_NO_ACCESS_FOLDER_ID}`,
code: "forbidden",
link: expect.any(Object),
},
]);
});
- test("bulk update links in folder without write access", async () => {
+ test("bulk update links in folders without write access", async () => {
const { status, data } = await http.patch({
path: "/links/bulk",
body: {
- linkIds: [E2E_READ_ONLY_FOLDER_LINK_ID],
- data: {
- url: "https://google.com",
- },
+ linkIds: [E2E_READ_ONLY_FOLDER_LINK_ID, E2E_NO_ACCESS_FOLDER_LINK_ID],
+ data: { url: "https://google.com" },
},
});
@@ -160,83 +279,20 @@ describe.runIf(env.CI).sequential("Folder access", async () => {
code: "forbidden",
link: expect.any(Object),
},
+ {
+ error: `You don't have permission to move this link to the folder: ${E2E_NO_ACCESS_FOLDER_ID}`,
+ code: "forbidden",
+ link: expect.any(Object),
+ },
]);
});
- test("bulk delete links from folder without write access", async () => {
+ test("bulk delete links from folders without write access", async () => {
const { status, data } = await http.delete({
- path: `/links/bulk?linkIds=${E2E_READ_ONLY_FOLDER_LINK_ID}`,
+ path: `/links/bulk?linkIds=${E2E_READ_ONLY_FOLDER_LINK_ID},${E2E_NO_ACCESS_FOLDER_LINK_ID}`,
});
expect(status).toEqual(200);
expect(data).toEqual({ deletedCount: 0 });
});
-
- test("bulk move links to a folder without write access", async ({
- onTestFinished,
- }) => {
- const link = await http.post<Link>({
- path: "/links",
- body: { url, domain },
- });
-
- onTestFinished(async () => {
- await h.deleteLink(link.data.id);
- });
-
- const { status, data } = await http.patch({
- path: "/links/bulk",
- body: {
- linkIds: [link.data.id],
- data: {
- folderId: E2E_READ_ONLY_FOLDER_ID,
- },
- },
- });
-
- expect(status).toEqual(403);
- expect(data).toEqual({
- error: {
- code: "forbidden",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
- message: "You are not allowed to perform this action on this folder.",
- },
- });
- });
-
- test("access links within an invalid folder", async () => {
- const { status, data } = await http.get({
- path: "/links",
- query: {
- folderId: "fold_invalid",
- },
- });
-
- expect(status).toEqual(404);
- expect(data).toEqual({
- error: {
- code: "not_found",
- message: "Folder not found.",
- doc_url: "https://dub.co/docs/api-reference/errors#not-found",
- },
- });
- });
-
- test("access links within a folder with no access", async () => {
- const { status, data } = await http.get({
- path: "/links",
- query: {
- folderId: E2E_NO_ACCESS_FOLDER_ID,
- },
- });
-
- expect(status).toEqual(403);
- expect(data).toEqual({
- error: {
- code: "forbidden",
- message: "You are not allowed to perform this action on this folder.",
- doc_url: "https://dub.co/docs/api-reference/errors#forbidden",
- },
- });
- });
});
diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts
index 37780bafa1..3c9f0ed997 100644
--- a/apps/web/tests/utils/resource.ts
+++ b/apps/web/tests/utils/resource.ts
@@ -11,4 +11,6 @@ export const E2E_WEBHOOK_ID = "wh_MHR7sZXXtZ7keBaNYZ30rQ0v";
// Folders specific
export const E2E_READ_ONLY_FOLDER_ID = "fold_XgAYzHjSq6z0X5R60cXymphU"; // Folder without write access
export const E2E_NO_ACCESS_FOLDER_ID = "fold_CPXCwj8wBWd222NuQ2zEGZHj"; // Folder with no access
-export const E2E_READ_ONLY_FOLDER_LINK_ID = "link_9pBo2gl0gIKIjOSDZRcVK6lH"; // Link in folder without write access
+
+export const E2E_READ_ONLY_FOLDER_LINK_ID = "link_9pBo2gl0gIKIjOSDZRcVK6lH"; // Link in folder read-only
+export const E2E_NO_ACCESS_FOLDER_LINK_ID = "link_NwJLTVICb1rDgKHJcN4OJ7pT"; // Link in folder no access