UNPKG

@tiberriver256/mcp-server-azure-devops

Version:

Azure DevOps reference server for the Model Context Protocol (MCP)

122 lines 5.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); const feature_1 = require("./list-pipelines/feature"); const feature_2 = require("./get-pipeline/feature"); const feature_3 = require("./trigger-pipeline/feature"); jest.mock('./list-pipelines/feature'); jest.mock('./get-pipeline/feature'); jest.mock('./trigger-pipeline/feature'); describe('Pipelines Request Handlers', () => { const mockConnection = {}; describe('isPipelinesRequest', () => { it('should return true for pipelines requests', () => { const validTools = ['list_pipelines', 'get_pipeline', 'trigger_pipeline']; validTools.forEach((tool) => { const request = { params: { name: tool, arguments: {} }, method: 'tools/call', }; expect((0, index_1.isPipelinesRequest)(request)).toBe(true); }); }); it('should return false for non-pipelines requests', () => { const request = { params: { name: 'get_project', arguments: {} }, method: 'tools/call', }; expect((0, index_1.isPipelinesRequest)(request)).toBe(false); }); }); describe('handlePipelinesRequest', () => { it('should handle list_pipelines request', async () => { const mockPipelines = [ { id: 1, name: 'Pipeline 1' }, { id: 2, name: 'Pipeline 2' }, ]; feature_1.listPipelines.mockResolvedValue(mockPipelines); const request = { params: { name: 'list_pipelines', arguments: { projectId: 'test-project', }, }, method: 'tools/call', }; const response = await (0, index_1.handlePipelinesRequest)(mockConnection, request); expect(response.content).toHaveLength(1); expect(JSON.parse(response.content[0].text)).toEqual(mockPipelines); expect(feature_1.listPipelines).toHaveBeenCalledWith(mockConnection, expect.objectContaining({ projectId: 'test-project', })); }); it('should handle get_pipeline request', async () => { const mockPipeline = { id: 1, name: 'Pipeline 1' }; feature_2.getPipeline.mockResolvedValue(mockPipeline); const request = { params: { name: 'get_pipeline', arguments: { projectId: 'test-project', pipelineId: 1, }, }, method: 'tools/call', }; const response = await (0, index_1.handlePipelinesRequest)(mockConnection, request); expect(response.content).toHaveLength(1); expect(JSON.parse(response.content[0].text)).toEqual(mockPipeline); expect(feature_2.getPipeline).toHaveBeenCalledWith(mockConnection, expect.objectContaining({ projectId: 'test-project', pipelineId: 1, })); }); it('should handle trigger_pipeline request', async () => { const mockRun = { id: 1, state: 'inProgress' }; feature_3.triggerPipeline.mockResolvedValue(mockRun); const request = { params: { name: 'trigger_pipeline', arguments: { projectId: 'test-project', pipelineId: 1, }, }, method: 'tools/call', }; const response = await (0, index_1.handlePipelinesRequest)(mockConnection, request); expect(response.content).toHaveLength(1); expect(JSON.parse(response.content[0].text)).toEqual(mockRun); expect(feature_3.triggerPipeline).toHaveBeenCalledWith(mockConnection, expect.objectContaining({ projectId: 'test-project', pipelineId: 1, })); }); it('should throw error for unknown tool', async () => { const request = { params: { name: 'unknown_tool', arguments: {}, }, method: 'tools/call', }; await expect((0, index_1.handlePipelinesRequest)(mockConnection, request)).rejects.toThrow('Unknown pipelines tool'); }); it('should propagate errors from pipeline functions', async () => { const mockError = new Error('Test error'); feature_1.listPipelines.mockRejectedValue(mockError); const request = { params: { name: 'list_pipelines', arguments: { projectId: 'test-project', }, }, method: 'tools/call', }; await expect((0, index_1.handlePipelinesRequest)(mockConnection, request)).rejects.toThrow(mockError); }); }); }); //# sourceMappingURL=index.spec.unit.js.map