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.

at 9a620ba2f31238f03cd28f1da5ef3838d67e4e8a 113 lines 3.1 kB view raw
1import { eq } from "drizzle-orm"; 2import { beforeEach, describe, expect, it } from "vitest"; 3import db, { schema } from "../../apps/api/src/database"; 4import { createApp } from "../../apps/api/src/index"; 5import { mockAnonymousSession, mockAuthenticatedSession } from "./helpers/auth"; 6import { resetTestDatabase } from "./helpers/database"; 7import { createWorkspaceMember } from "./helpers/fixtures"; 8 9describe("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 73 it("rejects label creation for users outside the workspace", async () => { 74 const member = await createWorkspaceMember(); 75 const outsiderId = "user-label-outsider"; 76 77 const [outsider] = await db 78 .insert(schema.userTable) 79 .values({ 80 id: outsiderId, 81 email: `${outsiderId}@example.com`, 82 emailVerified: true, 83 name: "Label Outsider", 84 }) 85 .returning(); 86 87 mockAuthenticatedSession(outsider); 88 const { app } = createApp(); 89 90 const response = await app.request("/api/label", { 91 method: "POST", 92 headers: { 93 "content-type": "application/json", 94 }, 95 body: JSON.stringify({ 96 name: "Blocked", 97 color: "#6b7280", 98 workspaceId: member.workspace.id, 99 }), 100 }); 101 102 expect(response.status).toBe(403); 103 await expect(response.text()).resolves.toBe( 104 "You don't have access to this workspace", 105 ); 106 107 const persisted = await db.query.labelTable.findFirst({ 108 where: eq(schema.labelTable.name, "Blocked"), 109 }); 110 111 expect(persisted).toBeUndefined(); 112 }); 113});