Files
dacli/tests/unit/test_browser_workflow_target.test.ts
sushub f403a7e80e import: ssw/dacli@eea0ebc (2026-08-12) 起点版本
本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的
dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。

- 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12)
- 历史未带 ssw main 整体历史(避免大仓污染)
- 此为新仓基线 commit,未来以本仓历史为主
2026-08-12 15:58:06 +08:00

48 lines
2.1 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest'
import { resolveWorkflowTarget } from '../../src/commands/test/_workflow_target.ts'
describe('test browser workflow target (Task 8b)', () => {
it('--id --taskId 都传 → 定向 operator 查询', async () => {
const webapi = {
getFlowTaskOperator: vi.fn().mockResolvedValue({ id: 'op1', userId: 'u1' }),
}
const r = await resolveWorkflowTarget(webapi, { id: 'F1', taskId: 'T1', userId: 'u1' })
expect(r.mode).toBe('targeted')
expect(r.operatorId).toBe('op1')
expect(r.status).toBe('ACTIONABLE')
})
it('--id 传但 operator 为空 → NO_ACTIONABLE_TASK', async () => {
const webapi = { getFlowTaskOperator: vi.fn().mockResolvedValue(null) }
const r = await resolveWorkflowTarget(webapi, { id: 'F1', taskId: 'T1', userId: 'u1' })
expect(r.status).toBe('NO_ACTIONABLE_TASK')
expect(r.exitCode).toBe(2)
})
it('不传 --id → 走通用 flowTodo 兼容模式', async () => {
const r = await resolveWorkflowTarget({}, { userId: 'u1' })
expect(r.mode).toBe('generic')
expect(r.status).toBe('GENERIC_PAGE')
})
// 新增 (Task 8 review Minor): operator userId 不匹配当前 user → NO_ACTIONABLE_TASK
it('operator userId ≠ current userId → NO_ACTIONABLE_TASK (用户不匹配)', async () => {
const webapi = {
getFlowTaskOperator: vi.fn().mockResolvedValue({ id: 'op1', userId: 'u2' }),
}
const r = await resolveWorkflowTarget(webapi, { id: 'F1', taskId: 'T1', userId: 'u1' })
expect(r.status).toBe('NO_ACTIONABLE_TASK')
expect(r.exitCode).toBe(2)
expect(r.reason).toMatch(/user u2.*u1/)
})
// 新增 (Task 8 review Minor): 数字 vs 字符串 userId coerce (后端常返数字)
it('operator userId 数字, current userId 字符串 → String() 比较 OK', async () => {
const webapi = {
getFlowTaskOperator: vi.fn().mockResolvedValue({ id: 'op1', userId: 100 }),
}
const r = await resolveWorkflowTarget(webapi, { id: 'F1', taskId: 'T1', userId: '100' })
expect(r.status).toBe('ACTIONABLE')
expect(r.operatorId).toBe('op1')
})
})