Files
dacli/tests/unit/workflow_launch_actionable.test.ts
T

44 lines
1.9 KiB
TypeScript

/**
* workflow launch actionable task 验证 + auto-authorize 失败回执
*
* 关注 launch 后的两个强不变量:
* 1. 流程发起后, 当前用户必须能查到 actionable operator (待办/待签)
* 否则 launch "成功" 是假阳性 — 没人能办理.
* 2. --auto-authorize 失败必须有显式回执, 不允许静默吞错.
*
* verifyLaunched 收口在 _launch_verify.ts, 是纯函数 + webapi 注入契约,
* 单元测试用 vi.fn() 模拟 webapi, 不依赖真实 JNPF.
*/
import { describe, expect, it, vi } from 'vitest'
import { verifyLaunched } from '../../src/commands/workflow/_launch_verify.ts'
describe('workflow launch verify (Task 6)', () => {
it('launch 成功但 operator 为空 → actionableTaskCreated=false', async () => {
const webapi = {
getFlowTaskOperatorList: vi.fn().mockResolvedValue([]),
}
const r = await verifyLaunched(webapi, { flowId: 'f1', taskId: 't1', currentUserId: 'u1' })
expect(r.actionableTaskCreated).toBe(false)
expect(r.exitCode).toBe(2)
})
it('launch 成功 + 有 operator → actionableTaskCreated=true', async () => {
const webapi = {
getFlowTaskOperatorList: vi.fn().mockResolvedValue([{ id: 'op1', taskNodeId: 't1', userId: 'u1' }]),
}
const r = await verifyLaunched(webapi, { flowId: 'f1', taskId: 't1', currentUserId: 'u1' })
expect(r.actionableTaskCreated).toBe(true)
expect(r.operatorId).toBe('op1')
expect(r.exitCode).toBe(0)
})
it('--auto-authorize POST 404 → 非零退出', async () => {
const webapi = {
getFlowTaskOperatorList: vi.fn().mockResolvedValue([{ id: 'op1', userId: 'u1' }]),
postAuthorize: vi.fn().mockRejectedValue({ status: 404, message: 'Not Found' }),
}
const r = await verifyLaunched(webapi, { flowId: 'f1', taskId: 't1', currentUserId: 'u1', autoAuthorize: true })
expect(r.autoAuthorize).toBe('failed: 404')
expect(r.exitCode).toBe(3)
})
})