Skip to main content
Glama
updateConceptScheme.test.ts5.79 kB
import { describe, it, expect, beforeEach } from 'vitest'; import { testConceptScheme, testUpdatedConceptScheme, mockConceptSchemeUpdate, mockCreateClient, } from './mockClient.js'; import { updateConceptSchemeTool } from './updateConceptScheme.js'; import { createClientConfig } from '../../../utils/tools.js'; import { formatResponse } from '../../../utils/formatters.js'; import { createMockConfig } from '../../../test-helpers/mockConfig.js'; describe('updateConceptScheme', () => { const mockConfig = createMockConfig(); beforeEach(() => { mockConceptSchemeUpdate.mockClear(); mockCreateClient.mockClear(); }); const testArgs = { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, prefLabel: { 'en-US': 'Updated Test Concept Scheme', }, }; it('should update a concept scheme successfully', async () => { mockConceptSchemeUpdate.mockResolvedValue(testUpdatedConceptScheme); const tool = updateConceptSchemeTool(mockConfig); const result = await tool(testArgs); const clientConfig = createClientConfig(mockConfig); expect(mockCreateClient).toHaveBeenCalledWith(clientConfig, { type: 'plain', }); expect(mockConceptSchemeUpdate).toHaveBeenCalledWith( { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, }, [ { op: 'replace', path: '/prefLabel', value: { 'en-US': 'Updated Test Concept Scheme', }, }, ], ); const expectedResponse = formatResponse( 'Concept scheme updated successfully', { updatedConceptScheme: testUpdatedConceptScheme, }, ); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should update multiple fields', async () => { const multiFieldArgs = { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, prefLabel: { 'en-US': 'Updated Test Concept Scheme', }, definition: { 'en-US': 'Updated definition', }, uri: 'https://example.com/updated', }; mockConceptSchemeUpdate.mockResolvedValue(testUpdatedConceptScheme); const tool = updateConceptSchemeTool(mockConfig); const result = await tool(multiFieldArgs); expect(mockConceptSchemeUpdate).toHaveBeenCalledWith( { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, }, [ { op: 'replace', path: '/prefLabel', value: { 'en-US': 'Updated Test Concept Scheme', }, }, { op: 'replace', path: '/definition', value: { 'en-US': 'Updated definition', }, }, { op: 'replace', path: '/uri', value: 'https://example.com/updated', }, ], ); const expectedResponse = formatResponse( 'Concept scheme updated successfully', { updatedConceptScheme: testUpdatedConceptScheme, }, ); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should handle URI removal when set to null', async () => { const argsWithNullUri = { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, uri: null, }; mockConceptSchemeUpdate.mockResolvedValue(testConceptScheme); const tool = updateConceptSchemeTool(mockConfig); const result = await tool(argsWithNullUri); expect(mockConceptSchemeUpdate).toHaveBeenCalledWith( { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, }, [ { op: 'remove', path: '/uri', }, ], ); const expectedResponse = formatResponse( 'Concept scheme updated successfully', { updatedConceptScheme: testConceptScheme, }, ); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should handle errors gracefully', async () => { const errorMessage = 'Failed to update concept scheme'; mockConceptSchemeUpdate.mockRejectedValue(new Error(errorMessage)); const tool = updateConceptSchemeTool(mockConfig); const result = await tool(testArgs); expect(result).toEqual({ content: [ { type: 'text', text: `Error updating concept scheme: ${errorMessage}`, }, ], isError: true, }); }); it('should handle empty update (no fields provided)', async () => { const emptyArgs = { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, }; mockConceptSchemeUpdate.mockResolvedValue(testConceptScheme); const tool = updateConceptSchemeTool(mockConfig); const result = await tool(emptyArgs); expect(mockConceptSchemeUpdate).toHaveBeenCalledWith( { organizationId: 'test-org-id', conceptSchemeId: 'test-concept-scheme-id', version: 1, }, [], ); const expectedResponse = formatResponse( 'Concept scheme updated successfully', { updatedConceptScheme: testConceptScheme, }, ); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); });

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/contentful/contentful-mcp-server'

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