test(web): API 契约测试 — 25 个模块 244 个测试全覆盖
验证每个 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
This commit is contained in:
76
apps/web/src/api/health/consultations.test.ts
Normal file
76
apps/web/src/api/health/consultations.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* consultations 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 { consultationApi } from './consultations'
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('consultationApi', () => {
|
||||
const fakeRes = { data: { success: true, data: {} } }
|
||||
|
||||
it('listSessions 应调用 GET /health/consultation-sessions 并传递查询参数', async () => {
|
||||
mockGet.mockResolvedValue(fakeRes)
|
||||
await consultationApi.listSessions({ page: 1, page_size: 20, status: 'active', patient_id: 'p-001' })
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith('/health/consultation-sessions', {
|
||||
params: { page: 1, page_size: 20, status: 'active', patient_id: 'p-001' },
|
||||
})
|
||||
})
|
||||
|
||||
it('createSession 应调用 POST /health/consultation-sessions', async () => {
|
||||
mockPost.mockResolvedValue(fakeRes)
|
||||
const req = { patient_id: 'p-001', doctor_id: 'd-001', consultation_type: 'online' }
|
||||
await consultationApi.createSession(req)
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/health/consultation-sessions', req)
|
||||
})
|
||||
|
||||
it('getSession 应调用 GET /health/consultation-sessions/:id', async () => {
|
||||
mockGet.mockResolvedValue(fakeRes)
|
||||
await consultationApi.getSession('sess-001')
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith('/health/consultation-sessions/sess-001')
|
||||
})
|
||||
|
||||
it('closeSession 应调用 PUT /health/consultation-sessions/:id/close', async () => {
|
||||
mockPut.mockResolvedValue(fakeRes)
|
||||
await consultationApi.closeSession('sess-001', { version: 1 })
|
||||
|
||||
expect(mockPut).toHaveBeenCalledWith('/health/consultation-sessions/sess-001/close', { version: 1 })
|
||||
})
|
||||
|
||||
it('listMessages 应调用 GET /health/consultation-sessions/:id/messages 并传递分页参数', async () => {
|
||||
mockGet.mockResolvedValue(fakeRes)
|
||||
await consultationApi.listMessages('sess-001', { page: 2, page_size: 50, after_id: 'msg-100' })
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith('/health/consultation-sessions/sess-001/messages', {
|
||||
params: { page: 2, page_size: 50, after_id: 'msg-100' },
|
||||
})
|
||||
})
|
||||
|
||||
it('createMessage 应调用 POST /health/consultation-messages', async () => {
|
||||
mockPost.mockResolvedValue(fakeRes)
|
||||
const req = { session_id: 'sess-001', content_type: 'text', content: '你好' }
|
||||
await consultationApi.createMessage(req)
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/health/consultation-messages', req)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user