Skip to content

Commit c7bfb61

Browse files
committed
Merge list_user_workspaces dependency
2 parents 88b4f4c + debb153 commit c7bfb61

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ const {
1111
getEffectiveBlockOutputPathsMock,
1212
hasTriggerCapabilityMock,
1313
getBlockMock,
14+
listUserWorkspacesMock,
1415
} = vi.hoisted(() => ({
1516
ensureWorkflowAccessMock: vi.fn(),
1617
getEffectiveBlockOutputPathsMock: vi.fn(),
1718
hasTriggerCapabilityMock: vi.fn(),
1819
getBlockMock: vi.fn(),
20+
listUserWorkspacesMock: vi.fn(),
1921
}))
2022

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

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

47-
import { executeGetBlockOutputs } from './queries'
49+
vi.mock('@/lib/workspaces/utils', () => ({
50+
listUserWorkspaces: listUserWorkspacesMock,
51+
}))
52+
53+
import {
54+
executeGetBlockOutputs,
55+
executeListUserWorkspaces,
56+
} from '@/lib/copilot/tools/handlers/workflow/queries'
57+
58+
describe('executeListUserWorkspaces', () => {
59+
beforeEach(() => {
60+
vi.clearAllMocks()
61+
})
62+
63+
it('marks the current workspace in the accessible workspace list', async () => {
64+
listUserWorkspacesMock.mockResolvedValue([
65+
{ workspaceId: 'workspace-1', workspaceName: 'One', role: 'owner' },
66+
{ workspaceId: 'workspace-2', workspaceName: 'Two', role: 'read' },
67+
])
68+
69+
const result = await executeListUserWorkspaces({
70+
userId: 'user-1',
71+
workflowId: 'workflow-1',
72+
workspaceId: 'workspace-2',
73+
})
74+
75+
expect(listUserWorkspacesMock).toHaveBeenCalledWith('user-1')
76+
expect(result).toEqual({
77+
success: true,
78+
output: {
79+
workspaces: [
80+
{
81+
workspaceId: 'workspace-1',
82+
workspaceName: 'One',
83+
role: 'owner',
84+
isCurrent: false,
85+
},
86+
{
87+
workspaceId: 'workspace-2',
88+
workspaceName: 'Two',
89+
role: 'read',
90+
isCurrent: true,
91+
},
92+
],
93+
},
94+
})
95+
})
96+
})
4897

4998
describe('executeGetBlockOutputs', () => {
5099
beforeEach(() => {

apps/sim/lib/copilot/tools/handlers/workflow/queries.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ export async function executeListUserWorkspaces(
3232
context: ExecutionContext
3333
): Promise<ToolCallResult> {
3434
try {
35-
const workspaces = await listUserWorkspaces(context.userId)
35+
const workspaces = (await listUserWorkspaces(context.userId)).map((workspace) => ({
36+
...workspace,
37+
isCurrent: workspace.workspaceId === context.workspaceId,
38+
}))
3639

3740
return { success: true, output: { workspaces } }
3841
} catch (error) {

0 commit comments

Comments
 (0)