UNPKG

n8n-nodes-databricks-api

Version:
50 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jest_mock_extended_1 = require("jest-mock-extended"); const n8n_workflow_1 = require("n8n-workflow"); const n8nLlmFailedAttemptHandler_1 = require("./n8nLlmFailedAttemptHandler"); describe('makeN8nLlmFailedAttemptHandler', () => { const ctx = (0, jest_mock_extended_1.mock)({ getNode: jest.fn(), }); it('should throw a wrapped error, when NO custom handler is provided', () => { const handler = (0, n8nLlmFailedAttemptHandler_1.makeN8nLlmFailedAttemptHandler)(ctx); expect(() => handler(new Error('Test error'))).toThrow(n8n_workflow_1.NodeApiError); }); it('should wrapped error when custom handler is provided', () => { const customHandler = jest.fn(); const handler = (0, n8nLlmFailedAttemptHandler_1.makeN8nLlmFailedAttemptHandler)(ctx, customHandler); expect(() => handler(new Error('Test error'))).toThrow(n8n_workflow_1.NodeApiError); expect(customHandler).toHaveBeenCalled(); }); it('should throw wrapped exception from custom handler', () => { const customHandler = jest.fn(() => { throw new n8n_workflow_1.ApplicationError('Custom handler error'); }); const handler = (0, n8nLlmFailedAttemptHandler_1.makeN8nLlmFailedAttemptHandler)(ctx, customHandler); expect(() => handler(new Error('Test error'))).toThrow('Custom handler error'); expect(customHandler).toHaveBeenCalled(); }); it('should not throw if retries are left', () => { const customHandler = jest.fn(); const handler = (0, n8nLlmFailedAttemptHandler_1.makeN8nLlmFailedAttemptHandler)(ctx, customHandler); const error = new Error('Test error'); error.retriesLeft = 1; expect(() => handler(error)).not.toThrow(); }); it('should throw NodeApiError if no retries are left', () => { const handler = (0, n8nLlmFailedAttemptHandler_1.makeN8nLlmFailedAttemptHandler)(ctx); const error = new Error('Test error'); error.retriesLeft = 0; expect(() => handler(error)).toThrow(n8n_workflow_1.NodeApiError); }); it('should throw NodeApiError if no retries are left with custom handler', () => { const customHandler = jest.fn(); const handler = (0, n8nLlmFailedAttemptHandler_1.makeN8nLlmFailedAttemptHandler)(ctx, customHandler); const error = new Error('Test error'); error.retriesLeft = 0; expect(() => handler(error)).toThrow(n8n_workflow_1.NodeApiError); expect(customHandler).toHaveBeenCalled(); }); }); //# sourceMappingURL=n8nLlmFailedAttemptHandler.test.js.map