ken_nogi/NodeSrv/apps/app-portal/test/n8nTree.test.js
Kenichiro NOGI 041a5e454c refactor(app-portal): n8nワークフロー分類をフォルダからタグベースに変更
n8n Public APIはworkflow.parentFolderIdがwriteOnlyでフォルダ→ワークフロー
対応を読み取れない仕様上の制約が判明したため、フォルダ階層表示を断念し
タグ単位のフラットなグルーピング(未分類は最後)に切り替えた。n8n側は
既存6フォルダ相当のタグを作成、44ワークフローへ割当済み。
2026-09-19 13:58:10 +09:00

58 lines
2.0 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert');
const { buildTagTree } = require('../src/n8nTree');
test('buildTagTree returns an empty array when there are no workflows', () => {
assert.deepStrictEqual(buildTagTree([]), []);
});
test('buildTagTree groups a workflow under its tag name', () => {
const workflows = [{ id: 'w1', name: 'ワークフローA', active: true, tags: [{ name: 'タグA' }] }];
const tree = buildTagTree(workflows);
assert.deepStrictEqual(tree, [
{
type: 'folder',
id: 'タグA',
name: 'タグA',
children: [{ type: 'workflow', id: 'w1', name: 'ワークフローA', active: true }],
},
]);
});
test('buildTagTree puts untagged workflows into a "未分類" group', () => {
const workflows = [{ id: 'w1', name: 'ワークフローA', active: true, tags: [] }];
const tree = buildTagTree(workflows);
assert.deepStrictEqual(tree, [
{
type: 'folder',
id: '__untagged__',
name: '未分類',
children: [{ type: 'workflow', id: 'w1', name: 'ワークフローA', active: true }],
},
]);
});
test('buildTagTree puts a multi-tagged workflow into every one of its tag groups', () => {
const workflows = [{ id: 'w1', name: 'ワークフローA', active: true, tags: [{ name: 'タグA' }, { name: 'タグB' }] }];
const tree = buildTagTree(workflows);
assert.deepStrictEqual(
tree.map((g) => g.name),
['タグA', 'タグB']
);
assert.strictEqual(tree[0].children.length, 1);
assert.strictEqual(tree[1].children.length, 1);
});
test('buildTagTree sorts tag groups alphabetically and puts "未分類" last', () => {
const workflows = [
{ id: 'w1', name: 'A', active: true, tags: [{ name: 'Zタグ' }] },
{ id: 'w2', name: 'B', active: true, tags: [] },
{ id: 'w3', name: 'C', active: true, tags: [{ name: 'Aタグ' }] },
];
const tree = buildTagTree(workflows);
assert.deepStrictEqual(
tree.map((g) => g.name),
['Aタグ', 'Zタグ', '未分類']
);
});