mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 21:43:07 +00:00
Replace 'as any' type assertions with proper TypeScript interfaces for improved type safety in Phase 8 integration tests. Changes: - Created response-types.ts with comprehensive interfaces for all response types - Updated health-check.test.ts to use HealthCheckResponse interface - Updated list-tools.test.ts to use ListToolsResponse interface - Updated diagnostic.test.ts to use DiagnosticResponse interface - Added null-safety checks for optional fields (data.debug) - Used non-null assertions (!) for values verified with expect().toBeDefined() - Removed unnecessary 'as any' casts throughout test files Benefits: - Better type safety and IDE autocomplete - Catches potential type mismatches at compile time - More maintainable and self-documenting code - Consistent with code review recommendation All 19 tests still passing with full type safety. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
111 lines
3.6 KiB
TypeScript
111 lines
3.6 KiB
TypeScript
/**
|
|
* Integration Tests: handleHealthCheck
|
|
*
|
|
* Tests API health check against a real n8n instance.
|
|
* Covers connectivity verification and feature availability.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { createMcpContext } from '../utils/mcp-context';
|
|
import { InstanceContext } from '../../../../src/types/instance-context';
|
|
import { handleHealthCheck } from '../../../../src/mcp/handlers-n8n-manager';
|
|
import { HealthCheckResponse } from '../utils/response-types';
|
|
|
|
describe('Integration: handleHealthCheck', () => {
|
|
let mcpContext: InstanceContext;
|
|
|
|
beforeEach(() => {
|
|
mcpContext = createMcpContext();
|
|
});
|
|
|
|
// ======================================================================
|
|
// Successful Health Check
|
|
// ======================================================================
|
|
|
|
describe('API Available', () => {
|
|
it('should successfully check n8n API health', async () => {
|
|
const response = await handleHealthCheck(mcpContext);
|
|
|
|
expect(response.success).toBe(true);
|
|
expect(response.data).toBeDefined();
|
|
|
|
const data = response.data as HealthCheckResponse;
|
|
|
|
// Verify required fields
|
|
expect(data).toHaveProperty('status');
|
|
expect(data).toHaveProperty('apiUrl');
|
|
expect(data).toHaveProperty('mcpVersion');
|
|
|
|
// Status should be a string (e.g., "ok", "healthy")
|
|
if (data.status) {
|
|
expect(typeof data.status).toBe('string');
|
|
}
|
|
|
|
// API URL should match configuration
|
|
expect(data.apiUrl).toBeDefined();
|
|
expect(typeof data.apiUrl).toBe('string');
|
|
|
|
// MCP version should be defined
|
|
expect(data.mcpVersion).toBeDefined();
|
|
expect(typeof data.mcpVersion).toBe('string');
|
|
});
|
|
|
|
it('should include feature availability information', async () => {
|
|
const response = await handleHealthCheck(mcpContext);
|
|
|
|
expect(response.success).toBe(true);
|
|
const data = response.data as HealthCheckResponse;
|
|
|
|
// Check for feature information
|
|
// Note: Features may vary by n8n instance configuration
|
|
if (data.features) {
|
|
expect(typeof data.features).toBe('object');
|
|
}
|
|
|
|
// Check for version information
|
|
if (data.n8nVersion) {
|
|
expect(typeof data.n8nVersion).toBe('string');
|
|
}
|
|
|
|
if (data.supportedN8nVersion) {
|
|
expect(typeof data.supportedN8nVersion).toBe('string');
|
|
}
|
|
|
|
// Should include version note for AI agents
|
|
if (data.versionNote) {
|
|
expect(typeof data.versionNote).toBe('string');
|
|
expect(data.versionNote).toContain('version');
|
|
}
|
|
});
|
|
});
|
|
|
|
// ======================================================================
|
|
// Response Format Verification
|
|
// ======================================================================
|
|
|
|
describe('Response Format', () => {
|
|
it('should return complete health check response structure', async () => {
|
|
const response = await handleHealthCheck(mcpContext);
|
|
|
|
expect(response.success).toBe(true);
|
|
expect(response.data).toBeDefined();
|
|
|
|
const data = response.data as HealthCheckResponse;
|
|
|
|
// Verify all expected fields are present
|
|
const expectedFields = ['status', 'apiUrl', 'mcpVersion'];
|
|
expectedFields.forEach(field => {
|
|
expect(data).toHaveProperty(field);
|
|
});
|
|
|
|
// Optional fields that may be present
|
|
const optionalFields = ['instanceId', 'n8nVersion', 'features', 'supportedN8nVersion', 'versionNote'];
|
|
optionalFields.forEach(field => {
|
|
if (data[field] !== undefined) {
|
|
expect(data[field]).not.toBeNull();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|