54 lines
2.4 KiB
JavaScript
54 lines
2.4 KiB
JavaScript
const { test } = require("node:test");
|
|
const assert = require("node:assert");
|
|
const {
|
|
extractProcessesForStatus,
|
|
matchProcessByLabel,
|
|
classifyAwaitInput,
|
|
} = require("../src/lib/processFlow");
|
|
|
|
const processes = [
|
|
{ Id: 1, Name: "了承", DisplayName: "了承", CurrentStatus: 100, ChangedStatus: 200 },
|
|
{ Id: 2, Name: "日程変更", DisplayName: "日程変更", CurrentStatus: 100, ChangedStatus: 150, ValidateInputs: [{ Id: 1, ColumnName: "Date001", Required: true }] },
|
|
{ Id: 3, Name: "受けた", DisplayName: "受けた", CurrentStatus: 200, ChangedStatus: 300 },
|
|
{ Id: 4, Name: "結果受取り", DisplayName: "受け取った", CurrentStatus: 300, ChangedStatus: 900, ValidateInputs: [{ Id: 1, ColumnName: "AttachmentsA", Required: true }] },
|
|
];
|
|
|
|
test("extractProcessesForStatus: 現在のStatusに一致するProcessのみ返す", () => {
|
|
const result = extractProcessesForStatus(processes, 100);
|
|
assert.strictEqual(result.length, 2);
|
|
assert.deepStrictEqual(result.map((p) => p.Id), [1, 2]);
|
|
});
|
|
|
|
test("extractProcessesForStatus: 一致するProcessが無ければ空配列", () => {
|
|
assert.deepStrictEqual(extractProcessesForStatus(processes, 999), []);
|
|
});
|
|
|
|
test("matchProcessByLabel: DisplayNameが完全一致するProcessを返す", () => {
|
|
const candidates = extractProcessesForStatus(processes, 100);
|
|
const matched = matchProcessByLabel(candidates, "日程変更");
|
|
assert.strictEqual(matched.Id, 2);
|
|
});
|
|
|
|
test("matchProcessByLabel: 前後の空白を無視して一致判定する", () => {
|
|
const candidates = extractProcessesForStatus(processes, 100);
|
|
const matched = matchProcessByLabel(candidates, " 了承 ");
|
|
assert.strictEqual(matched.Id, 1);
|
|
});
|
|
|
|
test("matchProcessByLabel: 一致しなければnull", () => {
|
|
const candidates = extractProcessesForStatus(processes, 100);
|
|
assert.strictEqual(matchProcessByLabel(candidates, "存在しない選択肢"), null);
|
|
});
|
|
|
|
test("classifyAwaitInput: ValidateInputsが無いProcessはnone", () => {
|
|
assert.deepStrictEqual(classifyAwaitInput(processes[0]), { awaitInput: "none", column: null });
|
|
});
|
|
|
|
test("classifyAwaitInput: Date*列はdate", () => {
|
|
assert.deepStrictEqual(classifyAwaitInput(processes[1]), { awaitInput: "date", column: "Date001" });
|
|
});
|
|
|
|
test("classifyAwaitInput: Attachments*列はfile", () => {
|
|
assert.deepStrictEqual(classifyAwaitInput(processes[3]), { awaitInput: "file", column: "AttachmentsA" });
|
|
});
|