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
+25
View File
@@ -4,6 +4,8 @@ import providerRoute from './provider'
import { providerService } from '@shumai/core/src/provider/provider'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
vi.mock('./middleware/auth', () => ({
authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>,
@@ -16,6 +18,11 @@ vi.mock('./middleware/auth', () => ({
vi.mock('@shumai/core/src/authz/authz')
vi.mock('@shumai/core/src/provider/provider')
vi.mock('@shumai/core/src/auditLog/auditLog', () => ({
auditLogService: {
logAction: vi.fn().mockResolvedValue({}),
},
}))
describe('provider api', () => {
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
@@ -115,6 +122,12 @@ describe('provider api', () => {
type: ResourceType.Team,
id: 't1',
})
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'provider_create',
teamId: 't1',
userId: 'user1',
itemId: 'p1',
})
})
it('PUT /providers/:id updates provider', async () => {
@@ -163,6 +176,12 @@ describe('provider api', () => {
type: ResourceType.Provider,
id: 'p1',
})
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'provider_update',
teamId: 't1',
userId: 'user1',
itemId: 'p1',
})
})
it('DELETE /providers/:id deletes provider', async () => {
@@ -188,5 +207,11 @@ describe('provider api', () => {
type: ResourceType.Provider,
id: 'p1',
})
expect(auditLogService.logAction).toHaveBeenCalledWith({
action: 'provider_delete',
teamId: 't1',
userId: 'user1',
itemId: 'p1',
})
})
})