Files
knowledge-governance/web/src/productionBindings.test.ts
dev 0fb78cfe26
build / build (push) Successful in 1m51s
feat(web): 发布管理界面精简 + 系统设置审查修复
发布管理:状态卡 + 一个主按钮,准备动作与检查项分层次收纳,去掉重复入口。
系统设置:F02 停滞阈值接入活动配置;F03 分区保存边界;F05/F06 生产绑定分层与凭据说明;
F07 备份未接主机/未知证据如实显示;F09 分区独立加载与保存后重探;F10 文案精简;F11 重置密码对话框。
2026-11-17 15:23:29 +08:00

89 lines
3.1 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { fetchProductionBindingOptions, fetchProductionBindings, saveProductionBindings } from './productionBindings'
const binding = {
internal_kb_id: '0b217e8a-2a65-40a3-ab8f-34ac5c7a6f05',
external_kb_id: '',
internal_kb_name: '对内知识库-wiki',
external_kb_name: '',
updated_by: 'admin',
production_base_url: 'https://weknora-test.dobot.cn/',
production_connected: true,
production_message: '',
}
describe('production bindings API', () => {
it('reads the 源库 → 目标库 projection without leaking extra fields', async () => {
vi.stubGlobal(
'fetch',
vi
.fn()
.mockResolvedValue(new Response(JSON.stringify({ data: { ...binding, api_key: 'drop' } }), { status: 200 }))
)
const result = await fetchProductionBindings()
expect(result.internal_kb_name).toBe('对内知识库-wiki')
expect(result.production_connected).toBe(true)
expect(result).not.toHaveProperty('api_key')
vi.unstubAllGlobals()
})
it('lists production knowledge base options for the picker', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue(
new Response(
JSON.stringify({
data: [
{ id: 'kb-1', name: '对内知识库-wiki', knowledge_count: 2069 },
{ id: '', name: '坏行' },
],
}),
{ status: 200 }
)
)
)
expect(await fetchProductionBindingOptions()).toEqual([
{ id: 'kb-1', name: '对内知识库-wiki', knowledge_count: 2069 },
])
vi.unstubAllGlobals()
})
it('saves with an idempotency key and surfaces a rejected base', async () => {
const fetchMock = vi
.fn()
.mockResolvedValueOnce(new Response(JSON.stringify({ data: binding }), { status: 200 }))
.mockResolvedValueOnce(
new Response(JSON.stringify({ error: '对内绑定的生产知识库在该 WeKnora 实例中不存在' }), { status: 400 })
)
vi.stubGlobal('fetch', fetchMock)
await expect(saveProductionBindings({ internal_kb_id: 'kb-1', external_kb_id: '' })).resolves.toMatchObject({
internal_kb_name: '对内知识库-wiki',
})
const [, init] = fetchMock.mock.calls[0]
expect(init.method).toBe('PUT')
expect(init.headers['Idempotency-Key']).toBeTruthy()
await expect(saveProductionBindings({ internal_kb_id: 'kb-ghost', external_kb_id: '' })).rejects.toThrow('不存在')
vi.unstubAllGlobals()
})
it('reports an unverified save honestly instead of pretending it was checked', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue(
new Response(
JSON.stringify({
data: {
...binding,
production_connected: false,
production_message: '生产 WeKnora 不可用:dial tcp: timeout',
},
}),
{ status: 200 }
)
)
)
const result = await saveProductionBindings({ internal_kb_id: 'kb-1', external_kb_id: '' })
expect(result.production_connected).toBe(false)
expect(result.production_message).toContain('不可用')
vi.unstubAllGlobals()
})
})