Skip to main content
Glama
updateAiAction.test.ts3.22 kB
import { describe, it, expect, beforeEach, vi } from 'vitest'; import { updateAiActionTool } from './updateAiAction.js'; import { formatResponse } from '../../utils/formatters.js'; import { VariableType } from '../../utils/ai-actions.js'; import { setupMockClient, mockAiActionUpdate, mockAiAction, mockArgs, } from './mockClient.js'; import { createMockConfig } from '../../test-helpers/mockConfig.js'; vi.mock('../../../src/utils/tools.js'); describe('updateAiAction', () => { const mockConfig = createMockConfig(); beforeEach(() => { setupMockClient(); }); it('should update an AI action successfully with all fields', async () => { const testArgs = { ...mockArgs, name: 'Updated AI Action', description: 'Updated description', instruction: { template: 'Updated template: {{var.input}}', variables: [ { id: 'input', name: 'Input Text', type: VariableType.TEXT, description: 'Text to process', }, ], }, configuration: { modelType: 'gpt-4-turbo', modelTemperature: 0.2, }, testCases: [ { name: 'Updated test case', variables: { input: 'test input', }, }, ], }; const updatedAiAction = { ...mockAiAction, name: 'Updated AI Action', description: 'Updated description', instruction: testArgs.instruction, configuration: testArgs.configuration, testCases: testArgs.testCases, }; mockAiActionUpdate.mockResolvedValue(updatedAiAction); const tool = updateAiActionTool(mockConfig); const result = await tool(testArgs); const expectedResponse = formatResponse('AI action updated successfully', { updatedAiAction: updatedAiAction, }); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should update only specific fields when provided', async () => { const testArgs = { ...mockArgs, name: 'New Name Only', }; const updatedAiAction = { ...mockAiAction, name: 'New Name Only', }; mockAiActionUpdate.mockResolvedValue(updatedAiAction); const tool = updateAiActionTool(mockConfig); const result = await tool(testArgs); const expectedResponse = formatResponse('AI action updated successfully', { updatedAiAction: updatedAiAction, }); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should handle errors when AI action update fails', async () => { const testArgs = { ...mockArgs, name: 'Invalid Update', }; const error = new Error('AI action not found'); mockAiActionUpdate.mockRejectedValue(error); const tool = updateAiActionTool(mockConfig); const result = await tool(testArgs); expect(result).toEqual({ isError: true, content: [ { type: 'text', text: 'Error updating AI action: AI action not found', }, ], }); }); });

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