115 lines
3.8 KiB
TypeScript
115 lines
3.8 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { mergeDefaultChatTypes, resolveAppConfigByOrigin } from './app-config-service.js';
|
|
|
|
test('mergeDefaultChatTypes preserves saved edits for built-in chat types', () => {
|
|
const merged = mergeDefaultChatTypes([
|
|
{
|
|
id: 'general-request',
|
|
name: '일반 요청',
|
|
description: '사용자가 수정한 일반 요청 문맥',
|
|
permissions: ['guest', 'token-user'],
|
|
enabled: true,
|
|
updatedAt: '2026-04-24T09:00:00.000Z',
|
|
},
|
|
]);
|
|
|
|
const generalRequest = merged.find((item) => item.id === 'general-request');
|
|
|
|
assert.ok(generalRequest);
|
|
assert.equal(generalRequest.description, '사용자가 수정한 일반 요청 문맥');
|
|
assert.deepEqual(generalRequest.permissions, ['guest', 'token-user']);
|
|
});
|
|
|
|
test('mergeDefaultChatTypes preserves saved edits for layout editor execution', () => {
|
|
const merged = mergeDefaultChatTypes([
|
|
{
|
|
id: 'layout-editor-execution',
|
|
name: 'Layout editor 실행',
|
|
description: '호출 가능한 API 요청만 처리합니다.',
|
|
permissions: ['token-user'],
|
|
enabled: true,
|
|
updatedAt: '2026-04-27T00:00:00.000Z',
|
|
},
|
|
]);
|
|
|
|
const layoutEditorExecution = merged.find((item) => item.id === 'layout-editor-execution');
|
|
|
|
assert.ok(layoutEditorExecution);
|
|
assert.equal(layoutEditorExecution.description, '호출 가능한 API 요청만 처리합니다.');
|
|
});
|
|
|
|
test('mergeDefaultChatTypes preserves saved edits for guided layout editor execution', () => {
|
|
const merged = mergeDefaultChatTypes([
|
|
{
|
|
id: 'layout-editor-guided-execution',
|
|
name: 'Layout editor 단계별 실행',
|
|
description: '사용자가 정리한 단계별 Layout 실행 문맥',
|
|
permissions: ['token-user'],
|
|
enabled: true,
|
|
updatedAt: '2026-05-01T09:00:00.000Z',
|
|
},
|
|
]);
|
|
|
|
const guidedLayoutEditorExecution = merged.find((item) => item.id === 'layout-editor-guided-execution');
|
|
|
|
assert.ok(guidedLayoutEditorExecution);
|
|
assert.equal(guidedLayoutEditorExecution.description, '사용자가 정리한 단계별 Layout 실행 문맥');
|
|
});
|
|
|
|
test('mergeDefaultChatTypes still appends missing built-in chat types', () => {
|
|
const merged = mergeDefaultChatTypes([]);
|
|
|
|
assert.ok(merged.some((item) => item.id === 'general-request'));
|
|
assert.ok(merged.some((item) => item.id === 'layout-editor-execution'));
|
|
assert.ok(merged.some((item) => item.id === 'api-request-template'));
|
|
assert.ok(merged.some((item) => item.id === 'general-inquiry'));
|
|
assert.ok(!merged.some((item) => item.id === 'layout-editor-guided-execution'));
|
|
});
|
|
|
|
test('resolveAppConfigByOrigin prefers scoped app config over legacy global config', () => {
|
|
const resolved = resolveAppConfigByOrigin(
|
|
{
|
|
chat: {
|
|
maxContextMessages: 12,
|
|
receiveRoomNotifications: true,
|
|
},
|
|
automation: {
|
|
notifyOnAutomationStart: true,
|
|
},
|
|
scopedAppConfigs: {
|
|
'https://rel.sm-home.cloud': {
|
|
config: {
|
|
chat: {
|
|
receiveRoomNotifications: false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
'https://rel.sm-home.cloud',
|
|
) as {
|
|
chat?: { maxContextMessages?: number; receiveRoomNotifications?: boolean };
|
|
automation?: { notifyOnAutomationStart?: boolean };
|
|
};
|
|
|
|
assert.equal(resolved.chat?.maxContextMessages, 12);
|
|
assert.equal(resolved.chat?.receiveRoomNotifications, false);
|
|
assert.equal(resolved.automation?.notifyOnAutomationStart, true);
|
|
});
|
|
|
|
test('resolveAppConfigByOrigin falls back to legacy global config when scoped config is missing', () => {
|
|
const resolved = resolveAppConfigByOrigin(
|
|
{
|
|
chat: {
|
|
receiveRoomNotifications: true,
|
|
},
|
|
},
|
|
'https://test.sm-home.cloud',
|
|
) as {
|
|
chat?: { receiveRoomNotifications?: boolean };
|
|
};
|
|
|
|
assert.equal(resolved.chat?.receiveRoomNotifications, true);
|
|
});
|