The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
wip
Kiran K27ccfafecd0e
diff --git a/apps/web/tests/links.test.ts b/apps/web/tests/links.test.tsindex 4046f29449..7d86cc1050 100644--- a/apps/web/tests/links.test.ts+++ b/apps/web/tests/links.test.ts@@ -1,21 +1,24 @@import { beforeAll, describe, expect, test } from "vitest";import { HttpClient } from "./utils/http";import { Link } from "@prisma/client";+import { init } from "./utils/integration";-const workspaceId = "ws_cltx2raaz0000pju4z0v33sy2";+describe("links", async () => {+ const { workspace, apiKey } = await init();-describe("links", () => {test("creates new link", async () => {const http = new HttpClient({baseUrl: "http://localhost:8888/api",headers: {- Authorization: "Bearer cJHO9vZR8B4eaY3mJoI0b6JZ",+ Authorization: `Bearer ${apiKey}`,},});+ console.log("workspace", workspace);+const res = await http.post<Link>({path: "/links",- query: { workspaceId },+ query: { workspaceId: workspace.workspaceId },body: { url: "https://google.com" },});@@ -25,8 +28,8 @@ describe("links", () => {domain: "kiran.localhost",shortLink: `https://kiran.localhost/${res.data.key}`,archived: false,- workspaceId,- projectId: workspaceId.replace("ws_", ""),+ workspaceId: workspace.workspaceId,+ projectId: workspace.id,});});});diff --git a/apps/web/tests/setup.ts b/apps/web/tests/setup.tsindex b90464f294..dd5fc8f734 100644--- a/apps/web/tests/setup.ts+++ b/apps/web/tests/setup.ts@@ -1,25 +1,18 @@-import prisma from "@/lib/prisma";-import { afterAll, beforeAll } from "vitest";--beforeAll(async () => {- console.log("Running beforeAll")+import { beforeAll } from "vitest";- await prisma.user.create({- data: {- name: "Kiran",- email: "[email protected]",- emailVerified: new Date(),- },- });+beforeAll(() => {+ console.log("Running beforeAll");+ console.log("Running beforeAll");+ console.log("Running beforeAll");+ console.log("Running beforeAll");+ console.log("Running beforeAll");+ console.log("Running beforeAll");+ // await prisma.$transaction([+ // prisma.project.deleteMany(),+ // prisma.token.deleteMany(),+ // prisma.user.deleteMany(),+ // ]);- // Create a user- // Create a workspace- // Create a api key+ // await prisma.$disconnect()});--afterAll(async () => {- console.log("Running afterAll")- await prisma.$transaction([prisma.project.deleteMany()]);- await prisma.$transaction([prisma.user.deleteMany()]);-})\ No newline at end of filediff --git a/apps/web/tests/utils/integration.ts b/apps/web/tests/utils/integration.tsindex e69de29bb2..0c16cffc66 100644--- a/apps/web/tests/utils/integration.ts+++ b/apps/web/tests/utils/integration.ts@@ -0,0 +1,51 @@+import { hashToken } from "@/lib/auth";+import prisma from "@/lib/prisma";+import { nanoid } from "@dub/utils";++export const init = async () => {+ // Create a user+ const user = await prisma.user.create({+ data: {+ name: "Kiran",+ email: "[email protected]",+ emailVerified: new Date(),+ },+ });++ // Create a workspace for the user+ const workspace = await prisma.project.create({+ data: {+ name: "Dub",+ slug: "dub",+ users: {+ create: {+ userId: user.id,+ role: "owner",+ },+ },+ billingCycleStart: new Date().getDate(),+ defaultDomains: {+ create: {},+ },+ },+ });++ // Create an API key for the user+ const token = nanoid(24);+ await prisma.token.create({+ data: {+ name: "API Key",+ hashedKey: hashToken(token, {+ noSecret: true,+ }),+ partialKey: `${token.slice(0, 3)}...${token.slice(-4)}`,+ userId: user.id,+ },+ });++ return {+ user,+ workspace: { ...workspace, workspaceId: `ws_${workspace.id}` },+ apiKey: token,+ } as const;+};