e34306b2db
build / build (push) Failing after 18s
发布管理:maintenanceSummary 只看 job.state === 'failed' 就给 held 处置文案; 窗口已 released 的旧作业(libsync-internal-1793399248431728863)因此自相矛盾。 改为仅 held 时给 recoveryError,已释放时给 releasedFailure(如实记录失败,不提供强制成功)。 版本记录:LoadVersionHistorySyncState 把可空的 finished_at 扫进 time.Time; 部署重启触发的同步在"进行中"时该列为 NULL,扫描失败使整页 500 (nginx access log:GET /api/v1/version-history?limit=30 → 500,74 字节错误体)。 改为指针接值再判空。前端同时区分"未配置/加载失败"并显示服务端 code。 RED/GREEN:新增 Go 集成用例(NULL finished_at)、两条前端用例; make verify 16/16 通过(local 档案)。
69 lines
2.4 KiB
TypeScript
69 lines
2.4 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()
|
|
})
|
|
})
|