feat: 添加管理端前端 (HMS 基座 React 管理面板)
- 从 HMS 基座复制 apps/web/ (React + Ant Design + Vite + TypeScript) - 管理端自动代理 API 到 localhost:3000 (vite.config.ts) - 更新 scripts/dev.sh 支持三端启动: backend/admin/app - 登录验证通过, 用户管理/角色权限/审计日志等页面正常 - 添加 .gitignore 排除 node_modules/dist
This commit is contained in:
96
apps/web/src/api/dictionaries.test.ts
Normal file
96
apps/web/src/api/dictionaries.test.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* dictionaries 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 dictApi from './dictionaries'
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('dictionaries API', () => {
|
||||
const fakeRes = { data: { success: true, data: {} } }
|
||||
|
||||
it('listDictionaries 应调用 GET /config/dictionaries 并传递分页参数', async () => {
|
||||
mockGet.mockResolvedValue(fakeRes)
|
||||
await dictApi.listDictionaries(1, 10)
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith('/config/dictionaries', {
|
||||
params: { page: 1, page_size: 10 },
|
||||
})
|
||||
})
|
||||
|
||||
it('createDictionary 应调用 POST /config/dictionaries', async () => {
|
||||
mockPost.mockResolvedValue(fakeRes)
|
||||
const req = { name: '性别', code: 'gender', description: '性别字典' }
|
||||
await dictApi.createDictionary(req)
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/config/dictionaries', req)
|
||||
})
|
||||
|
||||
it('updateDictionary 应调用 PUT /config/dictionaries/:id', async () => {
|
||||
mockPut.mockResolvedValue(fakeRes)
|
||||
const req = { name: '性别(更新)', version: 1 }
|
||||
await dictApi.updateDictionary('dict-001', req)
|
||||
|
||||
expect(mockPut).toHaveBeenCalledWith('/config/dictionaries/dict-001', req)
|
||||
})
|
||||
|
||||
it('deleteDictionary 应调用 DELETE /config/dictionaries/:id 并在 body 传递 version', async () => {
|
||||
mockDelete.mockResolvedValue(undefined)
|
||||
await dictApi.deleteDictionary('dict-001', 2)
|
||||
|
||||
expect(mockDelete).toHaveBeenCalledWith('/config/dictionaries/dict-001', {
|
||||
data: { version: 2 },
|
||||
})
|
||||
})
|
||||
|
||||
it('listItemsByCode 应调用 GET /config/dictionaries/items 并传递 code 参数', async () => {
|
||||
mockGet.mockResolvedValue(fakeRes)
|
||||
await dictApi.listItemsByCode('gender')
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith('/config/dictionaries/items', {
|
||||
params: { code: 'gender' },
|
||||
})
|
||||
})
|
||||
|
||||
it('createDictionaryItem 应调用 POST /config/dictionaries/:id/items', async () => {
|
||||
mockPost.mockResolvedValue(fakeRes)
|
||||
const req = { label: '男', value: 'male', sort_order: 1 }
|
||||
await dictApi.createDictionaryItem('dict-001', req)
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/config/dictionaries/dict-001/items', req)
|
||||
})
|
||||
|
||||
it('updateDictionaryItem 应调用 PUT /config/dictionaries/:dictId/items/:itemId', async () => {
|
||||
mockPut.mockResolvedValue(fakeRes)
|
||||
const req = { label: '女', version: 1 }
|
||||
await dictApi.updateDictionaryItem('dict-001', 'item-001', req)
|
||||
|
||||
expect(mockPut).toHaveBeenCalledWith('/config/dictionaries/dict-001/items/item-001', req)
|
||||
})
|
||||
|
||||
it('deleteDictionaryItem 应调用 DELETE /config/dictionaries/:dictId/items/:itemId', async () => {
|
||||
mockDelete.mockResolvedValue(undefined)
|
||||
await dictApi.deleteDictionaryItem('dict-001', 'item-001', 1)
|
||||
|
||||
expect(mockDelete).toHaveBeenCalledWith('/config/dictionaries/dict-001/items/item-001', {
|
||||
data: { version: 1 },
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user