mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 07:34:25 +00:00
* fix(share): only return share-visible field values on public share links The public share children and file detail endpoints returned every custom field value on an asset, while the share's field settings only hid them in the share UI. Filter fieldValues server-side to the fields turned on for the share, matching what GET /shares/:shareId/fields already returns. * fix(share): stop returning share passwords and compare them in constant time Share link responses included the saved password in plain text. Remove it from ShareLinkInfo; clients already get hasPassword. Check the password a guest enters with a constant-time comparison of SHA-256 digests instead of a string comparison. The share settings panel no longer pre-fills the saved password. When a password is set, the field starts empty with a hint, Save stays disabled until a new password is typed, and the field clears after saving. Turning the password off still removes it. * fix(kanban): limit task lists and task reads to the caller's projects Kanban checked only team membership for task reads, so a member invited to one project could list every task in the team and open any task, its linked files, comments and activity. - Task lists and the tasks linked to a file now include, for project-scoped members, only tasks in projects they belong to plus tasks they created, report, or are assigned to. Team-scoped members see every task as before. - Reading a task, its files, comments and activity follows the same rule: a project-scoped member outside the task's project needs to be its creator, reporter or assignee. - Linking a file to a task (create, update, or the link endpoints) now requires Read on that file, since linked files are shown to everyone who can read the task. * fix(security): sign only issued comment attachments and keep files on comment delete Kanban comment attachments: - Upload keys now include the team and the uploader: kanban/attachments/<teamId>/<userId>/<ulid>/<file name>. - addComment rejects any attachment key that was not issued to the comment author for the task's team, so a client can no longer store an arbitrary storage key in a comment. - When comments are read, only keys of kanban comment attachments for the task's team (or the previous kanban/attachments/<ulid>/<name> form) are presigned. Keys stored earlier that point anywhere else are dropped. Asset comment attachments: - createComment only links attachment uploads made by the commenter in the same project that are not linked to another comment. Project files can no longer be linked as comment attachments. - deleteComment deletes the stored object and asset only for attachment uploads not linked elsewhere; anything else linked to the comment is only unlinked. Upload keys: - Sanitize the file name in kanban and project attachment upload keys, as regular uploads already do, so a name cannot add path segments. - The local storage backend rejects keys with a '..' segment instead of resolving them into another object's path. * fix(security): enforce visibility and protect comment attachments --------- Co-authored-by: phj1081 <5908832+phj1081@users.noreply.github.com>
763 lines
25 KiB
TypeScript
763 lines
25 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { Hono, type Context, type Next } from 'hono'
|
|
import { kanbanService } from '@shumai/core/src/kanban/kanban'
|
|
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
|
import { notificationService } from '@shumai/core/src/notification/notification'
|
|
import { KanbanTaskStatus, KanbanTaskPriority } from '@shumai/db/enums'
|
|
import { HTTPException } from 'hono/http-exception'
|
|
import { authzService } from '@shumai/core/src/authz/authz'
|
|
import kanbanRoute from './index'
|
|
|
|
vi.mock('@shumai/core/src/authz/authz', () => ({
|
|
authzService: {
|
|
hasPermission: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
resolveEffectiveRole: vi.fn().mockResolvedValue('owner'),
|
|
Permission: {
|
|
Read: 'Read',
|
|
Edit: 'Edit',
|
|
Admin: 'Admin',
|
|
},
|
|
ResourceType: {
|
|
Team: 'team',
|
|
Project: 'project',
|
|
Asset: 'asset',
|
|
KanbanGoal: 'kanbanGoal',
|
|
KanbanTask: 'kanbanTask',
|
|
},
|
|
}))
|
|
|
|
vi.mock('@shumai/core/src/auditLog/auditLog', () => ({
|
|
auditLogService: {
|
|
logAction: vi.fn().mockResolvedValue({}),
|
|
},
|
|
}))
|
|
|
|
vi.mock('@shumai/core/src/notification/notification', () => ({
|
|
notificationService: {
|
|
notifyKanbanTaskEvent: vi.fn().mockResolvedValue(undefined),
|
|
create: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
}))
|
|
|
|
describe('Kanban API Routes', () => {
|
|
const teamId = 'team-1'
|
|
const taskId = 'task-1'
|
|
const goalId = 'goal-1'
|
|
|
|
const authMiddleware = async (c: Context, next: Next) => {
|
|
c.set('user', { id: 'user-1', name: 'Test User' })
|
|
await next()
|
|
}
|
|
|
|
let app: Hono
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
vi.mocked(authzService.hasPermission).mockResolvedValue(undefined)
|
|
vi.mocked(auditLogService.logAction).mockResolvedValue({} as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
vi.mocked(notificationService.notifyKanbanTaskEvent).mockResolvedValue(undefined as any) // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
app = new Hono()
|
|
app.use('*', authMiddleware)
|
|
app.route('/', kanbanRoute)
|
|
})
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Goals Endpoints
|
|
// --------------------------------------------------------------------------
|
|
describe('Goals Endpoints', () => {
|
|
it('POST /teams/:teamId/kanban/goals', async () => {
|
|
const mockCreate = vi.spyOn(kanbanService, 'createGoal').mockResolvedValue({
|
|
id: goalId,
|
|
title: 'New Goal',
|
|
description: 'Goal description',
|
|
teamId,
|
|
creatorId: 'user-1',
|
|
taskCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/goals`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ title: 'New Goal', description: 'Goal description' }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.id).toBe(goalId)
|
|
expect(mockCreate).toHaveBeenCalledWith(
|
|
teamId,
|
|
{ title: 'New Goal', description: 'Goal description' },
|
|
'user-1',
|
|
'owner',
|
|
)
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/goals', async () => {
|
|
const mockList = vi.spyOn(kanbanService, 'listGoals').mockResolvedValue([
|
|
{
|
|
id: goalId,
|
|
title: 'Goal 1',
|
|
teamId,
|
|
creatorId: 'user-1',
|
|
taskCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
},
|
|
])
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/goals`)
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.data).toHaveLength(1)
|
|
expect(mockList).toHaveBeenCalledWith(teamId, expect.any(Object))
|
|
})
|
|
|
|
it('PATCH /teams/:teamId/kanban/goals/:goalId', async () => {
|
|
const mockUpdate = vi.spyOn(kanbanService, 'updateGoal').mockResolvedValue({
|
|
id: goalId,
|
|
title: 'Updated Goal',
|
|
teamId,
|
|
creatorId: 'user-1',
|
|
taskCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/goals/${goalId}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ title: 'Updated Goal' }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.title).toBe('Updated Goal')
|
|
expect(mockUpdate).toHaveBeenCalledWith(goalId, { title: 'Updated Goal' }, 'owner')
|
|
})
|
|
|
|
it('DELETE /teams/:teamId/kanban/goals/:goalId', async () => {
|
|
const mockDelete = vi.spyOn(kanbanService, 'deleteGoal').mockResolvedValue(undefined)
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/goals/${goalId}`, {
|
|
method: 'DELETE',
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.ok).toBe(true)
|
|
expect(mockDelete).toHaveBeenCalledWith(goalId, 'owner')
|
|
})
|
|
})
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Tasks Endpoints
|
|
// --------------------------------------------------------------------------
|
|
describe('Tasks Endpoints', () => {
|
|
it('POST /teams/:teamId/kanban/tasks', async () => {
|
|
const mockCreate = vi.spyOn(kanbanService, 'createTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'New Task',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ title: 'New Task', isAgentTask: false }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.id).toBe(taskId)
|
|
expect(mockCreate).toHaveBeenCalledWith(teamId, expect.any(Object), 'user-1', 'owner')
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/tasks (with isAgentTask and goal filters)', async () => {
|
|
const mockList = vi.spyOn(kanbanService, 'listTasks').mockResolvedValue({
|
|
data: [
|
|
{
|
|
id: taskId,
|
|
title: 'Task 1',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
},
|
|
],
|
|
pageInfo: { total: 1 },
|
|
})
|
|
|
|
const res = await app.request(
|
|
`/teams/${teamId}/kanban/tasks?isAgentTask=false&status=READY&goalId=goal-1`,
|
|
)
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.data).toHaveLength(1)
|
|
expect(mockList).toHaveBeenCalledWith(
|
|
teamId,
|
|
expect.objectContaining({
|
|
isAgentTask: false,
|
|
status: 'READY',
|
|
goalId: 'goal-1',
|
|
}),
|
|
'user-1',
|
|
)
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/tasks/:taskId', async () => {
|
|
const mockGet = vi.spyOn(kanbanService, 'getTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task 1',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
dependencies: [],
|
|
dependents: [],
|
|
assets: [],
|
|
comments: [],
|
|
events: [],
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`)
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.id).toBe(taskId)
|
|
expect(mockGet).toHaveBeenCalledWith(taskId, 'user-1')
|
|
})
|
|
|
|
it('PATCH /teams/:teamId/kanban/tasks/:taskId', async () => {
|
|
vi.spyOn(kanbanService, 'getTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Old Task Title',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
dependencies: [],
|
|
dependents: [],
|
|
assets: [],
|
|
comments: [],
|
|
events: [],
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
const mockUpdate = vi.spyOn(kanbanService, 'updateTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Updated Task Title',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.HIGH,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ priority: 'HIGH', status: 'DONE', reason: 'All done' }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(mockUpdate).toHaveBeenCalledWith(
|
|
taskId,
|
|
{ priority: 'HIGH', status: 'DONE', reason: 'All done' },
|
|
'user-1',
|
|
'owner',
|
|
)
|
|
})
|
|
|
|
it('PATCH /teams/:teamId/kanban/tasks/:taskId with beforeIndex and afterIndex', async () => {
|
|
vi.spyOn(kanbanService, 'getTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task 1',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
sortIndex: 'a0V',
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
dependencies: [],
|
|
dependents: [],
|
|
assets: [],
|
|
comments: [],
|
|
events: [],
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
const mockUpdate = vi.spyOn(kanbanService, 'updateTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task 1',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
sortIndex: 'a0V',
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ status: 'READY', beforeIndex: 'a1', afterIndex: 'a0' }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(mockUpdate).toHaveBeenCalledWith(
|
|
taskId,
|
|
{ status: 'READY', beforeIndex: 'a1', afterIndex: 'a0' },
|
|
'user-1',
|
|
'owner',
|
|
)
|
|
})
|
|
|
|
it('PATCH /teams/:teamId/kanban/tasks/:taskId with fromStatus for CAS', async () => {
|
|
vi.spyOn(kanbanService, 'getTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task 1',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.TODO,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
dependencies: [],
|
|
dependents: [],
|
|
assets: [],
|
|
comments: [],
|
|
events: [],
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
const mockUpdate = vi.spyOn(kanbanService, 'updateTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task 1',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.IN_PROGRESS,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ fromStatus: 'TODO', status: 'IN_PROGRESS' }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(mockUpdate).toHaveBeenCalledWith(
|
|
taskId,
|
|
{ fromStatus: 'TODO', status: 'IN_PROGRESS' },
|
|
'user-1',
|
|
'owner',
|
|
)
|
|
})
|
|
|
|
it('DELETE /teams/:teamId/kanban/tasks/:taskId', async () => {
|
|
vi.spyOn(kanbanService, 'getTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task to delete',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
dependencies: [],
|
|
dependents: [],
|
|
assets: [],
|
|
comments: [],
|
|
events: [],
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
const mockDelete = vi.spyOn(kanbanService, 'deleteTask').mockResolvedValue({
|
|
id: taskId,
|
|
title: 'Task to delete',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 0,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`, {
|
|
method: 'DELETE',
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
expect(mockDelete).toHaveBeenCalledWith(taskId, 'user-1', 'owner')
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/tasks/:taskId/assets', async () => {
|
|
const mockListTaskAssets = vi.spyOn(kanbanService, 'listTaskAssets').mockResolvedValue([
|
|
{
|
|
id: 'asset-1',
|
|
name: 'Video.mp4',
|
|
type: 'file',
|
|
proxyType: 'video',
|
|
thumbnailUrl: 'http://example.com/thumb.jpg',
|
|
path: '/Project/Video.mp4',
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
])
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/assets`)
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json).toHaveLength(1)
|
|
expect(json[0].name).toBe('Video.mp4')
|
|
expect(mockListTaskAssets).toHaveBeenCalledWith(taskId)
|
|
})
|
|
|
|
it('POST /teams/:teamId/kanban/tasks/:taskId/assets', async () => {
|
|
const mockLinkAssets = vi.spyOn(kanbanService, 'linkAssets').mockResolvedValue(undefined)
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/assets`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ assetIds: ['asset-1', 'asset-2'] }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
expect(mockLinkAssets).toHaveBeenCalledWith(teamId, taskId, ['asset-1', 'asset-2'])
|
|
})
|
|
|
|
describe('linking files the caller cannot read', () => {
|
|
const denyAsset = (deniedAssetId: string) =>
|
|
vi.mocked(authzService.hasPermission).mockImplementation(async (req) => {
|
|
if (req.type === 'asset' && req.id === deniedAssetId) {
|
|
throw new HTTPException(403, { message: 'User has only project scope' })
|
|
}
|
|
})
|
|
|
|
it('checks Read on every file linked to a task', async () => {
|
|
const mockLinkAssets = vi.spyOn(kanbanService, 'linkAssets').mockResolvedValue(undefined)
|
|
denyAsset('asset-2')
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/assets`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ assetIds: ['asset-1', 'asset-2'] }),
|
|
})
|
|
|
|
expect(res.status).toBe(403)
|
|
expect(mockLinkAssets).not.toHaveBeenCalled()
|
|
expect(authzService.hasPermission).toHaveBeenCalledWith(
|
|
expect.objectContaining({ type: 'asset', id: 'asset-1', permission: 'Read' }),
|
|
)
|
|
})
|
|
|
|
it('checks Read on the file when linking it from the file side', async () => {
|
|
const mockLinkAsset = vi.spyOn(kanbanService, 'linkAsset').mockResolvedValue(undefined)
|
|
denyAsset('asset-1')
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/assets/asset-1/tasks`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ taskId }),
|
|
})
|
|
|
|
expect(res.status).toBe(403)
|
|
expect(mockLinkAsset).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('checks Read on files passed when updating a task', async () => {
|
|
const mockUpdate = vi.spyOn(kanbanService, 'updateTask')
|
|
denyAsset('asset-9')
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ assetIds: ['asset-9'] }),
|
|
})
|
|
|
|
expect(res.status).toBe(403)
|
|
expect(mockUpdate).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('checks Read on files passed when creating a task', async () => {
|
|
const mockCreate = vi.spyOn(kanbanService, 'createTask')
|
|
denyAsset('asset-9')
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ title: 'Task', assetIds: ['asset-9'] }),
|
|
})
|
|
|
|
expect(res.status).toBe(403)
|
|
expect(mockCreate).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
it('DELETE /teams/:teamId/kanban/tasks/:taskId/assets/:assetId', async () => {
|
|
const mockUnlinkAsset = vi.spyOn(kanbanService, 'unlinkAsset').mockResolvedValue(undefined)
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/assets/asset-1`, {
|
|
method: 'DELETE',
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
expect(mockUnlinkAsset).toHaveBeenCalledWith(teamId, taskId, 'asset-1')
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/assets/:assetId/tasks', async () => {
|
|
const mockListTasksForAsset = vi.spyOn(kanbanService, 'listTasksForAsset').mockResolvedValue([
|
|
{
|
|
id: taskId,
|
|
title: 'Task linked to asset',
|
|
isAgentTask: false,
|
|
status: KanbanTaskStatus.READY,
|
|
priority: KanbanTaskPriority.MEDIUM,
|
|
teamId,
|
|
creator: { id: 'user-1', name: 'User 1' },
|
|
commentCount: 0,
|
|
dependencyCount: 0,
|
|
dependentCount: 0,
|
|
assetCount: 1,
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
},
|
|
])
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/assets/asset-1/tasks`)
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.total).toBe(1)
|
|
expect(json.data).toHaveLength(1)
|
|
expect(mockListTasksForAsset).toHaveBeenCalledWith(teamId, 'asset-1', 'user-1')
|
|
})
|
|
|
|
it('POST /teams/:teamId/kanban/assets/:assetId/tasks', async () => {
|
|
const mockLinkAsset = vi.spyOn(kanbanService, 'linkAsset').mockResolvedValue(undefined)
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/assets/asset-1/tasks`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ taskId }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
expect(mockLinkAsset).toHaveBeenCalledWith(teamId, taskId, 'asset-1')
|
|
})
|
|
|
|
it('DELETE /teams/:teamId/kanban/assets/:assetId/tasks/:taskId', async () => {
|
|
const mockUnlinkAsset = vi.spyOn(kanbanService, 'unlinkAsset').mockResolvedValue(undefined)
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/assets/asset-1/tasks/${taskId}`, {
|
|
method: 'DELETE',
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
expect(mockUnlinkAsset).toHaveBeenCalledWith(teamId, taskId, 'asset-1')
|
|
})
|
|
})
|
|
|
|
// --------------------------------------------------------------------------
|
|
// Comments, Attachments & Events
|
|
// --------------------------------------------------------------------------
|
|
describe('Comments, Attachments and Events Endpoints', () => {
|
|
it('POST /teams/:teamId/kanban/attachments', async () => {
|
|
const mockAttachment = vi.spyOn(kanbanService, 'createAttachment').mockResolvedValue({
|
|
id: 'att-1',
|
|
name: 'test.png',
|
|
key: 'kanban/attachments/test.png',
|
|
sizeByte: 1024,
|
|
uploadUrl: 'http://s3/upload',
|
|
proxyType: 'image',
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/attachments`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ fileName: 'test.png', size: 1024, contentType: 'image/png' }),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.id).toBe('att-1')
|
|
expect(mockAttachment).toHaveBeenCalledWith(teamId, 'user-1', {
|
|
fileName: 'test.png',
|
|
size: 1024,
|
|
contentType: 'image/png',
|
|
})
|
|
})
|
|
|
|
it('POST /teams/:teamId/kanban/tasks/:taskId/comments', async () => {
|
|
const mockAdd = vi.spyOn(kanbanService, 'addComment').mockResolvedValue({
|
|
id: 'c-1',
|
|
taskId,
|
|
author: { id: 'user-1', name: 'User 1' },
|
|
body: 'Here is a note',
|
|
attachments: [],
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
})
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/comments`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
body: 'Here is a note',
|
|
attachments: [
|
|
{
|
|
id: 'att-1',
|
|
name: 'test.png',
|
|
key: 'key-1',
|
|
sizeByte: 1024,
|
|
proxyType: 'image',
|
|
},
|
|
],
|
|
}),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
expect(mockAdd).toHaveBeenCalledWith(taskId, 'user-1', 'Here is a note', [
|
|
{
|
|
id: 'att-1',
|
|
name: 'test.png',
|
|
key: 'key-1',
|
|
sizeByte: 1024,
|
|
proxyType: 'image',
|
|
},
|
|
])
|
|
})
|
|
|
|
it('DELETE /teams/:teamId/kanban/tasks/:taskId/comments/:commentId', async () => {
|
|
const mockDelete = vi.spyOn(kanbanService, 'deleteComment').mockResolvedValue()
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/comments/c-1`, {
|
|
method: 'DELETE',
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
expect(mockDelete).toHaveBeenCalledWith(taskId, 'c-1', 'user-1', 'owner')
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/tasks/:taskId/comments', async () => {
|
|
const mockList = vi.spyOn(kanbanService, 'listComments').mockResolvedValue([
|
|
{
|
|
id: 'c-1',
|
|
taskId,
|
|
author: { id: 'user-1', name: 'User 1' },
|
|
body: 'Note',
|
|
attachments: [],
|
|
createdAt: new Date().toISOString(),
|
|
updatedAt: new Date().toISOString(),
|
|
},
|
|
])
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/comments`)
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.data).toHaveLength(1)
|
|
expect(mockList).toHaveBeenCalledWith(taskId)
|
|
})
|
|
|
|
it('GET /teams/:teamId/kanban/tasks/:taskId/events', async () => {
|
|
const mockEvents = vi.spyOn(kanbanService, 'listEvents').mockResolvedValue([
|
|
{
|
|
id: 'e-1',
|
|
taskId,
|
|
actor: { id: 'user-1', name: 'User 1' },
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
type: 'CREATED' as any,
|
|
createdAt: new Date().toISOString(),
|
|
},
|
|
])
|
|
|
|
const res = await app.request(`/teams/${teamId}/kanban/tasks/${taskId}/events`)
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.data).toHaveLength(1)
|
|
expect(mockEvents).toHaveBeenCalledWith(taskId, 'user-1')
|
|
})
|
|
})
|
|
})
|