feat(api): add missing audit log calls to API endpoints

This commit is contained in:
yiling
2026-08-01 11:03:50 +08:00
parent 7dfb2c7f2f
commit 0324b95c7e
18 changed files with 695 additions and 2 deletions
+30
View File
@@ -40,6 +40,14 @@ vi.mock('@shumai/core/src/authz/authz', () => ({
},
}))
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
vi.mock('@shumai/core/src/auditLog/auditLog', () => ({
auditLogService: {
logAction: vi.fn().mockResolvedValue({}),
},
}))
vi.mock('./middleware/auth', () => ({
authMiddleware: async (c: Context, next: Next) => {
c.set('user', { id: 'user1', name: 'Test User' })
@@ -129,6 +137,13 @@ describe('file api', () => {
type: ResourceType.Asset,
id: 'test-id',
})
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'asset_update',
teamId: 'test-team',
userId: 'user1',
projectId: undefined,
itemId: 'test-id',
})
})
it('DELETE /files', async () => {
@@ -150,6 +165,13 @@ describe('file api', () => {
id: 'test-id',
})
expect(assetService.deleteAssets).toHaveBeenCalledWith(['test-id'])
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'asset_delete',
teamId: 'test-team',
userId: 'user1',
projectId: undefined,
itemId: 'test-id',
})
})
it('POST /files/restore', async () => {
@@ -208,6 +230,14 @@ describe('file api', () => {
const json = await res.json()
expect(json.message).toBe('hello')
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'comment_create',
teamId: 'test-team',
userId: 'user1',
projectId: undefined,
itemId: 'comment-id',
})
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user1', name: 'Test User' },
permission: Permission.Read,