Files
NetMesh/domain/hostGroupPathMutations.test.ts

48 lines
1.8 KiB
TypeScript
Raw Normal View History

import assert from 'node:assert/strict';
import test from 'node:test';
import {
remapSnippetTargetGroupPaths,
removeSnippetTargetGroupPaths,
} from './hostGroupPathMutations.ts';
import type { Snippet } from './models';
const snippets: Snippet[] = [{
id: 'script-a',
label: 'A',
command: 'echo a',
kind: 'script',
targetGroups: ['Production', 'Production/Web', 'Staging'],
}];
test('remapSnippetTargetGroupPaths follows group rename and descendants', () => {
const next = remapSnippetTargetGroupPaths(snippets, 'Production', 'Platform');
assert.deepEqual(next[0].targetGroups, ['Platform', 'Platform/Web', 'Staging']);
});
test('removeSnippetTargetGroupPaths removes a deleted group subtree', () => {
const next = removeSnippetTargetGroupPaths(snippets, ['Production']);
assert.deepEqual(next[0].targetGroups, ['Staging']);
});
test('removeSnippetTargetGroupPaths preserves an explicit empty scope', () => {
const next = removeSnippetTargetGroupPaths([
{ ...snippets[0], targetGroups: ['Production'] },
], ['Production']);
assert.deepEqual(next[0].targetGroups, []);
});
test('remapSnippetTargetGroupPaths deduplicates rename collisions', () => {
const next = remapSnippetTargetGroupPaths([
{ ...snippets[0], targetGroups: ['Platform', 'Production'] },
], 'Production', 'Platform');
assert.deepEqual(next[0].targetGroups, ['Platform']);
});
test('group path mutations normalize imported legacy paths', () => {
const legacy = [{ ...snippets[0], targetGroups: [' Production\\Web ', 'Production//Web'] }];
const renamed = remapSnippetTargetGroupPaths(legacy, 'Production/Web', 'Platform/Web');
assert.deepEqual(renamed[0].targetGroups, ['Platform/Web']);
const removed = removeSnippetTargetGroupPaths(legacy, ['Production/Web']);
assert.deepEqual(removed[0].targetGroups, []);
});