验证每个 API 模块的 URL/HTTP Method/参数序列化: - health(14): patients/appointments/alerts/articles/consultations/ dashboard/deviceReadings/doctors/followUp/healthData/points/ followUpTemplates/api - 基础模块(11): auth/users/roles/orgs/dictionaries/messages/ plugins/pluginData/config-modules/workflow/auditLogs 前端测试总数: 140(store) + 244(api) = 384
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
/**
|
|
* auditLogs API 契约测试
|
|
*/
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
const mockGet = vi.fn()
|
|
const mockPost = vi.fn()
|
|
const mockPut = vi.fn()
|
|
const mockDelete = vi.fn()
|
|
|
|
vi.mock('./client', () => ({
|
|
default: {
|
|
get: (...args: unknown[]) => mockGet(...args),
|
|
post: (...args: unknown[]) => mockPost(...args),
|
|
put: (...args: unknown[]) => mockPut(...args),
|
|
delete: (...args: unknown[]) => mockDelete(...args),
|
|
},
|
|
}))
|
|
|
|
import * as auditLogsApi from './auditLogs'
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('auditLogs API', () => {
|
|
const fakeRes = { data: { success: true, data: {} } }
|
|
|
|
it('listAuditLogs 应调用 GET /audit-logs 并传递查询参数', async () => {
|
|
mockGet.mockResolvedValue(fakeRes)
|
|
await auditLogsApi.listAuditLogs({ resource_type: 'user', user_id: 'u-001', page: 1, page_size: 10 })
|
|
|
|
expect(mockGet).toHaveBeenCalledWith('/audit-logs', {
|
|
params: expect.objectContaining({
|
|
resource_type: 'user',
|
|
user_id: 'u-001',
|
|
page: 1,
|
|
page_size: 10,
|
|
}),
|
|
})
|
|
})
|
|
|
|
it('listAuditLogs 默认应传 page=1 page_size=20', async () => {
|
|
mockGet.mockResolvedValue(fakeRes)
|
|
await auditLogsApi.listAuditLogs()
|
|
|
|
expect(mockGet).toHaveBeenCalledWith('/audit-logs', {
|
|
params: expect.objectContaining({ page: 1, page_size: 20 }),
|
|
})
|
|
})
|
|
})
|