mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 18:08:24 +00:00
* feat(kanban): implement AI-native kanban database models, services, and REST APIs * feat(webui): implement team kanban board and task management * style(webui): increase kanban dialog widths and form container * fix(webui): ensure kanban dialogs override sm:max-w-lg base class * style(webui): set edit task dialog max width to 5xl * chore: untrack kanban plan markdown files * feat(webui): update kanban page layout to 2 columns and refine task activity UI * fix(webui): constrain kanban column and board heights for vertical scrolling * feat(kanban): unify task status transition into updateTask API and allow unconstrained human task transitions * fix(webui): add optimistic updates to kanban drag-and-drop to eliminate flash * refactor(webui): remove client-side search box from kanban header * feat(kanban): redesign task dialog comments area and add attachment support * refactor(webui): remove top status action bar from task info dialog * fix(webui): narrow query cache predicate and add defensive guards for kanban drag optimistic update * feat(kanban): add drag-and-drop task reordering with fractional indexing (#331) * feat(kanban): add drag-and-drop task reordering with fractional indexing * fix(kanban): improve card drop zones, snap indicators, and column highlight * fix(kanban): enable card droppables only during active drag * fix(kanban): refine hover styles and drop indicators for column boundaries * fix(kanban): unify bottom drop indicator and fix top indicator clipping * fix(kanban): ensure full column highlight and full coverage drop target * minor change * feat(kanban): allow agent tasks free drag-and-drop and enforce status change permissions (#332) * refactor(kanban): rename task_type_agentic translation keys to task_type_agent * feat(kanban): refactor task type enum to isAgentTask boolean (#333) * refactor(kanban): remove phase 2 agent execution logic and streamline phase 1 kanban * feat(kanban): add notifications and audit logging for kanban (#334) * feat(kanban): redesign config area layout and add parent tasks multi-selector (#335) * feat(webui): redesign kanban task dialog config area * feat(kanban): simplify task dependencies with parent tasks multi-selector * refactor(kanban): remove unused links routes and legacy dependency methods * feat(kanban): connect assets and kanban tasks with many-to-many relationship (#336) * feat(kanban): connect assets and kanban tasks with many-to-many relationship * feat(kanban): improve asset picker layout, infinite scrolling, and breadcrumb icon styling * fix(kanban): ensure asset picker scrollarea is scrollable with min-h-0 and shrink-0 flex styling * fix(kanban): hide recently deleted in folder tree picker and adjust header padding * fix(kanban): use lucide files icon instead of paperclip for linked assets * feat(kanban): improve task deletion, goal sidebar interaction, and card styling (#337) * feat(kanban): improve task deletion, goal sidebar interaction, and card styling * feat(kanban): move agent task badge after priority and update to orange style * feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions (#338) * feat(kanban): add status Compare-And-Swap (CAS) to prevent drag-and-drop race conditions * style(kanban): rotate kanban icon 180 degrees in sidebar and top nav * style(kanban): remove rotate-180 from SquareKanban icons * feat(kanban): add unassigned goal record and fix all tasks count (#339) * feat(kanban): add unassigned goal record and fix all tasks count * feat(kanban): toggle task count with three-dot action button on goal card hover * fix(ci): pin bun version to 1.3.14 across CI and Docker (#340) * fix(webui): truncate goal name to max 2 lines in kanban sidebar (#341)
159 lines
5.0 KiB
TypeScript
159 lines
5.0 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
|
import { Hono, type Context, type Next } from 'hono'
|
|
import notificationRoute from './notification'
|
|
import { notificationService } from '@shumai/core/src/notification/notification'
|
|
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
|
|
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
|
|
|
|
vi.mock('./middleware/auth', () => ({
|
|
authMiddleware: async (
|
|
c: Context<{ Variables: { user: { id: string; name: string } } }>,
|
|
next: Next,
|
|
) => {
|
|
c.set('user', { id: 'user1', name: 'Test User' })
|
|
await next()
|
|
},
|
|
}))
|
|
|
|
vi.mock('@shumai/core/src/authz/authz')
|
|
vi.mock('@shumai/core/src/notification/notification')
|
|
vi.mock('@shumai/core/src/user-metadata/user-metadata')
|
|
|
|
describe('notification api', () => {
|
|
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
|
|
.use('*', async (c, next) => {
|
|
c.set('user', { id: 'user1', name: 'Test User' })
|
|
await next()
|
|
})
|
|
.route('/', notificationRoute)
|
|
|
|
beforeEach(() => {
|
|
vi.restoreAllMocks()
|
|
vi.mocked(authzService.hasPermission).mockResolvedValue(undefined)
|
|
})
|
|
|
|
it('GET /teams/:teamId/notifications', async () => {
|
|
vi.mocked(notificationService.list).mockResolvedValue({
|
|
data: [{ id: 'n1', type: 'comment_created' }] as any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
pageInfo: { total: 1, cursor: 'abc' },
|
|
})
|
|
|
|
const res = await app.request('/teams/t1/notifications?unreadOnly=true&pageSize=10')
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.data).toHaveLength(1)
|
|
expect(json.pageInfo.total).toBe(1)
|
|
expect(json.pageInfo.cursor).toBe('abc')
|
|
|
|
expect(notificationService.list).toHaveBeenCalledWith('t1', 'user1', {
|
|
unreadOnly: true,
|
|
after: undefined,
|
|
pageSize: 10,
|
|
})
|
|
expect(authzService.hasPermission).toHaveBeenCalledWith({
|
|
user: expect.anything(),
|
|
permission: Permission.Read,
|
|
type: ResourceType.Team,
|
|
id: 't1',
|
|
})
|
|
})
|
|
|
|
it('POST /teams/:teamId/notifications/read', async () => {
|
|
// Using any here because mocking complex service return types or Hono context is overly verbose for this test.
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
vi.mocked(notificationService.markRead).mockResolvedValue(undefined as any)
|
|
|
|
const res = await app.request('/teams/t1/notifications/read', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ notificationId: 'n1' }),
|
|
})
|
|
|
|
expect(res.status).toBe(204)
|
|
expect(notificationService.markRead).toHaveBeenCalledWith('t1', 'user1', 'n1')
|
|
expect(authzService.hasPermission).toHaveBeenCalledWith({
|
|
user: expect.anything(),
|
|
permission: Permission.Read,
|
|
type: ResourceType.Team,
|
|
id: 't1',
|
|
})
|
|
})
|
|
|
|
it('GET /teams/:teamId/notifications/settings - returns default settings', async () => {
|
|
vi.mocked(userMetadataService.getMetadata).mockResolvedValue(null)
|
|
|
|
const res = await app.request('/teams/t1/notifications/settings')
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.comments).toBe(true)
|
|
expect(json.yourUploads).toBe(false)
|
|
|
|
expect(userMetadataService.getMetadata).toHaveBeenCalledWith(
|
|
'user1',
|
|
't1',
|
|
'notification_settings',
|
|
)
|
|
})
|
|
|
|
it('GET /teams/:teamId/notifications/settings - returns saved settings', async () => {
|
|
vi.mocked(userMetadataService.getMetadata).mockResolvedValue({
|
|
key: 'notification_settings',
|
|
value: {
|
|
comments: false,
|
|
replies: false,
|
|
mentions: true,
|
|
yourUploads: true,
|
|
otherUploads: false,
|
|
statusUpdates: true,
|
|
},
|
|
})
|
|
|
|
const res = await app.request('/teams/t1/notifications/settings')
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.comments).toBe(false)
|
|
expect(json.yourUploads).toBe(true)
|
|
})
|
|
|
|
it('POST /teams/:teamId/notifications/settings - saves settings', async () => {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
vi.mocked(userMetadataService.upsertMetadata).mockResolvedValue(undefined as any)
|
|
|
|
const res = await app.request('/teams/t1/notifications/settings', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
comments: false,
|
|
replies: false,
|
|
mentions: true,
|
|
yourUploads: true,
|
|
otherUploads: false,
|
|
statusUpdates: true,
|
|
}),
|
|
})
|
|
|
|
expect(res.status).toBe(200)
|
|
const json = await res.json()
|
|
expect(json.success).toBe(true)
|
|
|
|
expect(userMetadataService.upsertMetadata).toHaveBeenCalledWith(
|
|
'user1',
|
|
't1',
|
|
'notification_settings',
|
|
{
|
|
comments: false,
|
|
replies: false,
|
|
mentions: true,
|
|
yourUploads: true,
|
|
otherUploads: false,
|
|
statusUpdates: true,
|
|
kanbanTasks: true,
|
|
kanbanComments: true,
|
|
},
|
|
)
|
|
})
|
|
})
|