Files
drawio-mcp-server/src/tests/integration/end-to-end.test.ts
Alejandro Lembke Barrientos bf088da9d5
Some checks failed
CI Pipeline / Test and Build (20.x) (push) Failing after 3m22s
CI Pipeline / Code Quality Check (push) Failing after 11m52s
CI Pipeline / Security Audit (push) Failing after 11m53s
CI Pipeline / Test and Build (18.x) (push) Failing after 12m31s
CI Pipeline / Build Release Artifacts (push) Has been cancelled
CI Pipeline / Notification (push) Has been cancelled
Creating first version of MCP server.
2025-07-22 07:11:59 +00:00

321 lines
9.7 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, jest } from '@jest/globals';
describe('End-to-End Integration Tests', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('Complete Diagram Creation Workflow', () => {
it('should create a diagram from start to finish', async () => {
const input = {
name: 'integration-test',
type: 'flowchart' as const,
format: 'drawio' as const,
description: 'Integration test diagram',
processes: ['Start', 'Process 1', 'Decision', 'Process 2', 'End']
};
const mockResult = {
success: true,
filePath: '/test/workspace/integration-test.drawio',
message: 'Successfully created flowchart diagram: integration-test',
diagramType: 'flowchart' as const,
format: 'drawio' as const
};
expect(mockResult.success).toBe(true);
expect(mockResult.filePath).toBe('/test/workspace/integration-test.drawio');
expect(mockResult.diagramType).toBe('flowchart');
expect(mockResult.format).toBe('drawio');
});
it('should create and open diagram in VSCode', async () => {
const createResult = {
success: true,
filePath: '/test/workspace/test-diagram.drawio',
message: 'Successfully created diagram',
diagramType: 'bpmn-process' as const,
format: 'drawio' as const
};
expect(createResult.success).toBe(true);
// Simulate opening in VSCode
const openResult = { success: true };
expect(openResult.success).toBe(true);
});
});
describe('MCP Server Tool Integration', () => {
it('should handle create_diagram tool call', async () => {
const toolArgs = {
name: 'mcp-test',
type: 'uml-class' as const,
classes: ['User', 'Order', 'Product'],
workspaceRoot: '/test/workspace'
};
const mockResult = {
success: true,
filePath: '/test/workspace/mcp-test.drawio',
message: 'Successfully created UML class diagram: mcp-test',
diagramType: 'uml-class' as const,
format: 'drawio' as const
};
expect(mockResult.success).toBe(true);
expect(mockResult.diagramType).toBe('uml-class');
});
it('should handle list_diagrams tool call', async () => {
const mockFiles = [
{
path: '/test/workspace/test1.drawio',
relativePath: 'test1.drawio',
format: 'drawio' as const,
isDiagram: true,
stats: { size: 1024, mtime: new Date() }
}
];
expect(mockFiles).toHaveLength(1);
expect(mockFiles[0].path).toBe('/test/workspace/test1.drawio');
expect(mockFiles[0].format).toBe('drawio');
});
it('should handle setup_vscode_environment tool call', async () => {
const mockResult = {
success: true,
message: 'Environment ready'
};
expect(mockResult.success).toBe(true);
expect(mockResult.message).toBe('Environment ready');
});
it('should handle get_diagram_types tool call', async () => {
const types = [
'bpmn-process',
'uml-class',
'er-diagram',
'flowchart',
'network-topology',
'system-architecture'
];
const typesWithDescriptions = types.map(type => ({
type,
description: `Description for ${type}`
}));
expect(Array.isArray(types)).toBe(true);
expect(types.length).toBeGreaterThan(0);
expect(typesWithDescriptions[0]).toHaveProperty('type');
expect(typesWithDescriptions[0]).toHaveProperty('description');
});
});
describe('Error Handling Integration', () => {
it('should handle file creation errors gracefully', async () => {
const mockResult = {
success: false,
message: 'Failed to create diagram: Permission denied',
diagramType: 'flowchart' as const,
format: 'drawio' as const
};
expect(mockResult.success).toBe(false);
expect(mockResult.message).toContain('Failed to create diagram');
});
it('should handle VSCode integration errors', async () => {
const mockResult = {
success: false,
message: 'VSCode is not available. Please install VSCode first.'
};
expect(mockResult.success).toBe(false);
expect(mockResult.message).toContain('VSCode is not available');
});
});
describe('Resource Access Integration', () => {
it('should provide workspace diagrams resource', async () => {
const diagrams = [
{
path: '/test/workspace/test1.drawio',
relativePath: 'test1.drawio',
format: 'drawio' as const,
isDiagram: true,
stats: { size: 1024, mtime: new Date() }
}
];
const resourceData = {
uri: 'diagrams://workspace/list',
mimeType: 'application/json',
text: JSON.stringify(diagrams, null, 2)
};
expect(resourceData.uri).toBe('diagrams://workspace/list');
expect(resourceData.mimeType).toBe('application/json');
expect(typeof resourceData.text).toBe('string');
});
it('should provide supported diagram types resource', async () => {
const types = [
'bpmn-process',
'uml-class',
'er-diagram',
'flowchart',
'network-topology',
'system-architecture'
];
const typesWithDescriptions = types.map(type => ({
type,
description: `Description for ${type}`
}));
const resourceData = {
uri: 'diagrams://types/supported',
mimeType: 'application/json',
text: JSON.stringify(typesWithDescriptions, null, 2)
};
expect(resourceData.uri).toBe('diagrams://types/supported');
expect(resourceData.mimeType).toBe('application/json');
expect(typeof resourceData.text).toBe('string');
});
});
describe('Multi-format Support', () => {
it('should create diagrams in different formats', async () => {
const formats = ['drawio', 'drawio.svg', 'dio'] as const;
for (const format of formats) {
const mockResult = {
success: true,
filePath: `/test/workspace/test.${format}`,
message: `Successfully created diagram in ${format} format`,
diagramType: 'flowchart' as const,
format
};
expect(mockResult.success).toBe(true);
expect(mockResult.format).toBe(format);
}
});
});
describe('Complex Diagram Types', () => {
it('should create BPMN process with gateway', async () => {
const mockResult = {
success: true,
filePath: '/test/workspace/complex-bpmn.drawio',
message: 'Successfully created BPMN process diagram: complex-bpmn',
diagramType: 'bpmn-process' as const,
format: 'drawio' as const
};
expect(mockResult.success).toBe(true);
expect(mockResult.diagramType).toBe('bpmn-process');
});
it('should create UML class diagram with relationships', async () => {
const mockResult = {
success: true,
filePath: '/test/workspace/uml-classes.drawio',
message: 'Successfully created UML class diagram: uml-classes',
diagramType: 'uml-class' as const,
format: 'drawio' as const
};
expect(mockResult.success).toBe(true);
expect(mockResult.diagramType).toBe('uml-class');
});
});
describe('Workflow Validation', () => {
it('should validate complete workflow steps', () => {
const workflowSteps = [
'validate_input',
'create_diagram_data',
'generate_xml',
'write_file',
'return_result'
];
workflowSteps.forEach(step => {
expect(typeof step).toBe('string');
expect(step.length).toBeGreaterThan(0);
});
expect(workflowSteps).toHaveLength(5);
});
it('should validate MCP server capabilities', () => {
const capabilities = {
tools: [
'create_diagram',
'list_diagrams',
'open_diagram_in_vscode',
'setup_vscode_environment',
'get_diagram_types'
],
resources: [
'diagrams://workspace/list',
'diagrams://types/supported'
]
};
expect(capabilities.tools).toHaveLength(5);
expect(capabilities.resources).toHaveLength(2);
expect(capabilities.tools).toContain('create_diagram');
expect(capabilities.resources).toContain('diagrams://workspace/list');
});
});
describe('Performance and Reliability', () => {
it('should handle multiple concurrent diagram creations', async () => {
const concurrentRequests = [
{ name: 'diagram1', type: 'flowchart' as const },
{ name: 'diagram2', type: 'bpmn-process' as const },
{ name: 'diagram3', type: 'uml-class' as const }
];
const mockResults = concurrentRequests.map((req, index) => ({
success: true,
filePath: `/test/workspace/${req.name}.drawio`,
message: `Successfully created ${req.type} diagram: ${req.name}`,
diagramType: req.type,
format: 'drawio' as const
}));
expect(mockResults).toHaveLength(3);
mockResults.forEach(result => {
expect(result.success).toBe(true);
});
});
it('should handle large diagram data', async () => {
const largeInput = {
name: 'large-diagram',
type: 'flowchart' as const,
processes: Array.from({ length: 100 }, (_, i) => `Process ${i + 1}`)
};
const mockResult = {
success: true,
filePath: '/test/workspace/large-diagram.drawio',
message: 'Successfully created flowchart diagram: large-diagram',
diagramType: 'flowchart' as const,
format: 'drawio' as const
};
expect(largeInput.processes).toHaveLength(100);
expect(mockResult.success).toBe(true);
});
});
});