f6cb90cd70
- main.tsx 挂 AuthProvider 门控:未登录→登录页;must_change_password→强制改密页 - 登录页/改密页/顶栏身份(头像+姓名+角色徽章+退出)按 A·Data-console token 样式 - 全局 fetch 拦截器:任意业务请求 401 自动回登录页(会话过期/被撤销不留死表单) - 系统设置新增「成员与角色」分区(仅 admin 可见):名单、角色调整、启停、重置临时密码、新增成员 - 消灭全部手填操作人:审核/封批/确认计划集/范围规则/来源调度/UI 设置/开始处理/批量重试/ 目录差异确认共 9 处输入框删除,请求体不再携带 actor 字段(服务端从会话注入) - 测试断言方向翻转:显式验证请求体不含 operator_ref/created_by 等字段 - 附带修复:登录失败计数 SQL 参数类型无法推断导致 500(pgx 扩展协议),显式 cast 解决 前端门禁:tsc 0 错、125 用例全绿、build 通过
42 lines
2.1 KiB
TypeScript
42 lines
2.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { roleLabels } from './auth'
|
|
import { fetchManagedUsers, resetManagedUserPassword, setManagedUserState } from './members'
|
|
|
|
describe('role labels', () => {
|
|
it('covers exactly the three platform roles', () => {
|
|
expect(Object.keys(roleLabels).sort()).toEqual(['admin', 'engineer', 'viewer'])
|
|
})
|
|
})
|
|
|
|
describe('members API', () => {
|
|
it('parses the managed user roster', async () => {
|
|
const payload = { data: [{ id: 'usr-1', username: 'boss', display_name: '老板', role: 'admin', state: 'active', must_change_password: false }] }
|
|
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify(payload), { status: 200 }))
|
|
vi.stubGlobal('fetch', fetchMock)
|
|
const users = await fetchManagedUsers()
|
|
expect(users).toHaveLength(1)
|
|
expect(users[0].role).toBe('admin')
|
|
expect(String(fetchMock.mock.calls[0][0])).toBe('/api/v1/users')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('rejects a role the server does not know', async () => {
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: [{ id: 'u', username: 'x', role: 'superuser', state: 'active' }] }))))
|
|
await expect(fetchManagedUsers()).rejects.toThrow('成员响应无效')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('surfaces server errors for state changes', async () => {
|
|
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(JSON.stringify({ error: 'cannot disable the last active admin' }), { status: 409 })))
|
|
await expect(setManagedUserState('usr-1', 'disabled')).rejects.toThrow('cannot disable the last active admin')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('resets passwords without sending any actor field', async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: { reset: true } }), { status: 200 }))
|
|
vi.stubGlobal('fetch', fetchMock)
|
|
await resetManagedUserPassword('usr-2', 'temp-pass-1')
|
|
const body = JSON.parse(String(fetchMock.mock.calls[0][1].body))
|
|
expect(body).toEqual({ temporary_password: 'temp-pass-1' })
|
|
expect(fetchMock.mock.calls[0][0]).toBe('/api/v1/users/usr-2/reset-password')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
})
|