48 lines
2.1 KiB
TypeScript
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')
|
|
})
|
|
}) |