186 lines
6.4 KiB
TypeScript
186 lines
6.4 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import {
|
|
SYSTEM_WORKFLOW_ACTION_ENUMS,
|
|
translateWorkflowAction,
|
|
isWorkflowActionCode,
|
|
matchWorkflowAction,
|
|
resolveWorkflowEnumOptions,
|
|
} from "../services.js";
|
|
import { analyzeWorkflow } from "./analysis/index.js";
|
|
|
|
describe("Workflow Action Enums & Diagnostics", () => {
|
|
it("contains 18 standard system notification action enums", () => {
|
|
expect(SYSTEM_WORKFLOW_ACTION_ENUMS).toHaveLength(18);
|
|
const codes = SYSTEM_WORKFLOW_ACTION_ENUMS.map((item) => item.code);
|
|
expect(codes).toContain("flow.rejected");
|
|
expect(codes).toContain("flow.paid");
|
|
expect(codes).toContain("backlog.approving");
|
|
expect(codes).toContain("backlog.paying");
|
|
expect(codes).toContain("backlog.receiving");
|
|
expect(codes).toContain("freeflow.retract");
|
|
});
|
|
|
|
it("translates workflow action codes accurately", () => {
|
|
expect(translateWorkflowAction("flow.rejected")).toBe("被驳回");
|
|
expect(translateWorkflowAction("flow.paid")).toBe("已支付/审批完成");
|
|
expect(translateWorkflowAction("backlog.approving")).toBe("待审批");
|
|
expect(translateWorkflowAction("unknown.action")).toBe("unknown.action");
|
|
expect(translateWorkflowAction(undefined)).toBeUndefined();
|
|
});
|
|
|
|
it("checks if a code is a known workflow action", () => {
|
|
expect(isWorkflowActionCode("flow.rejected")).toBe(true);
|
|
expect(isWorkflowActionCode("flow.paid")).toBe(true);
|
|
expect(isWorkflowActionCode("custom.action")).toBe(false);
|
|
});
|
|
|
|
it("matches workflow action by code or label", () => {
|
|
const matchByLabel = matchWorkflowAction("被驳回");
|
|
expect(matchByLabel?.code).toBe("flow.rejected");
|
|
|
|
const matchByCode = matchWorkflowAction("flow.rejected");
|
|
expect(matchByCode?.label).toBe("被驳回");
|
|
|
|
expect(matchWorkflowAction("不存在的动作")).toBeUndefined();
|
|
});
|
|
|
|
it("resolves fallback options when client is undefined", async () => {
|
|
const options = await resolveWorkflowEnumOptions(undefined, "action");
|
|
expect(options).toHaveLength(18);
|
|
expect(options.find((o) => o.code === "flow.rejected")?.label).toBe("被驳回");
|
|
});
|
|
|
|
it("detects DEADLOCK_CONDITION_STATE_FILTER when condition matches state against '被驳回'", () => {
|
|
const wf = {
|
|
id: "wf-cond-deadlock",
|
|
label: "单据条件判断",
|
|
state: 1,
|
|
version: "1",
|
|
tasks: [
|
|
{
|
|
name: "trigger_1",
|
|
type: "ekuaibao-flowform-trigger",
|
|
label: "单据审批事件触发器",
|
|
},
|
|
{
|
|
name: "control_1",
|
|
type: "condition",
|
|
label: "条件节点",
|
|
combineFilters: {
|
|
condition: "or",
|
|
filters: [
|
|
{
|
|
condition: "and",
|
|
filters: [
|
|
{
|
|
key: "@{choose('{\"key\":\"trigger_1\",\"properties\":[{\"key\":\"state\",\"label\":\"审批状态\",\"type\":\"TEXT\"}],\"label\":\"单据审批事件触发器.审批状态\"}')}",
|
|
compare: "eq",
|
|
value: "被驳回",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
tasks: [
|
|
{
|
|
name: "stop_1",
|
|
type: "stop",
|
|
label: "终止",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = analyzeWorkflow(wf as any);
|
|
const codes = result.diagnostics.map((d) => d.code);
|
|
expect(codes).toContain("DEADLOCK_CONDITION_STATE_FILTER");
|
|
const diag = result.diagnostics.find((d) => d.code === "DEADLOCK_CONDITION_STATE_FILTER");
|
|
expect(diag?.severity).toBe("error");
|
|
expect(diag?.message).toContain("单据审批状态 [state]");
|
|
expect(diag?.message).toContain("flow.rejected");
|
|
});
|
|
|
|
it("detects INVALID_ACTION_ENUM_TEXT_VALUE when condition matches action with plain text '被驳回'", () => {
|
|
const wf = {
|
|
id: "wf-action-text",
|
|
label: "单据通知类型错误文本比较",
|
|
state: 1,
|
|
version: "1",
|
|
tasks: [
|
|
{
|
|
name: "control_2",
|
|
type: "condition",
|
|
label: "条件节点",
|
|
combineFilters: {
|
|
condition: "or",
|
|
filters: [
|
|
{
|
|
condition: "and",
|
|
filters: [
|
|
{
|
|
key: "@{choose('{\"key\":\"trigger_1\",\"properties\":[{\"key\":\"action\",\"label\":\"通知类型\",\"type\":\"ENUM\",\"thirdId\":\"action\"}],\"label\":\"单据审批事件触发器.通知类型\"}')}",
|
|
compare: "eq",
|
|
value: "被驳回",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
tasks: [],
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = analyzeWorkflow(wf as any);
|
|
const codes = result.diagnostics.map((d) => d.code);
|
|
expect(codes).toContain("INVALID_ACTION_ENUM_TEXT_VALUE");
|
|
const diag = result.diagnostics.find((d) => d.code === "INVALID_ACTION_ENUM_TEXT_VALUE");
|
|
expect(diag?.severity).toBe("error");
|
|
expect(diag?.message).toContain("纯文本");
|
|
});
|
|
|
|
it("passes cleanly when condition correctly uses action enum macro @value(flow.rejected)", () => {
|
|
const wf = {
|
|
id: "wf-valid-action",
|
|
label: "单据通知类型正确配置",
|
|
state: 1,
|
|
version: "1",
|
|
tasks: [
|
|
{
|
|
name: "control_3",
|
|
type: "condition",
|
|
label: "条件节点",
|
|
combineFilters: {
|
|
condition: "or",
|
|
filters: [
|
|
{
|
|
condition: "and",
|
|
filters: [
|
|
{
|
|
key: "@{choose('{\"key\":\"trigger_1\",\"properties\":[{\"key\":\"action\",\"label\":\"通知类型\",\"type\":\"ENUM\",\"thirdId\":\"action\"}],\"label\":\"单据审批事件触发器.通知类型\"}')}",
|
|
compare: "eq",
|
|
value: "@{value('{\"key\":\"flow.rejected\",\"label\":\"被驳回\"}')}",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
tasks: [
|
|
{
|
|
name: "stop_1",
|
|
type: "stop",
|
|
label: "终止",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
const result = analyzeWorkflow(wf as any);
|
|
const codes = result.diagnostics.map((d) => d.code);
|
|
expect(codes).not.toContain("DEADLOCK_CONDITION_STATE_FILTER");
|
|
expect(codes).not.toContain("INVALID_ACTION_ENUM_TEXT_VALUE");
|
|
});
|
|
});
|