Add tests for getFlatAppResponses function in chat utils.

This commit is contained in:
gru-agent[bot] 2025-05-25 12:55:13 +00:00 committed by GitHub
parent a8673344b1
commit 3338be6650
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,7 +4,8 @@ import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import type { ChatItemType } from '@fastgpt/global/core/chat/type'; import type { ChatItemType } from '@fastgpt/global/core/chat/type';
import { import {
transformPreviewHistories, transformPreviewHistories,
addStatisticalDataToHistoryItem addStatisticalDataToHistoryItem,
getFlatAppResponses
} from '@/global/core/chat/utils'; } from '@/global/core/chat/utils';
const mockResponseData = { const mockResponseData = {
@ -14,6 +15,70 @@ const mockResponseData = {
moduleType: FlowNodeTypeEnum.chatNode moduleType: FlowNodeTypeEnum.chatNode
}; };
describe('getFlatAppResponses', () => {
it('should return empty array for empty input', () => {
expect(getFlatAppResponses([])).toEqual([]);
});
it('should handle single level responses', () => {
const responses = [
{ ...mockResponseData, moduleType: FlowNodeTypeEnum.chatNode },
{ ...mockResponseData, moduleType: FlowNodeTypeEnum.tools }
];
expect(getFlatAppResponses(responses)).toEqual(responses);
});
it('should handle nested pluginDetail', () => {
const responses = [
{
...mockResponseData,
pluginDetail: [{ ...mockResponseData, moduleType: FlowNodeTypeEnum.tools }]
}
];
expect(getFlatAppResponses(responses)).toHaveLength(2);
});
it('should handle nested toolDetail', () => {
const responses = [
{
...mockResponseData,
toolDetail: [{ ...mockResponseData, moduleType: FlowNodeTypeEnum.chatNode }]
}
];
expect(getFlatAppResponses(responses)).toHaveLength(2);
});
it('should handle nested loopDetail', () => {
const responses = [
{
...mockResponseData,
loopDetail: [{ ...mockResponseData, moduleType: FlowNodeTypeEnum.datasetSearchNode }]
}
];
expect(getFlatAppResponses(responses)).toHaveLength(2);
});
it('should handle multiple levels of nesting', () => {
const responses = [
{
...mockResponseData,
pluginDetail: [
{
...mockResponseData,
toolDetail: [
{
...mockResponseData,
loopDetail: [{ ...mockResponseData }]
}
]
}
]
}
];
expect(getFlatAppResponses(responses)).toHaveLength(4);
});
});
describe('transformPreviewHistories', () => { describe('transformPreviewHistories', () => {
it('should transform histories correctly with responseDetail=true', () => { it('should transform histories correctly with responseDetail=true', () => {
const histories: ChatItemType[] = [ const histories: ChatItemType[] = [