mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
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:
202
tests/integration/n8n-api/utils/response-types.ts
Normal file
202
tests/integration/n8n-api/utils/response-types.ts
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* TypeScript interfaces for n8n API and MCP handler responses
|
||||
* Used in integration tests to provide type safety
|
||||
*/
|
||||
|
||||
// ======================================================================
|
||||
// System Tool Response Types
|
||||
// ======================================================================
|
||||
|
||||
export interface HealthCheckResponse {
|
||||
status: string;
|
||||
instanceId?: string;
|
||||
n8nVersion?: string;
|
||||
features?: Record<string, any>;
|
||||
apiUrl: string;
|
||||
mcpVersion: string;
|
||||
supportedN8nVersion?: string;
|
||||
versionNote?: string;
|
||||
[key: string]: any; // Allow dynamic property access for optional field checks
|
||||
}
|
||||
|
||||
export interface ToolDefinition {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface ToolCategory {
|
||||
category: string;
|
||||
tools: ToolDefinition[];
|
||||
}
|
||||
|
||||
export interface ApiConfiguration {
|
||||
apiUrl: string;
|
||||
timeout: number;
|
||||
maxRetries: number;
|
||||
}
|
||||
|
||||
export interface ListToolsResponse {
|
||||
tools: ToolCategory[];
|
||||
apiConfigured: boolean;
|
||||
configuration?: ApiConfiguration | null;
|
||||
limitations: string[];
|
||||
}
|
||||
|
||||
export interface ApiStatus {
|
||||
configured: boolean;
|
||||
connected: boolean;
|
||||
error?: string | null;
|
||||
version?: string | null;
|
||||
}
|
||||
|
||||
export interface ToolsAvailability {
|
||||
documentationTools: {
|
||||
count: number;
|
||||
enabled: boolean;
|
||||
description: string;
|
||||
};
|
||||
managementTools: {
|
||||
count: number;
|
||||
enabled: boolean;
|
||||
description: string;
|
||||
};
|
||||
totalAvailable: number;
|
||||
}
|
||||
|
||||
export interface DebugInfo {
|
||||
processEnv: string[];
|
||||
nodeVersion: string;
|
||||
platform: string;
|
||||
workingDirectory: string;
|
||||
}
|
||||
|
||||
export interface DiagnosticResponse {
|
||||
timestamp: string;
|
||||
environment: {
|
||||
N8N_API_URL: string | null;
|
||||
N8N_API_KEY: string | null;
|
||||
NODE_ENV: string;
|
||||
MCP_MODE: string;
|
||||
};
|
||||
apiConfiguration: {
|
||||
configured: boolean;
|
||||
status: ApiStatus;
|
||||
config?: {
|
||||
baseUrl: string;
|
||||
timeout: number;
|
||||
maxRetries: number;
|
||||
} | null;
|
||||
};
|
||||
toolsAvailability: ToolsAvailability;
|
||||
troubleshooting: {
|
||||
steps: string[];
|
||||
documentation: string;
|
||||
};
|
||||
debug?: DebugInfo;
|
||||
[key: string]: any; // Allow dynamic property access for optional field checks
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// Execution Response Types
|
||||
// ======================================================================
|
||||
|
||||
export interface ExecutionData {
|
||||
id: string;
|
||||
status?: 'success' | 'error' | 'running' | 'waiting';
|
||||
mode?: string;
|
||||
startedAt?: string;
|
||||
stoppedAt?: string;
|
||||
workflowId?: string;
|
||||
data?: any;
|
||||
}
|
||||
|
||||
export interface ListExecutionsResponse {
|
||||
executions: ExecutionData[];
|
||||
returned: number;
|
||||
nextCursor?: string;
|
||||
hasMore: boolean;
|
||||
_note?: string;
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// Workflow Response Types
|
||||
// ======================================================================
|
||||
|
||||
export interface WorkflowNode {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
typeVersion: number;
|
||||
position: [number, number];
|
||||
parameters: Record<string, any>;
|
||||
credentials?: Record<string, any>;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface WorkflowConnections {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface WorkflowData {
|
||||
id: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
nodes: WorkflowNode[];
|
||||
connections: WorkflowConnections;
|
||||
settings?: Record<string, any>;
|
||||
staticData?: Record<string, any>;
|
||||
tags?: string[];
|
||||
versionId?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface ValidationError {
|
||||
nodeId?: string;
|
||||
nodeName?: string;
|
||||
field?: string;
|
||||
message: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface ValidationWarning {
|
||||
nodeId?: string;
|
||||
nodeName?: string;
|
||||
message: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface ValidateWorkflowResponse {
|
||||
valid: boolean;
|
||||
errors?: ValidationError[];
|
||||
warnings?: ValidationWarning[];
|
||||
errorCount?: number;
|
||||
warningCount?: number;
|
||||
summary?: string;
|
||||
}
|
||||
|
||||
export interface AutofixChange {
|
||||
nodeId: string;
|
||||
nodeName: string;
|
||||
field: string;
|
||||
oldValue: any;
|
||||
newValue: any;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export interface AutofixSuggestion {
|
||||
fixType: string;
|
||||
nodeId: string;
|
||||
nodeName: string;
|
||||
description: string;
|
||||
confidence: 'high' | 'medium' | 'low';
|
||||
changes: AutofixChange[];
|
||||
}
|
||||
|
||||
export interface AutofixResponse {
|
||||
appliedFixes?: number;
|
||||
suggestions?: AutofixSuggestion[];
|
||||
workflow?: WorkflowData;
|
||||
summary?: string;
|
||||
preview?: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user