The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add the tests for /workspaces/**
Kiran Kf2db7ac15474
diff --git a/apps/web/tests/utils/schema.ts b/apps/web/tests/utils/schema.tsindex e8bf712515..f7f40d1b8e 100644--- a/apps/web/tests/utils/schema.ts+++ b/apps/web/tests/utils/schema.ts@@ -39,12 +39,11 @@ export const expectedTag: Partial<Tag> = {updatedAt: expect.any(String),};-// TODO:-// Make it dynamic based on the planexport const expectedWorkspace: Partial<Project> = {- logo: expect.any(String) || null,- plan: expect.any(String),- stripeId: expect.any(String),+ id: expect.any(String),+ name: expect.any(String),+ slug: expect.any(String),+ logo: expect.any(String),usage: expect.any(Number),usageLimit: expect.any(Number),linksUsage: expect.any(Number),@@ -52,12 +51,9 @@ export const expectedWorkspace: Partial<Project> = {domainsLimit: expect.any(Number),tagsLimit: expect.any(Number),usersLimit: expect.any(Number),- aiLimit: expect.any(Number),- aiUsage: expect.any(Number),- monitoringId: null,- id: expect.any(String),+ plan: expect.any(String),+ stripeId: expect.any(String),billingCycleStart: expect.any(Number),inviteCode: expect.any(String),createdAt: expect.any(String),- updatedAt: expect.any(String),};diff --git a/apps/web/tests/workspaces/create-workspace-error.test.ts b/apps/web/tests/workspaces/create-workspace-error.test.tsindex c2a078864f..be46d4d3c6 100644--- a/apps/web/tests/workspaces/create-workspace-error.test.ts+++ b/apps/web/tests/workspaces/create-workspace-error.test.ts@@ -2,7 +2,7 @@ import { Project } from "@prisma/client";import { expect, test } from "vitest";import { IntegrationHarness } from "../utils/integration";-test.skip("should not create workspace with slug in use", async (ctx) => {+test("should not create workspace with slug in use", async (ctx) => {const h = new IntegrationHarness(ctx);const { workspace, http } = await h.init();diff --git a/apps/web/tests/workspaces/list-workspaces.test.ts b/apps/web/tests/workspaces/list-workspaces.test.tsindex 6185ef9a0e..6526681976 100644--- a/apps/web/tests/workspaces/list-workspaces.test.ts+++ b/apps/web/tests/workspaces/list-workspaces.test.ts@@ -1,9 +1,10 @@+import z from "@/lib/zod";+import { WorkspaceSchema } from "@/lib/zod/schemas";import { Project } from "@prisma/client";-import { expectedWorkspace } from "tests/utils/schema";import { expect, test } from "vitest";import { IntegrationHarness } from "../utils/integration";-test.skip("GET /workspaces", async (ctx) => {+test("GET /workspaces", async (ctx) => {const h = new IntegrationHarness(ctx);const { workspace, http } = await h.init();@@ -11,18 +12,23 @@ test.skip("GET /workspaces", async (ctx) => {path: "/workspaces",});- const workspaceFound = workspaces.find(- (w) => w.slug === h.resources.workspace.slug,- );+ const workspacesFetched = workspaces.map((w) => {+ return {+ id: w.id,+ name: w.name,+ slug: w.slug,+ };+ });expect(status).toEqual(200);expect(workspaces.length).toBeGreaterThanOrEqual(1);- expect(workspaceFound).toStrictEqual({- ...expectedWorkspace,+ expect(workspacesFetched).toContainEqual({+ id: workspace.id,name: workspace.name,slug: workspace.slug,- id: workspace.id,- domains: expect.any(Array),- users: [{ role: "owner" }],});++ z.array(WorkspaceSchema.extend({ createdAt: z.string() }).strict()).parse(+ workspaces,+ );});diff --git a/apps/web/tests/workspaces/retrieve-workspace.error.test.ts b/apps/web/tests/workspaces/retrieve-workspace.error.test.tsindex 6845cf78b3..501fdae136 100644--- a/apps/web/tests/workspaces/retrieve-workspace.error.test.ts+++ b/apps/web/tests/workspaces/retrieve-workspace.error.test.ts@@ -2,7 +2,7 @@ import { Project } from "@prisma/client";import { expect, test } from "vitest";import { IntegrationHarness } from "../utils/integration";-test.skip("retrieve a workspace by invalid slug or id", async (ctx) => {+test("retrieve a workspace by invalid slug or id", async (ctx) => {const h = new IntegrationHarness(ctx);const { http } = await h.init();diff --git a/apps/web/tests/workspaces/retrieve-workspace.test.ts b/apps/web/tests/workspaces/retrieve-workspace.test.tsindex 72d66b9496..101e4d4b9a 100644--- a/apps/web/tests/workspaces/retrieve-workspace.test.ts+++ b/apps/web/tests/workspaces/retrieve-workspace.test.ts@@ -1,42 +1,48 @@+import z from "@/lib/zod";+import { WorkspaceSchema } from "@/lib/zod/schemas";import { Project } from "@prisma/client";-import { expect, test } from "vitest";+import { describe, expect, test } from "vitest";import { IntegrationHarness } from "../utils/integration";-import { expectedWorkspace } from "../utils/schema";-test.skip("GET /workspaces/{id}", async (ctx) => {- const h = new IntegrationHarness(ctx);+describe("GET /workspaces/{idOrSlug}", async () => {+ const h = new IntegrationHarness();const { workspace, http } = await h.init();- const { status, data: workspaceFetched } = await http.get<Project>({- path: `/workspaces/${workspace.workspaceId}`,- });+ test("by id", async () => {+ const { status, data: workspaceFetched } = await http.get<Project>({+ path: `/workspaces/${workspace.workspaceId}`,+ });- expect(status).toEqual(200);- expect(workspaceFetched).toMatchObject({- ...expectedWorkspace,- name: workspace.name,- slug: workspace.slug,- id: workspace.id,- domains: [],- users: [{ role: "owner" }],- });-});+ const { id, name, slug } = workspaceFetched;-test.skip("GET /workspaces/{slug}", async (ctx) => {- const h = new IntegrationHarness(ctx);- const { workspace, http } = await h.init();+ expect(status).toEqual(200);+ expect({ id, name, slug }).toStrictEqual({+ id: workspace.id,+ name: workspace.name,+ slug: workspace.slug,+ });- const { status, data: workspaceFetched } = await http.get<Project>({- path: `/workspaces/${workspace.slug}`,+ WorkspaceSchema.extend({ createdAt: z.string() })+ .strict()+ .parse(workspaceFetched);});- expect(status).toEqual(200);- expect(workspaceFetched).toStrictEqual({- ...expectedWorkspace,- name: workspace.name,- slug: workspace.slug,- id: workspace.id,- domains: [],- users: [{ role: "owner" }],+ test("by slug", async () => {+ const { status, data: workspaceFetched } = await http.get<Project>({+ path: `/workspaces/${workspace.slug}`,+ });++ const { id, name, slug } = workspaceFetched;++ expect(status).toEqual(200);+ expect({ id, name, slug }).toStrictEqual({+ id: workspace.id,+ name: workspace.name,+ slug: workspace.slug,+ });++ WorkspaceSchema.extend({ createdAt: z.string() })+ .strict()+ .parse(workspaceFetched);});});