kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(test): add label api integration tests and readme

Tin 528afc3d ec05672a

+80
+8
tests/api-integration/README.md
··· 1 + # API integration tests 2 + 3 + These tests boot the Hono app with a real PostgreSQL database (see `setup.ts` for env defaults). 4 + 5 + - Run: `pnpm test:integration` from the repo root (requires Postgres and `DATABASE_URL`). 6 + - CI: `.github/workflows/ci.yml` starts Postgres and runs the same command. 7 + 8 + 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`).
+72
tests/api-integration/label.test.ts
··· 1 + import { eq } from "drizzle-orm"; 2 + import { beforeEach, describe, expect, it } from "vitest"; 3 + import db, { schema } from "../../apps/api/src/database"; 4 + import { createApp } from "../../apps/api/src/index"; 5 + import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth"; 6 + import { resetTestDatabase } from "./helpers/database"; 7 + import { createWorkspaceMember } from "./helpers/fixtures"; 8 + 9 + describe("API integration: labels", () => { 10 + beforeEach(async () => { 11 + await resetTestDatabase(); 12 + }); 13 + 14 + it("rejects unauthenticated label creation", async () => { 15 + mockAnonymousSession(); 16 + const { app } = createApp(); 17 + 18 + const response = await app.request("/api/label", { 19 + method: "POST", 20 + headers: { 21 + "content-type": "application/json", 22 + }, 23 + body: JSON.stringify({ 24 + name: "Bug", 25 + color: "#ff0000", 26 + workspaceId: "workspace-missing", 27 + }), 28 + }); 29 + 30 + expect(response.status).toBe(401); 31 + await expect(response.text()).resolves.toBe("Unauthorized"); 32 + }); 33 + 34 + it("creates a label in a workspace for a member", async () => { 35 + const member = await createWorkspaceMember(); 36 + mockAuthenticatedSession(member.user); 37 + const { app } = createApp(); 38 + 39 + const response = await app.request("/api/label", { 40 + method: "POST", 41 + headers: { 42 + "content-type": "application/json", 43 + }, 44 + body: JSON.stringify({ 45 + name: "Bug", 46 + color: "#ef4444", 47 + workspaceId: member.workspace.id, 48 + }), 49 + }); 50 + 51 + expect(response.status).toBe(200); 52 + const payload = 53 + (await response.json()) as typeof schema.labelTable.$inferSelect; 54 + 55 + expect(payload).toMatchObject({ 56 + workspaceId: member.workspace.id, 57 + name: "Bug", 58 + color: "#ef4444", 59 + }); 60 + 61 + const persisted = await db.query.labelTable.findFirst({ 62 + where: eq(schema.labelTable.id, payload.id), 63 + }); 64 + 65 + expect(persisted).toMatchObject({ 66 + id: payload.id, 67 + workspaceId: member.workspace.id, 68 + name: "Bug", 69 + color: "#ef4444", 70 + }); 71 + }); 72 + });