diff --git a/test/cases/global/core/chat/utils.test.ts b/test/cases/global/core/chat/utils.test.ts index e0cbca21a..8c0340636 100644 --- a/test/cases/global/core/chat/utils.test.ts +++ b/test/cases/global/core/chat/utils.test.ts @@ -4,7 +4,8 @@ import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import type { ChatItemType } from '@fastgpt/global/core/chat/type'; import { transformPreviewHistories, - addStatisticalDataToHistoryItem + addStatisticalDataToHistoryItem, + getFlatAppResponses } from '@/global/core/chat/utils'; const mockResponseData = { @@ -14,6 +15,70 @@ const mockResponseData = { 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', () => { it('should transform histories correctly with responseDetail=true', () => { const histories: ChatItemType[] = [