⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat(test): add label api integration tests and readme
Tin528afc3d16dc
diff --git a/tests/api-integration/README.md b/tests/api-integration/README.mdnew file mode 100644index 000000000..102999123--- /dev/null+++ b/tests/api-integration/README.md@@ -0,0 +1,8 @@+# API integration tests++These tests boot the Hono app with a real PostgreSQL database (see `setup.ts` for env defaults).++- Run: `pnpm test:integration` from the repo root (requires Postgres and `DATABASE_URL`).+- CI: `.github/workflows/ci.yml` starts Postgres and runs the same command.++Coverage is intentionally incremental: add new files under this directory for additional routes or behaviors, following existing helpers (`helpers/fixtures.ts`, `helpers/database.ts`, `helpers/auth.ts`).diff --git a/tests/api-integration/label.test.ts b/tests/api-integration/label.test.tsnew file mode 100644index 000000000..1d94f916d--- /dev/null+++ b/tests/api-integration/label.test.ts@@ -0,0 +1,72 @@+import { eq } from "drizzle-orm";+import { beforeEach, describe, expect, it } from "vitest";+import db, { schema } from "../../apps/api/src/database";+import { createApp } from "../../apps/api/src/index";+import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth";+import { resetTestDatabase } from "./helpers/database";+import { createWorkspaceMember } from "./helpers/fixtures";++describe("API integration: labels", () => {+ beforeEach(async () => {+ await resetTestDatabase();+ });++ it("rejects unauthenticated label creation", async () => {+ mockAnonymousSession();+ const { app } = createApp();++ const response = await app.request("/api/label", {+ method: "POST",+ headers: {+ "content-type": "application/json",+ },+ body: JSON.stringify({+ name: "Bug",+ color: "#ff0000",+ workspaceId: "workspace-missing",+ }),+ });++ expect(response.status).toBe(401);+ await expect(response.text()).resolves.toBe("Unauthorized");+ });++ it("creates a label in a workspace for a member", async () => {+ const member = await createWorkspaceMember();+ mockAuthenticatedSession(member.user);+ const { app } = createApp();++ const response = await app.request("/api/label", {+ method: "POST",+ headers: {+ "content-type": "application/json",+ },+ body: JSON.stringify({+ name: "Bug",+ color: "#ef4444",+ workspaceId: member.workspace.id,+ }),+ });++ expect(response.status).toBe(200);+ const payload =+ (await response.json()) as typeof schema.labelTable.$inferSelect;++ expect(payload).toMatchObject({+ workspaceId: member.workspace.id,+ name: "Bug",+ color: "#ef4444",+ });++ const persisted = await db.query.labelTable.findFirst({+ where: eq(schema.labelTable.id, payload.id),+ });++ expect(persisted).toMatchObject({+ id: payload.id,+ workspaceId: member.workspace.id,+ name: "Bug",+ color: "#ef4444",+ });+ });+});