mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 05:49:04 +00:00
feat(audit): change audit log action to string at db level and split file/folder actions
This commit is contained in:
@@ -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',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user