mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
feat(comment): add emoji reaction support for comments (#405)
* feat(comment): add emoji reaction support for comments * fix(webui): adjust emoji picker trigger icon size to match mark-done icon * fix(webui): prevent search icon and placeholder overlap in emoji picker * fix(webui): use normal text color for reaction count * feat(db): limit comment reaction code column to VarChar(32)
This commit is contained in:
@@ -36,6 +36,7 @@ vi.mock('@shumai/core/src/authz/authz', () => ({
|
||||
Asset: 'asset',
|
||||
Team: 'team',
|
||||
Project: 'project',
|
||||
Comment: 'comment',
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -65,6 +66,8 @@ describe('file api', () => {
|
||||
vi.spyOn(assetService, 'createComment').mockImplementation(vi.fn())
|
||||
vi.spyOn(assetService, 'completeComment').mockImplementation(vi.fn())
|
||||
vi.spyOn(assetService, 'deleteComment').mockImplementation(vi.fn())
|
||||
vi.spyOn(assetService, 'addCommentReaction').mockImplementation(vi.fn())
|
||||
vi.spyOn(assetService, 'removeCommentReaction').mockImplementation(vi.fn())
|
||||
vi.spyOn(assetService, 'getComment').mockResolvedValue({
|
||||
id: 'comment1',
|
||||
assetId: 'file1',
|
||||
@@ -215,6 +218,7 @@ describe('file api', () => {
|
||||
sessionId: null,
|
||||
isCompleted: false,
|
||||
completionLastChangedBy: null,
|
||||
reactionCounts: [],
|
||||
})
|
||||
|
||||
// Mock assetService.getAsset to return teamId for notification
|
||||
@@ -274,6 +278,7 @@ describe('file api', () => {
|
||||
sessionId: null,
|
||||
isCompleted: false,
|
||||
completionLastChangedBy: null,
|
||||
reactionCounts: [],
|
||||
})
|
||||
|
||||
// Mock assetService.getAsset to return teamId for notification
|
||||
@@ -330,6 +335,7 @@ describe('file api', () => {
|
||||
sessionId: null,
|
||||
isCompleted: false,
|
||||
completionLastChangedBy: null,
|
||||
reactionCounts: [],
|
||||
},
|
||||
],
|
||||
pageInfo: { cursor: 'cursor', total: 1 },
|
||||
@@ -349,6 +355,7 @@ describe('file api', () => {
|
||||
type: ResourceType.Asset,
|
||||
id: 'test-id',
|
||||
})
|
||||
expect(assetService.listComments).toHaveBeenCalledWith('test-id', expect.anything(), 'user1')
|
||||
})
|
||||
|
||||
it('POST /files/:fileId/comments/export - success', async () => {
|
||||
@@ -472,6 +479,7 @@ describe('file api', () => {
|
||||
sessionId: null,
|
||||
isCompleted: true,
|
||||
completionLastChangedBy: { id: 'user1', name: 'Test User' },
|
||||
reactionCounts: [],
|
||||
})
|
||||
|
||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||
@@ -520,6 +528,56 @@ describe('file api', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('POST /comments/:commentId/reactions', async () => {
|
||||
vi.mocked(assetService.addCommentReaction).mockResolvedValue(undefined)
|
||||
|
||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||
const res = await app.request('/comments/comment-id/reactions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ code: '👍' }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.success).toBe(true)
|
||||
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith({
|
||||
user: { id: 'user1', name: 'Test User' },
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Comment,
|
||||
id: 'comment-id',
|
||||
})
|
||||
expect(assetService.addCommentReaction).toHaveBeenCalledWith('comment-id', 'user1', '👍')
|
||||
})
|
||||
|
||||
it('DELETE /comments/:commentId/reactions', async () => {
|
||||
vi.mocked(assetService.removeCommentReaction).mockResolvedValue(undefined)
|
||||
|
||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||
const res = await app.request('/comments/comment-id/reactions', {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ code: '👍' }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json.success).toBe(true)
|
||||
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith({
|
||||
user: { id: 'user1', name: 'Test User' },
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Comment,
|
||||
id: 'comment-id',
|
||||
})
|
||||
expect(assetService.removeCommentReaction).toHaveBeenCalledWith('comment-id', 'user1', '👍')
|
||||
})
|
||||
|
||||
it('POST /teams/:teamId/files - image with compression', async () => {
|
||||
vi.mocked(s3Service.putObject).mockResolvedValue(undefined)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user