UNPKG

n8n-bookstack-agent-tool

Version:

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

186 lines โ€ข 8.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorHandlingTester = void 0; const index_js_1 = require("../index.js"); const error_handler_js_1 = require("../error/error-handler.js"); class ErrorHandlingTester { constructor() { const config = { baseUrl: 'https://wiki.l7cloud.io', authType: 'bearer', token: 'EnRkbVwqzNSyLaVo7olU8Wx8umGznKuE', tokenSecret: 'TyaJ0JHAenwRIgScmsffrCeSIlon4fZ2', timeout: 30000, retryAttempts: 3, retryDelay: 1000 }; this.tool = new index_js_1.BookStackN8nTool(config); } async runErrorHandlingTests() { console.log('\n๐Ÿงช COMPREHENSIVE ERROR HANDLING TESTS'); console.log('====================================='); await this.testInvalidIds(); await this.testMissingRequiredFields(); await this.testInvalidTokens(); await this.testNetworkErrors(); await this.testValidationErrors(); await this.testPermissionErrors(); console.log('\nโœ… Error handling tests completed'); } async testInvalidIds() { console.log('\nโŒ Testing Invalid ID Scenarios...'); const invalidIdTests = [ { command: 'getBook', params: { id: 999999 } }, { command: 'getPage', params: { id: 999999 } }, { command: 'getChapter', params: { id: 999999 } }, { command: 'getShelf', params: { id: 999999 } }, { command: 'getUser', params: { id: 999999 } }, { command: 'deleteBook', params: { id: 999999 } }, { command: 'updatePage', params: { id: 999999, name: 'Test' } } ]; for (const test of invalidIdTests) { try { console.log(` Testing ${test.command} with invalid ID...`); await this.tool.execCommand(test.command, test.params); console.log(` โš ๏ธ ${test.command}: No error thrown (unexpected)`); } catch (error) { if (error instanceof error_handler_js_1.BookStackError) { console.log(` โœ… ${test.command}: BookStackError - ${error.type} (${error.message})`); } else { console.log(` โœ… ${test.command}: Error caught - ${error.constructor?.name}`); } } } } async testMissingRequiredFields() { console.log('\nโŒ Testing Missing Required Fields...'); const missingFieldTests = [ { command: 'createBook', params: {} }, { command: 'createPage', params: {} }, { command: 'createChapter', params: {} }, { command: 'createShelf', params: {} }, { command: 'createUser', params: {} }, { command: 'updateBook', params: { id: 2 } }, { command: 'updatePage', params: { id: 2 } } ]; for (const test of missingFieldTests) { try { console.log(` Testing ${test.command} with missing fields...`); await this.tool.execCommand(test.command, test.params); console.log(` โš ๏ธ ${test.command}: No error thrown (unexpected)`); } catch (error) { if (error instanceof error_handler_js_1.BookStackError) { console.log(` โœ… ${test.command}: BookStackError - ${error.type} (${error.message})`); } else { console.log(` โœ… ${test.command}: Error caught - ${error.constructor?.name}`); } } } } async testInvalidTokens() { console.log('\nโŒ Testing Invalid Authentication...'); const invalidConfig = { baseUrl: 'https://wiki.l7cloud.io', authType: 'bearer', token: 'invalid_token', tokenSecret: 'invalid_secret', timeout: 30000 }; const invalidTool = new index_js_1.BookStackN8nTool(invalidConfig); try { console.log(' Testing with invalid token...'); await invalidTool.execCommand('listBooks', { count: 1 }); console.log(' โš ๏ธ Invalid token: No error thrown (unexpected)'); } catch (error) { if (error instanceof error_handler_js_1.BookStackError) { console.log(` โœ… Invalid token: BookStackError - ${error.type} (${error.message})`); } else { console.log(` โœ… Invalid token: Error caught - ${error.constructor?.name}`); } } } async testNetworkErrors() { console.log('\nโŒ Testing Network Error Scenarios...'); const networkConfig = { baseUrl: 'https://nonexistent-bookstack-api.invalid', authType: 'bearer', token: 'test_token', tokenSecret: 'test_secret', timeout: 5000 }; const networkTool = new index_js_1.BookStackN8nTool(networkConfig); try { console.log(' Testing with invalid URL...'); await networkTool.execCommand('listBooks', { count: 1 }); console.log(' โš ๏ธ Invalid URL: No error thrown (unexpected)'); } catch (error) { if (error instanceof error_handler_js_1.BookStackError) { console.log(` โœ… Invalid URL: BookStackError - ${error.type} (${error.message})`); } else { console.log(` โœ… Invalid URL: Error caught - ${error.constructor?.name}`); } } } async testValidationErrors() { console.log('\nโŒ Testing Input Validation...'); const validationTests = [ { command: 'createBook', params: { name: '' } }, { command: 'createPage', params: { name: 'Test', book_id: 'invalid' } }, { command: 'createUser', params: { name: 'test', email: 'invalid-email' } }, { command: 'listBooks', params: { count: -1 } }, { command: 'listPages', params: { offset: 'invalid' } } ]; for (const test of validationTests) { try { console.log(` Testing ${test.command} with invalid data...`); await this.tool.execCommand(test.command, test.params); console.log(` โš ๏ธ ${test.command}: No error thrown (unexpected)`); } catch (error) { if (error instanceof error_handler_js_1.BookStackError) { console.log(` โœ… ${test.command}: BookStackError - ${error.type} (${error.message})`); } else { console.log(` โœ… ${test.command}: Error caught - ${error.constructor?.name}`); } } } } async testPermissionErrors() { console.log('\nโŒ Testing Permission Scenarios...'); const permissionTests = [ { command: 'createTag', params: { name: 'test-tag' } }, { command: 'updateTag', params: { id: 1, name: 'updated-tag' } }, { command: 'deleteTag', params: { id: 1 } } ]; for (const test of permissionTests) { try { console.log(` Testing ${test.command} (read-only resource)...`); await this.tool.execCommand(test.command, test.params); console.log(` โš ๏ธ ${test.command}: No error thrown (unexpected)`); } catch (error) { if (error instanceof error_handler_js_1.BookStackError) { console.log(` โœ… ${test.command}: BookStackError - ${error.type} (${error.message})`); } else { console.log(` โœ… ${test.command}: Error caught - ${error.constructor?.name}`); } } } } } exports.ErrorHandlingTester = ErrorHandlingTester; if (require.main === module) { const tester = new ErrorHandlingTester(); tester.runErrorHandlingTests().catch(console.error); } //# sourceMappingURL=error-handling-test.js.map