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:
55
apps/web/src/api/auth.test.ts
Normal file
55
apps/web/src/api/auth.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* auth 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 authApi from './auth'
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('auth API', () => {
|
||||
const fakeRes = { data: { success: true, data: {} } }
|
||||
|
||||
it('login 应调用 POST /auth/login 并传递用户名密码', async () => {
|
||||
mockPost.mockResolvedValue(fakeRes)
|
||||
await authApi.login({ username: 'admin', password: '123456' })
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/auth/login', {
|
||||
username: 'admin',
|
||||
password: '123456',
|
||||
})
|
||||
})
|
||||
|
||||
it('logout 应调用 POST /auth/logout', async () => {
|
||||
mockPost.mockResolvedValue(undefined)
|
||||
await authApi.logout()
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/auth/logout')
|
||||
})
|
||||
|
||||
it('changePassword 应调用 POST /auth/change-password', async () => {
|
||||
mockPost.mockResolvedValue(undefined)
|
||||
await authApi.changePassword('oldPass', 'newPass')
|
||||
|
||||
expect(mockPost).toHaveBeenCalledWith('/auth/change-password', {
|
||||
current_password: 'oldPass',
|
||||
new_password: 'newPass',
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user