Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const {
getEffectiveBlockOutputPathsMock,
hasTriggerCapabilityMock,
getBlockMock,
listUserWorkspacesMock,
} = vi.hoisted(() => ({
ensureWorkflowAccessMock: vi.fn(),
getEffectiveBlockOutputPathsMock: vi.fn(),
hasTriggerCapabilityMock: vi.fn(),
getBlockMock: vi.fn(),
listUserWorkspacesMock: vi.fn(),
}))

const loadWorkflowFromNormalizedTablesMock =
Expand Down Expand Up @@ -44,7 +46,54 @@ vi.mock('@/blocks/registry', () => ({

vi.mock('@/lib/workflows/utils', () => workflowsUtilsMock)

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(() => {
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/lib/copilot/tools/handlers/workflow/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export async function executeListUserWorkspaces(
context: ExecutionContext
): Promise<ToolCallResult> {
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) {
Expand Down
Loading