ken_nogi/NodeSrv/apps/app-portal/test/n8nTree.test.js
Kenichiro NOGI eca5c84c39 feat(app-portal): n8nワークフローのフォルダ構造・実行ログ閲覧ページを追加
n8nのフォルダ/ワークフロー構成をそのままapp-portal(/n8n)に反映し、
Webhookトリガーに限らず任意のワークフローの実行履歴・ノード単位の
成功/失敗・エラー内容を確認できるようにした(get-voice-mail専用にせず
n8n Public API経由で動的取得する汎用設計)。TDDで実装、テスト23件追加。
2026-09-19 12:19:27 +09:00

66 lines
2.6 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert');
const { buildFolderTree } = require('../src/n8nTree');
test('buildFolderTree returns an empty array when there are no folders or workflows', () => {
assert.deepStrictEqual(buildFolderTree([], []), []);
});
test('buildFolderTree places root-level workflows (no parentFolder) directly at the top', () => {
const workflows = [{ id: 'w1', name: 'ワークフローA', active: true, parentFolder: null }];
const tree = buildFolderTree([], workflows);
assert.deepStrictEqual(tree, [{ type: 'workflow', id: 'w1', name: 'ワークフローA', active: true }]);
});
test('buildFolderTree places root-level folders (no parentFolderId) at the top with empty children', () => {
const folders = [{ id: 'f1', name: 'フォルダA', parentFolderId: null }];
const tree = buildFolderTree(folders, []);
assert.deepStrictEqual(tree, [{ type: 'folder', id: 'f1', name: 'フォルダA', children: [] }]);
});
test('buildFolderTree nests a workflow inside its parent folder', () => {
const folders = [{ id: 'f1', name: 'フォルダA', parentFolderId: null }];
const workflows = [{ id: 'w1', name: 'ワークフローA', active: false, parentFolder: { id: 'f1' } }];
const tree = buildFolderTree(folders, workflows);
assert.deepStrictEqual(tree, [
{
type: 'folder',
id: 'f1',
name: 'フォルダA',
children: [{ type: 'workflow', id: 'w1', name: 'ワークフローA', active: false }],
},
]);
});
test('buildFolderTree nests a sub-folder inside its parent folder', () => {
const folders = [
{ id: 'f1', name: '親フォルダ', parentFolderId: null },
{ id: 'f2', name: '子フォルダ', parentFolderId: 'f1' },
];
const tree = buildFolderTree(folders, []);
assert.deepStrictEqual(tree, [
{
type: 'folder',
id: 'f1',
name: '親フォルダ',
children: [{ type: 'folder', id: 'f2', name: '子フォルダ', children: [] }],
},
]);
});
test('buildFolderTree sorts folders before workflows, each alphabetically by name', () => {
const folders = [
{ id: 'f2', name: 'Zフォルダ', parentFolderId: null },
{ id: 'f1', name: 'Aフォルダ', parentFolderId: null },
];
const workflows = [
{ id: 'w2', name: 'Zワークフロー', active: true, parentFolder: null },
{ id: 'w1', name: 'Aワークフロー', active: true, parentFolder: null },
];
const tree = buildFolderTree(folders, workflows);
assert.deepStrictEqual(
tree.map((n) => n.name),
['Aフォルダ', 'Zフォルダ', 'Aワークフロー', 'Zワークフロー']
);
});