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 档案)。
118 lines
4.0 KiB
TypeScript
118 lines
4.0 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { discoveryCandidates, driveSpaceURL, fetchAvailableDingtalkSources } from './dingtalkSources'
|
|
|
|
const payload = {
|
|
data: {
|
|
knowledge_bases: [
|
|
{
|
|
name: 'ATOM知识库',
|
|
space_id: '9JOGOQneRgkneX4Q',
|
|
space_type: 'orgWikiSpace',
|
|
url: 'https://alidocs.dingtalk.com/i/spaces/9JOGOQneRgkneX4Q/overview',
|
|
description: '',
|
|
},
|
|
{
|
|
name: '视觉文档',
|
|
space_id: '9JOGO9EEOMLMWX4Q',
|
|
space_type: 'orgWikiSpace',
|
|
url: '',
|
|
description: '2d/2.5D/3D 视觉',
|
|
},
|
|
{
|
|
name: '我的文档',
|
|
space_id: '9JOGOxeo90ybnz4Q',
|
|
space_type: 'myWikiSpace',
|
|
url: 'https://alidocs.dingtalk.com/i/spaces/9JOGOxeo90ybnz4Q/overview',
|
|
description: '',
|
|
},
|
|
],
|
|
drive_spaces: [
|
|
{ name: '我的文件', space_id: '28122692916', space_type: 'mySpace', root_folder_id: '65Y1OQX0' },
|
|
{ name: '全员文件夹', space_id: '102571304', space_type: 'orgSpace', root_folder_id: 'g1YGl6Pm' },
|
|
],
|
|
knowledge_notice: '',
|
|
drive_notice: '',
|
|
fetched_at: '2026-10-10T08:00:00Z',
|
|
},
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
describe('fetchAvailableDingtalkSources', () => {
|
|
it('parses knowledge bases and drive spaces', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async () => new Response(JSON.stringify(payload), { status: 200 }))
|
|
)
|
|
const list = await fetchAvailableDingtalkSources()
|
|
expect(list.knowledge_bases).toHaveLength(3)
|
|
expect(list.knowledge_bases[1].url).toBe('https://alidocs.dingtalk.com/i/spaces/9JOGO9EEOMLMWX4Q/overview')
|
|
expect(list.drive_spaces).toHaveLength(2)
|
|
expect(list.drive_spaces[1].space_type).toBe('orgSpace')
|
|
expect(list.knowledge_notice).toBe('')
|
|
expect(list.drive_notice).toBe('')
|
|
})
|
|
|
|
it('explains environment problems instead of pretending the list is empty', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async () => new Response('{"error":"dingtalk_discovery_unavailable"}', { status: 503 }))
|
|
)
|
|
await expect(fetchAvailableDingtalkSources()).rejects.toThrow(/暂时列不出来/)
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async () => new Response('{}', { status: 501 }))
|
|
)
|
|
await expect(fetchAvailableDingtalkSources()).rejects.toThrow(/后端未接线/)
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(async () => new Response('{}', { status: 403 }))
|
|
)
|
|
await expect(fetchAvailableDingtalkSources()).rejects.toThrow(/需要管理员身份/)
|
|
})
|
|
|
|
it('carries the drive notice so the page can explain a missing 钉盘 list', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn(
|
|
async () =>
|
|
new Response(
|
|
JSON.stringify({
|
|
data: { knowledge_bases: [], drive_spaces: [], drive_notice: 'list orgSpace: permission denied' },
|
|
}),
|
|
{ status: 200 }
|
|
)
|
|
)
|
|
)
|
|
const list = await fetchAvailableDingtalkSources()
|
|
expect(list.drive_notice).toContain('permission denied')
|
|
})
|
|
})
|
|
|
|
describe('discoveryCandidates', () => {
|
|
it('flattens both groups and marks the ones already registered as sources', () => {
|
|
const candidates = discoveryCandidates(payload.data as never, ['ATOM知识库', ' (空名字) '])
|
|
expect(candidates.map((item) => item.key)).toEqual([
|
|
'kb:9JOGOQneRgkneX4Q',
|
|
'kb:9JOGO9EEOMLMWX4Q',
|
|
'kb:9JOGOxeo90ybnz4Q',
|
|
'drive:28122692916',
|
|
'drive:102571304',
|
|
])
|
|
expect(candidates[0].alreadyRegistered).toBe(true)
|
|
expect(candidates[1].alreadyRegistered).toBe(false)
|
|
expect(candidates[0].detail).toBe('钉钉知识库 · 组织知识库')
|
|
expect(candidates[2].detail).toBe('钉钉知识库 · 我的知识库')
|
|
expect(candidates[3].detail).toBe('钉盘 · 我的文件')
|
|
expect(candidates[4].detail).toBe('钉盘 · 组织空间')
|
|
expect(candidates[4].url).toBe(driveSpaceURL('102571304'))
|
|
})
|
|
|
|
it('returns nothing for an empty list', () => {
|
|
expect(discoveryCandidates(null, ['X'])).toEqual([])
|
|
})
|
|
})
|