refactor: add TypeScript interfaces for test response types

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>
This commit is contained in:
czlonkowski
2025-10-05 10:45:30 +02:00
parent 69f3a31d41
commit c519cd5060
4 changed files with 241 additions and 35 deletions

View File

@@ -9,6 +9,7 @@ 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;
@@ -28,7 +29,7 @@ describe('Integration: handleHealthCheck', () => {
expect(response.success).toBe(true);
expect(response.data).toBeDefined();
const data = response.data as any;
const data = response.data as HealthCheckResponse;
// Verify required fields
expect(data).toHaveProperty('status');
@@ -53,7 +54,7 @@ describe('Integration: handleHealthCheck', () => {
const response = await handleHealthCheck(mcpContext);
expect(response.success).toBe(true);
const data = response.data as any;
const data = response.data as HealthCheckResponse;
// Check for feature information
// Note: Features may vary by n8n instance configuration
@@ -89,7 +90,7 @@ describe('Integration: handleHealthCheck', () => {
expect(response.success).toBe(true);
expect(response.data).toBeDefined();
const data = response.data as any;
const data = response.data as HealthCheckResponse;
// Verify all expected fields are present
const expectedFields = ['status', 'apiUrl', 'mcpVersion'];