feat(audit): change audit log action to string at db level and split file/folder actions

This commit is contained in:
yiling
2026-08-01 14:49:08 +08:00
parent 6d80f06c22
commit 5ef7716c9c
19 changed files with 192 additions and 193 deletions
+25
View File
@@ -5,6 +5,7 @@ import { assetService } from '@shumai/core/src/asset/asset'
import { AssetType } from '@shumai/db'
import { authMiddleware } from './middleware/auth'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
vi.mock('./middleware/auth', () => ({
// any is used here because Hono's Context and Next types are complex to mock in vitest.mock
@@ -18,6 +19,23 @@ vi.mock('./middleware/auth', () => ({
vi.mock('@shumai/core/src/authz/authz')
vi.mock('@shumai/core/src/asset/asset')
vi.mock('@shumai/core/src/auditLog/auditLog', () => ({
auditLogService: {
logAction: vi.fn().mockResolvedValue({}),
},
}))
vi.mock('@shumai/db', async (importOriginal) => {
const actual = await importOriginal<typeof import('@shumai/db')>()
return {
...actual,
prisma: {
project: {
findUnique: vi.fn().mockResolvedValue({ teamId: 't1' }),
},
},
}
})
vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: {
@@ -65,5 +83,12 @@ describe('Attachment API', () => {
projectId: 'project1',
}),
)
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'file_create',
teamId: 't1',
userId: 'user1',
projectId: 'project1',
itemId: 'asset1',
})
})
})