UNPKG

n8n-bookstack-agent-tool

Version:

Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility

187 lines • 8.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiFailureSimulator = void 0; const index_js_1 = require("../index.js"); class ApiFailureSimulator { constructor() { this.validConfig = { baseUrl: 'https://wiki.l7cloud.io', authType: 'bearer', token: 'EnRkbVwqzNSyLaVo7olU8Wx8umGznKuE', tokenSecret: 'TyaJ0JHAenwRIgScmsffrCeSIlon4fZ2', timeout: 30000, retryAttempts: 3, retryDelay: 1000 }; this.tool = new index_js_1.BookStackN8nTool(this.validConfig); } async runApiFailureTests() { console.log('\n🚨 API FAILURE SIMULATION TESTS'); console.log('==============================='); await this.testTimeoutScenarios(); await this.testServerErrorScenarios(); await this.testAuthenticationFailures(); await this.testNetworkIssues(); console.log('\nāœ… API failure simulation tests completed'); } async testTimeoutScenarios() { console.log('\nā° Testing timeout scenarios...'); const shortTimeoutConfig = { ...this.validConfig, timeout: 1000 // Minimum valid timeout to test timeout handling }; const timeoutTool = new index_js_1.BookStackN8nTool(shortTimeoutConfig); try { console.log(' Testing with extremely short timeout (100ms)...'); await timeoutTool.execCommand('listBooks', {}); console.log(' āš ļø Timeout test: Request completed unexpectedly'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('timeout') || errorMessage.toLowerCase().includes('aborted')) { console.log(' āœ… Timeout handling: Properly detected and handled'); } else { console.log(` āŒ Timeout handling: Unexpected error - ${errorMessage}`); } } } async testServerErrorScenarios() { console.log('\nšŸ”„ Testing server error scenarios...'); try { console.log(' Testing with invalid book ID to trigger 404...'); await this.tool.execCommand('getBook', { id: 999999 }); console.log(' āš ļø 404 test: No error thrown for invalid ID'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('not found') || errorMessage.toLowerCase().includes('404')) { console.log(' āœ… 404 handling: Properly detected and handled'); } else { console.log(` āŒ 404 handling: Unexpected error - ${errorMessage}`); } } try { console.log(' Testing with invalid endpoint to trigger server errors...'); await this.tool.execCommand('createBook', { name: '', // Empty name should trigger validation error description: 'Test book' }); console.log(' āš ļø Validation test: No error thrown for invalid data'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('validation') || errorMessage.toLowerCase().includes('required') || errorMessage.toLowerCase().includes('422')) { console.log(' āœ… Validation error handling: Properly detected and handled'); } else { console.log(` āŒ Validation error handling: Unexpected error - ${errorMessage}`); } } } async testAuthenticationFailures() { console.log('\nšŸ” Testing authentication failures...'); const invalidAuthConfig = { ...this.validConfig, token: 'invalid_token_12345', tokenSecret: 'invalid_secret_67890' }; const invalidAuthTool = new index_js_1.BookStackN8nTool(invalidAuthConfig); try { console.log(' Testing with invalid authentication credentials...'); await invalidAuthTool.execCommand('listBooks', {}); console.log(' āš ļø Auth test: Request succeeded with invalid credentials'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('unauthorized') || errorMessage.toLowerCase().includes('401') || errorMessage.toLowerCase().includes('forbidden') || errorMessage.toLowerCase().includes('403')) { console.log(' āœ… Authentication error handling: Properly detected and handled'); } else { console.log(` āŒ Authentication error handling: Unexpected error - ${errorMessage}`); } } try { console.log(' Testing with missing authentication credentials...'); const missingTokenConfig = { ...this.validConfig, token: '', tokenSecret: '' }; const missingTokenTool = new index_js_1.BookStackN8nTool(missingTokenConfig); await missingTokenTool.execCommand('listBooks', {}); console.log(' āš ļø Missing auth test: Request succeeded without credentials'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('token') || errorMessage.toLowerCase().includes('auth') || errorMessage.toLowerCase().includes('credential') || errorMessage.toLowerCase().includes('required')) { console.log(' āœ… Missing credentials handling: Properly detected and handled'); } else { console.log(` āŒ Missing credentials handling: Unexpected error - ${errorMessage}`); } } } async testNetworkIssues() { console.log('\n🌐 Testing network issues...'); const invalidUrlConfig = { ...this.validConfig, baseUrl: 'https://nonexistent-bookstack-server.invalid' }; const networkTool = new index_js_1.BookStackN8nTool(invalidUrlConfig); try { console.log(' Testing with invalid/unreachable URL...'); await networkTool.execCommand('listBooks', {}); console.log(' āš ļø Network test: Request succeeded to invalid URL'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('network') || errorMessage.toLowerCase().includes('dns') || errorMessage.toLowerCase().includes('enotfound') || errorMessage.toLowerCase().includes('connection')) { console.log(' āœ… Network error handling: Properly detected and handled'); } else { console.log(` āŒ Network error handling: Unexpected error - ${errorMessage}`); } } try { console.log(' Testing with malformed URL...'); const malformedUrlConfig = { ...this.validConfig, baseUrl: 'not-a-valid-url' }; const malformedTool = new index_js_1.BookStackN8nTool(malformedUrlConfig); await malformedTool.execCommand('listBooks', {}); console.log(' āš ļø Malformed URL test: Request succeeded with invalid URL format'); } catch (error) { const errorMessage = error.message; if (errorMessage.toLowerCase().includes('url') || errorMessage.toLowerCase().includes('protocol') || errorMessage.toLowerCase().includes('http') || errorMessage.toLowerCase().includes('https')) { console.log(' āœ… Malformed URL handling: Properly detected and handled'); } else { console.log(` āŒ Malformed URL handling: Unexpected error - ${errorMessage}`); } } } } exports.ApiFailureSimulator = ApiFailureSimulator; if (require.main === module) { const simulator = new ApiFailureSimulator(); simulator.runApiFailureTests().catch(console.error); } //# sourceMappingURL=api-failure-simulation.js.map