@@ -2,6 +2,15 @@ import type { ApiServices } from './loadMethodRegistry'
22import { getLoadMethod , loadMethodRegistry } from './loadMethodRegistry'
33
44const mockApis : ApiServices = {
5+ chatflowsApi : {
6+ getAllChatflows : jest . fn ( ) ,
7+ getChatflow : jest . fn ( ) ,
8+ createChatflow : jest . fn ( ) ,
9+ updateChatflow : jest . fn ( ) ,
10+ deleteChatflow : jest . fn ( ) ,
11+ generateAgentflow : jest . fn ( ) ,
12+ getChatModels : jest . fn ( )
13+ } ,
514 chatModelsApi : {
615 getChatModels : jest . fn ( )
716 } ,
@@ -159,6 +168,39 @@ describe('loadMethodRegistry', () => {
159168 } )
160169 } )
161170
171+ describe ( 'listFlows' , ( ) => {
172+ it ( 'should call chatflowsApi.getAllChatflows() and map to label/name/description' , async ( ) => {
173+ const mockChatflows = [
174+ { id : 'cf-1' , name : 'My Chatflow' , type : 'CHATFLOW' } ,
175+ { id : 'cf-2' , name : 'My Agentflow' , type : 'AGENTFLOW' } ,
176+ { id : 'cf-3' , name : 'My Multi' , type : 'MULTIAGENT' }
177+ ]
178+ ; ( mockApis . chatflowsApi . getAllChatflows as jest . Mock ) . mockResolvedValue ( mockChatflows )
179+
180+ const result = await loadMethodRegistry [ 'listFlows' ] ( mockApis )
181+ expect ( mockApis . chatflowsApi . getAllChatflows ) . toHaveBeenCalled ( )
182+ expect ( result ) . toEqual ( [
183+ { label : 'My Chatflow' , name : 'cf-1' , description : 'Chatflow' } ,
184+ { label : 'My Agentflow' , name : 'cf-2' , description : 'Agentflow V2' } ,
185+ { label : 'My Multi' , name : 'cf-3' , description : 'Agentflow V1' }
186+ ] )
187+ } )
188+
189+ it ( 'should return empty array when there are no chatflows' , async ( ) => {
190+ ; ( mockApis . chatflowsApi . getAllChatflows as jest . Mock ) . mockResolvedValue ( [ ] )
191+
192+ const result = await loadMethodRegistry [ 'listFlows' ] ( mockApis )
193+ expect ( result ) . toEqual ( [ ] )
194+ } )
195+
196+ it ( 'should fall back to "Chatflow" description for unknown type' , async ( ) => {
197+ ; ( mockApis . chatflowsApi . getAllChatflows as jest . Mock ) . mockResolvedValue ( [ { id : 'cf-1' , name : 'Unknown' , type : 'UNKNOWN' } ] )
198+
199+ const result = await loadMethodRegistry [ 'listFlows' ] ( mockApis )
200+ expect ( result ) . toEqual ( [ { label : 'Unknown' , name : 'cf-1' , description : 'Chatflow' } ] )
201+ } )
202+ } )
203+
162204 describe ( 'listCredentials' , ( ) => {
163205 it ( 'should call credentialsApi.getCredentialsByName() with params.name' , async ( ) => {
164206 const mockCredentials = [ { id : '1' , name : 'My Key' , credentialName : 'openAIApi' } ]
0 commit comments