Skip to main content
Glama
workspace-tool.test.ts3.29 kB
import { WorkspaceManagementTool } from '../workspace-tool'; import { WorkspaceService } from '../../services'; import { TallyWorkspacesResponse, TallyWorkspace } from '../../models'; jest.mock('../../services'); const MockedWorkspaceService = WorkspaceService as jest.MockedClass<typeof WorkspaceService>; const mockWorkspacesResponse: TallyWorkspacesResponse = { workspaces: [ { id: 'ws1', name: 'Workspace 1', slug: 'ws1', createdAt: '', updatedAt: '' }, ], page: 1, limit: 50, hasMore: false, }; const mockWorkspace: TallyWorkspace = { id: 'ws1', name: 'Workspace 1', slug: 'ws1', createdAt: '', updatedAt: '' }; describe('WorkspaceManagementTool', () => { let tool: WorkspaceManagementTool; let service: jest.Mocked<WorkspaceService>; beforeEach(() => { MockedWorkspaceService.mockClear(); MockedWorkspaceService.prototype.getWorkspaces = jest.fn().mockResolvedValue(mockWorkspacesResponse); MockedWorkspaceService.prototype.getWorkspace = jest.fn().mockResolvedValue(mockWorkspace); tool = new WorkspaceManagementTool(); service = MockedWorkspaceService.mock.instances[0] as jest.Mocked<WorkspaceService>; }); describe('listWorkspaces', () => { it('should call WorkspaceService.getWorkspaces and return the result', async () => { const options = { page: 2, limit: 10 }; const result = await tool.listWorkspaces(options); expect(service.getWorkspaces).toHaveBeenCalledWith(options); expect(result).toEqual(mockWorkspacesResponse); }); }); describe('getWorkspaceDetails', () => { it('should call WorkspaceService.getWorkspace and return the result', async () => { const workspaceId = 'ws1'; const result = await tool.getWorkspaceDetails(workspaceId); expect(service.getWorkspace).toHaveBeenCalledWith(workspaceId); expect(result).toEqual(mockWorkspace); }); }); describe('inviteUserToWorkspace', () => { it('should call WorkspaceService.inviteUser with the correct parameters', async () => { const workspaceId = 'ws1'; const email = 'test@example.com'; const role = 'member'; await tool.inviteUserToWorkspace(workspaceId, email, role); expect(service.inviteUser).toHaveBeenCalledWith(workspaceId, email, role); }); }); describe('removeUserFromWorkspace', () => { it('should call WorkspaceService.removeUser with the correct parameters', async () => { const workspaceId = 'ws1'; const userId = 'user1'; await tool.removeUserFromWorkspace(workspaceId, userId); expect(service.removeUser).toHaveBeenCalledWith(workspaceId, userId); }); }); describe('updateUserRoleInWorkspace', () => { it('should call WorkspaceService.updateUserRole with the correct parameters', async () => { const workspaceId = 'ws1'; const userId = 'user1'; const role = 'admin'; await tool.updateUserRoleInWorkspace(workspaceId, userId, role); expect(service.updateUserRole).toHaveBeenCalledWith(workspaceId, userId, role); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/learnwithcc/tally-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server