@tiberriver256/mcp-server-azure-devops
Version:
Azure DevOps reference server for the Model Context Protocol (MCP)
83 lines • 3.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("../../../shared/errors");
const feature_1 = require("./feature");
// Mock the Azure DevOps WebApi
jest.mock('azure-devops-node-api');
describe('getWikis unit', () => {
// Mock WikiApi client
const mockWikiApi = {
getAllWikis: jest.fn(),
};
// Mock WebApi connection
const mockConnection = {
getWikiApi: jest.fn().mockResolvedValue(mockWikiApi),
};
beforeEach(() => {
// Clear mock calls between tests
jest.clearAllMocks();
});
test('should return wikis for a project', async () => {
// Mock data
const mockWikis = [
{
id: 'wiki1',
name: 'Project Wiki',
mappedPath: '/',
remoteUrl: 'https://example.com/wiki1',
url: 'https://dev.azure.com/org/project/_wiki/wikis/wiki1',
},
{
id: 'wiki2',
name: 'Code Wiki',
mappedPath: '/docs',
remoteUrl: 'https://example.com/wiki2',
url: 'https://dev.azure.com/org/project/_wiki/wikis/wiki2',
},
];
// Setup mock responses
mockWikiApi.getAllWikis.mockResolvedValue(mockWikis);
// Call the function
const result = await (0, feature_1.getWikis)(mockConnection, {
projectId: 'testProject',
});
// Assertions
expect(mockConnection.getWikiApi).toHaveBeenCalledTimes(1);
expect(mockWikiApi.getAllWikis).toHaveBeenCalledWith('testProject');
expect(result).toEqual(mockWikis);
expect(result.length).toBe(2);
});
test('should return empty array when no wikis are found', async () => {
// Setup mock responses
mockWikiApi.getAllWikis.mockResolvedValue([]);
// Call the function
const result = await (0, feature_1.getWikis)(mockConnection, {
projectId: 'projectWithNoWikis',
});
// Assertions
expect(mockConnection.getWikiApi).toHaveBeenCalledTimes(1);
expect(mockWikiApi.getAllWikis).toHaveBeenCalledWith('projectWithNoWikis');
expect(result).toEqual([]);
});
test('should handle API errors gracefully', async () => {
// Setup mock to throw an error
const mockError = new Error('API error occurred');
mockWikiApi.getAllWikis.mockRejectedValue(mockError);
// Call the function and expect it to throw
await expect((0, feature_1.getWikis)(mockConnection, { projectId: 'testProject' })).rejects.toThrow(errors_1.AzureDevOpsError);
// Assertions
expect(mockConnection.getWikiApi).toHaveBeenCalledTimes(1);
expect(mockWikiApi.getAllWikis).toHaveBeenCalledWith('testProject');
});
test('should throw ResourceNotFoundError for non-existent project', async () => {
// Setup mock to throw an error with specific resource not found message
const mockError = new Error('The resource cannot be found');
mockWikiApi.getAllWikis.mockRejectedValue(mockError);
// Call the function and expect it to throw a specific error type
await expect((0, feature_1.getWikis)(mockConnection, { projectId: 'nonExistentProject' })).rejects.toThrow(errors_1.AzureDevOpsResourceNotFoundError);
// Assertions
expect(mockConnection.getWikiApi).toHaveBeenCalledTimes(1);
expect(mockWikiApi.getAllWikis).toHaveBeenCalledWith('nonExistentProject');
});
});
//# sourceMappingURL=feature.spec.unit.js.map