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

Steven Teyd83c535b645e
diff --git a/apps/web/lib/api/workspace-id.ts b/apps/web/lib/api/workspace-id.ts
index 93f9c22b34..3931b98726 100644
--- a/apps/web/lib/api/workspace-id.ts
+++ b/apps/web/lib/api/workspace-id.ts
@@ -13,6 +13,7 @@ export const normalizeWorkspaceId = (workspaceId: string) => {
export const createWorkspaceId = () => {
const workspaceId = createId({ prefix: "ws_" });
+ // guard against collisions with old workspace ID format
if (workspaceId.toLowerCase().startsWith("ws_c")) {
return createWorkspaceId();
}
diff --git a/apps/web/scripts/migrate.ts b/apps/web/scripts/migrate.ts
index 237ed82695..71ad42ac0e 100644
--- a/apps/web/scripts/migrate.ts
+++ b/apps/web/scripts/migrate.ts
@@ -5,51 +5,15 @@ const DOMAIN = "x.com";
const PROJECT_ID = "xxx";
async function main() {
- const [links, project] = await Promise.all([
- prisma.link.updateMany({
- where: {
- domain: DOMAIN,
- },
- data: {
- projectId: PROJECT_ID,
- },
- }),
- prisma.project.findFirst({
- where: {
- domains: {
- some: {
- slug: DOMAIN,
- },
- },
- },
- }),
- ]);
-
- const response = await Promise.all([
- prisma.domain.update({
- where: {
- slug: DOMAIN,
- },
- data: {
- projectId: PROJECT_ID,
- primary: false,
- },
- }),
- prisma.project.update({
- where: {
- id: PROJECT_ID,
- },
- data: {
- usage: {
- increment: project?.usage,
- },
- linksUsage: {
- increment: links.count,
+ const response = await prisma.project.findMany({
+ where: {
+ id: {
+ not: {
+ startsWith: "c",
},
},
- }),
- ]);
-
+ },
+ });
console.log({ response });
}
diff --git a/apps/web/tests/links/bulk-create-link.test.ts b/apps/web/tests/links/bulk-create-link.test.ts
index 0f64d33628..a4010605c1 100644
--- a/apps/web/tests/links/bulk-create-link.test.ts
+++ b/apps/web/tests/links/bulk-create-link.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import z from "@/lib/zod";
import { Link } from "@dub/prisma/client";
import { expect, onTestFinished, test } from "vitest";
@@ -12,7 +13,7 @@ const setupBulkTest = async (ctx: any) => {
const h = new IntegrationHarness(ctx);
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
return { h, http, user, workspaceId, projectId };
};
diff --git a/apps/web/tests/links/bulk-update-link.test.ts b/apps/web/tests/links/bulk-update-link.test.ts
index 080fd3f4bc..2e1582c52c 100644
--- a/apps/web/tests/links/bulk-update-link.test.ts
+++ b/apps/web/tests/links/bulk-update-link.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import { Link, Tag } from "@dub/prisma/client";
import { expect, onTestFinished, test } from "vitest";
import { randomId, randomTagName } from "../utils/helpers";
@@ -11,7 +12,7 @@ test("PATCH /links/bulk", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
onTestFinished(async () => {
await Promise.all([
diff --git a/apps/web/tests/links/create-link.test.ts b/apps/web/tests/links/create-link.test.ts
index d22786baca..619c3e0bd7 100644
--- a/apps/web/tests/links/create-link.test.ts
+++ b/apps/web/tests/links/create-link.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import z from "@/lib/zod";
import { FolderSchema } from "@/lib/zod/schemas/folders";
import { Link, Tag } from "@dub/prisma/client";
@@ -16,7 +17,7 @@ describe.sequential("POST /links", async () => {
const h = new IntegrationHarness();
const { workspace, user, http } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
test("public link", async () => {
const { status, data: link } = await http.post<Link>({
@@ -470,7 +471,7 @@ describe.sequential("POST /links?workspaceId=xxx", async () => {
const h = new IntegrationHarnessOld();
const { workspace, user, http } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
test("create link with old personal API keys approach", async () => {
onTestFinished(async () => {
diff --git a/apps/web/tests/links/list-links.test.ts b/apps/web/tests/links/list-links.test.ts
index 7332787fc9..c082202764 100644
--- a/apps/web/tests/links/list-links.test.ts
+++ b/apps/web/tests/links/list-links.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import { Link } from "@dub/prisma/client";
import { expect, onTestFinished, test } from "vitest";
import { IntegrationHarness } from "../utils/integration";
@@ -9,7 +10,7 @@ test("GET /links", async (ctx) => {
const h = new IntegrationHarness(ctx);
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
onTestFinished(async () => {
await h.deleteLink(firstLink.id);
diff --git a/apps/web/tests/links/retrieve-link.test.ts b/apps/web/tests/links/retrieve-link.test.ts
index d03a3f69cd..dc3c3fd044 100644
--- a/apps/web/tests/links/retrieve-link.test.ts
+++ b/apps/web/tests/links/retrieve-link.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import { Link } from "@dub/prisma/client";
import { expectedLink } from "tests/utils/schema";
import { afterAll, describe, expect, test } from "vitest";
@@ -11,7 +12,7 @@ describe.concurrent("GET /links/{linkId}", async () => {
const h = new IntegrationHarness();
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
const externalId = randomId();
const key = randomId();
@@ -62,7 +63,7 @@ describe.sequential("GET /links/info", async () => {
const h = new IntegrationHarness();
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
const externalId = randomId();
const key = randomId();
diff --git a/apps/web/tests/links/update-link.test.ts b/apps/web/tests/links/update-link.test.ts
index 9f71067815..e258c4d41b 100644
--- a/apps/web/tests/links/update-link.test.ts
+++ b/apps/web/tests/links/update-link.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import { Link } from "@dub/prisma/client";
import { afterAll, describe, expect, test } from "vitest";
import { randomId } from "../utils/helpers";
@@ -11,7 +12,7 @@ describe.sequential("PATCH /links/{linkId}", async () => {
const h = new IntegrationHarness();
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
const externalId = randomId();
const { data: link } = await http.post<Link>({
@@ -186,7 +187,7 @@ describe.sequential(
const h = new IntegrationHarness();
const { workspace, http, user } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
const externalId = randomId();
const { data: link } = await http.post<Link>({
diff --git a/apps/web/tests/links/upsert-link.test.ts b/apps/web/tests/links/upsert-link.test.ts
index f552845953..0caaeb7f02 100644
--- a/apps/web/tests/links/upsert-link.test.ts
+++ b/apps/web/tests/links/upsert-link.test.ts
@@ -1,3 +1,4 @@
+import { normalizeWorkspaceId } from "@/lib/api/workspace-id";
import { Link } from "@dub/prisma/client";
import { afterAll, describe, expect, test } from "vitest";
import { randomId } from "../utils/helpers";
@@ -12,7 +13,7 @@ describe.sequential("PUT /links/upsert", async () => {
const h = new IntegrationHarness();
const { workspace, user, http } = await h.init();
const workspaceId = workspace.id;
- const projectId = workspaceId.replace("ws_", "");
+ const projectId = normalizeWorkspaceId(workspaceId);
let createdLink: Link;
afterAll(async () => {