diff --git a/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts b/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts index f8f33c8289e..801372da6f1 100644 --- a/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts +++ b/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts @@ -2,8 +2,9 @@ import { getErrorMessage } from '@sim/utils/errors' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { ExecutionContext } from '@/lib/copilot/request/types' -const { executeWorkflowUseCaseMock } = vi.hoisted(() => ({ +const { executeWorkflowUseCaseMock, listUserWorkspacesMock } = vi.hoisted(() => ({ executeWorkflowUseCaseMock: vi.fn(), + listUserWorkspacesMock: vi.fn(), })) vi.mock('@/lib/copilot/application/execute-workflow-use-case', () => ({ @@ -12,7 +13,54 @@ vi.mock('@/lib/copilot/application/execute-workflow-use-case', () => ({ getErrorMessage(error, 'Workflow operation failed'), })) -import { executeGetBlockOutputs } from './queries' +vi.mock('@/lib/workspaces/utils', () => ({ + listUserWorkspaces: listUserWorkspacesMock, +})) + +import { + executeGetBlockOutputs, + executeListUserWorkspaces, +} from '@/lib/copilot/tools/handlers/workflow/queries' + +describe('executeListUserWorkspaces', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('marks the current workspace in the accessible workspace list', async () => { + listUserWorkspacesMock.mockResolvedValue([ + { workspaceId: 'workspace-1', workspaceName: 'One', role: 'owner' }, + { workspaceId: 'workspace-2', workspaceName: 'Two', role: 'read' }, + ]) + + const result = await executeListUserWorkspaces({ + userId: 'user-1', + workflowId: 'workflow-1', + workspaceId: 'workspace-2', + }) + + expect(listUserWorkspacesMock).toHaveBeenCalledWith('user-1') + expect(result).toEqual({ + success: true, + output: { + workspaces: [ + { + workspaceId: 'workspace-1', + workspaceName: 'One', + role: 'owner', + isCurrent: false, + }, + { + workspaceId: 'workspace-2', + workspaceName: 'Two', + role: 'read', + isCurrent: true, + }, + ], + }, + }) + }) +}) describe('executeGetBlockOutputs', () => { beforeEach(() => { diff --git a/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts b/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts index 8861dbc98d6..0291fdee8fc 100644 --- a/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts +++ b/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts @@ -34,7 +34,10 @@ export async function executeListUserWorkspaces( context: ExecutionContext ): Promise { try { - const workspaces = await listUserWorkspaces(context.userId) + const workspaces = (await listUserWorkspaces(context.userId)).map((workspace) => ({ + ...workspace, + isCurrent: workspace.workspaceId === context.workspaceId, + })) return { success: true, output: { workspaces } } } catch (error) {