feat: Process抽出・回答照合・追加入力判定ロジックを追加
This commit is contained in:
parent
0405c3a089
commit
20396f465d
30
NodeSrv/apps/healthcheck-survey-bot/src/lib/processFlow.js
Normal file
30
NodeSrv/apps/healthcheck-survey-bot/src/lib/processFlow.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
function extractProcessesForStatus(processes, status) {
|
||||||
|
return processes.filter((p) => p.CurrentStatus === status || p.CurrentStatus === -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchProcessByLabel(processes, text) {
|
||||||
|
const trimmed = String(text ?? "").trim();
|
||||||
|
return processes.find((p) => (p.DisplayName || p.Name) === trimmed) || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getValidationColumnNames(process) {
|
||||||
|
if (!Array.isArray(process.ValidateInputs)) return [];
|
||||||
|
return process.ValidateInputs.map((v) => v.ColumnName).filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
function classifyAwaitInput(process) {
|
||||||
|
const columnNames = getValidationColumnNames(process);
|
||||||
|
if (columnNames.length === 0) {
|
||||||
|
return { awaitInput: "none", column: null };
|
||||||
|
}
|
||||||
|
const column = columnNames[0];
|
||||||
|
if (column.startsWith("Date")) {
|
||||||
|
return { awaitInput: "date", column };
|
||||||
|
}
|
||||||
|
if (column.startsWith("Attachments")) {
|
||||||
|
return { awaitInput: "file", column };
|
||||||
|
}
|
||||||
|
return { awaitInput: "none", column: null };
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { extractProcessesForStatus, matchProcessByLabel, classifyAwaitInput };
|
||||||
53
NodeSrv/apps/healthcheck-survey-bot/test/processFlow.test.js
Normal file
53
NodeSrv/apps/healthcheck-survey-bot/test/processFlow.test.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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" });
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user