mcp-cisco-support
Version:
MCP server for Cisco Support APIs including Bug Search and future tools
256 lines • 13.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const mcp_server_1 = require("../src/mcp-server");
const mockData_1 = require("./mockData");
const setup_1 = require("./setup");
// Skip this entire test suite if mockFetch is unavailable (integration test mode)
const isIntegrationMode = !setup_1.mockFetch;
(isIntegrationMode ? describe.skip : describe)('Cisco Bug API Tools', () => {
beforeEach(() => {
jest.clearAllMocks();
// Default successful OAuth response
setup_1.mockFetch.mockImplementation((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse),
text: () => Promise.resolve(JSON.stringify(mockData_1.mockOAuthResponse))
});
}
// Default API response
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse),
text: () => Promise.resolve(JSON.stringify(mockData_1.mockBugResponse))
});
});
});
describe('Tool Discovery', () => {
test('should list all available Bug API tools', () => {
const tools = (0, mcp_server_1.getAvailableTools)();
const bugTools = tools.filter(tool => tool.name.startsWith('get_bug_') || tool.name.startsWith('search_bugs_'));
expect(bugTools).toHaveLength(8);
expect(bugTools.map(t => t.name)).toEqual([
'get_bug_details',
'search_bugs_by_keyword',
'search_bugs_by_product_id',
'search_bugs_by_product_and_release',
'search_bugs_by_product_series_affected',
'search_bugs_by_product_series_fixed',
'search_bugs_by_product_name_affected',
'search_bugs_by_product_name_fixed'
]);
});
test('should have proper input schemas for all tools', () => {
const tools = (0, mcp_server_1.getAvailableTools)();
const bugTools = tools.filter(tool => tool.name.startsWith('get_bug_') || tool.name.startsWith('search_bugs_'));
bugTools.forEach(tool => {
expect(tool.inputSchema).toBeDefined();
expect(tool.inputSchema.type).toBe('object');
expect(tool.inputSchema.properties).toBeDefined();
expect(tool.inputSchema.required).toBeDefined();
});
});
});
describe('get_bug_details', () => {
test('should fetch details for specific bug IDs', async () => {
setup_1.mockFetch.mockImplementation((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/bug_ids/CSCvi12345');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockSingleBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('get_bug_details', mockData_1.testCases.get_bug_details.valid);
expect(result.bugs).toHaveLength(1);
expect(result.bugs[0].bug_id).toBe('CSCvi12345');
});
test('should handle missing required bug_ids parameter', async () => {
await expect((0, mcp_server_1.executeTool)('get_bug_details', {})).rejects.toThrow('Missing required field: bug_ids');
});
test('should handle empty bug_ids parameter', async () => {
await expect((0, mcp_server_1.executeTool)('get_bug_details', { bug_ids: '' })).rejects.toThrow('Missing required field: bug_ids');
});
});
describe('search_bugs_by_keyword', () => {
test('should search bugs by keyword with all parameters', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/keyword/CallManager%2012.5');
expect(url).toContain('severity=3');
expect(url).toContain('status=O');
expect(url).toContain('modified_date=2');
expect(url).toContain('page_index=1');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_keyword', mockData_1.testCases.search_bugs_by_keyword.valid);
expect(result.bugs).toHaveLength(2);
expect(result.total_results).toBe(2);
});
test('should handle missing required keyword parameter', async () => {
await expect((0, mcp_server_1.executeTool)('search_bugs_by_keyword', {})).rejects.toThrow('Missing required field: keyword');
});
test('should search with keyword only (no optional parameters)', async () => {
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_keyword', { keyword: 'CallManager' });
expect(result.bugs).toBeDefined();
});
});
describe('search_bugs_by_product_id', () => {
test('should search bugs by product ID', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/products/product_id/C9200-24P');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_product_id', mockData_1.testCases.search_bugs_by_product_id.valid);
expect(result.bugs).toHaveLength(2);
});
test('should handle missing required base_pid parameter', async () => {
await expect((0, mcp_server_1.executeTool)('search_bugs_by_product_id', {})).rejects.toThrow('Missing required field: base_pid');
});
});
describe('search_bugs_by_product_and_release', () => {
test('should search bugs by product ID and software releases', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/products/product_id/C9200-24P/software_releases/17.5.1');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_product_and_release', mockData_1.testCases.search_bugs_by_product_and_release.valid);
expect(result.bugs).toHaveLength(2);
});
test('should handle missing required parameters', async () => {
await expect((0, mcp_server_1.executeTool)('search_bugs_by_product_and_release', { base_pid: 'test' })).rejects.toThrow('Missing required field: software_releases');
await expect((0, mcp_server_1.executeTool)('search_bugs_by_product_and_release', { software_releases: 'test' })).rejects.toThrow('Missing required field: base_pid');
});
});
describe('search_bugs_by_product_series_affected', () => {
test('should search bugs by product series and affected releases', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/product_series/Cisco%20Catalyst%209200%20Series/affected_releases/17.5.1');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_product_series_affected', mockData_1.testCases.search_bugs_by_product_series_affected.valid);
expect(result.bugs).toHaveLength(2);
});
test('should handle missing required parameters', async () => {
await expect((0, mcp_server_1.executeTool)('search_bugs_by_product_series_affected', { product_series: 'test' })).rejects.toThrow('Missing required field: affected_releases');
await expect((0, mcp_server_1.executeTool)('search_bugs_by_product_series_affected', { affected_releases: 'test' })).rejects.toThrow('Missing required field: product_series');
});
});
describe('search_bugs_by_product_series_fixed', () => {
test('should search bugs by product series and fixed releases', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/product_series/Cisco%20Catalyst%209200%20Series/fixed_releases/17.5.2');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_product_series_fixed', mockData_1.testCases.search_bugs_by_product_series_fixed.valid);
expect(result.bugs).toHaveLength(2);
});
});
describe('search_bugs_by_product_name_affected', () => {
test('should search bugs by product name and affected releases', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/products/product_name/Cisco%20Unified%20Communications%20Manager%20(CallManager)/affected_releases/12.5');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_product_name_affected', mockData_1.testCases.search_bugs_by_product_name_affected.valid);
expect(result.bugs).toHaveLength(2);
});
});
describe('search_bugs_by_product_name_fixed', () => {
test('should search bugs by product name and fixed releases', async () => {
setup_1.mockFetch.mockImplementationOnce((url, init) => {
if (typeof url === 'string' && url.includes('oauth2')) {
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockOAuthResponse)
});
}
expect(url).toContain('/bugs/products/product_name/Cisco%20Unified%20Communications%20Manager%20(CallManager)/fixed_releases/12.5');
return Promise.resolve({
ok: true,
status: 200,
json: () => Promise.resolve(mockData_1.mockBugResponse)
});
});
const result = await (0, mcp_server_1.executeTool)('search_bugs_by_product_name_fixed', mockData_1.testCases.search_bugs_by_product_name_fixed.valid);
expect(result.bugs).toHaveLength(2);
});
});
});
//# sourceMappingURL=bugApi.test.js.map