Skip to main content
Glama
publishAiAction.test.ts2.49 kB
import { describe, it, expect, beforeEach, vi } from 'vitest'; import { publishAiActionTool } from './publishAiAction.js'; import { formatResponse } from '../../utils/formatters.js'; import { setupMockClient, mockAiActionGet, mockAiActionPublish, mockAiAction, mockPublishedAiAction, mockArgs, } from './mockClient.js'; import { createMockConfig } from '../../test-helpers/mockConfig.js'; vi.mock('../../../src/utils/tools.js'); describe('publishAiAction', () => { const mockConfig = createMockConfig(); beforeEach(() => { setupMockClient(); }); it('should publish an AI action successfully', async () => { mockAiActionGet.mockResolvedValue(mockAiAction); mockAiActionPublish.mockResolvedValue(mockPublishedAiAction); const tool = publishAiActionTool(mockConfig); const result = await tool(mockArgs); const expectedResponse = formatResponse( 'AI action published successfully', { version: mockPublishedAiAction.sys.publishedVersion, aiActionId: 'test-ai-action-id', }, ); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should handle errors when AI action publishing fails', async () => { const error = new Error('AI action not found'); mockAiActionGet.mockRejectedValue(error); const tool = publishAiActionTool(mockConfig); const result = await tool(mockArgs); const expectedResponse = formatResponse('AI action publish failed', { status: error, aiActionId: 'test-ai-action-id', }); expect(result).toEqual({ content: [ { type: 'text', text: expectedResponse, }, ], }); }); it('should handle publishing an already published AI action', async () => { // This should still succeed and return the published version mockAiActionGet.mockResolvedValue(mockAiAction); mockAiActionPublish.mockResolvedValue(mockPublishedAiAction); const tool = publishAiActionTool(mockConfig); const result = await tool(mockArgs); const expectedResponse = formatResponse( 'AI action published successfully', { version: mockPublishedAiAction.sys.publishedVersion, aiActionId: 'test-ai-action-id', }, ); 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