2024-01-16 07:18:34 -08:00
|
|
|
import { mock } from 'jest-mock-extended';
|
|
|
|
import type { INode } from '@/Interfaces';
|
|
|
|
import { NodeApiError } from '@/errors/node-api.error';
|
|
|
|
import { NodeOperationError } from '@/errors/node-operation.error';
|
2024-07-26 04:12:42 -07:00
|
|
|
import { ApplicationError } from '@/errors/application.error';
|
2024-01-16 07:18:34 -08:00
|
|
|
|
|
|
|
describe('NodeError', () => {
|
|
|
|
const node = mock<INode>();
|
|
|
|
|
2024-01-31 06:34:22 -08:00
|
|
|
it('should update re-wrapped error level and message', () => {
|
2024-03-07 08:08:01 -08:00
|
|
|
const apiError = new NodeApiError(node, { message: 'Some error happened', code: 500 });
|
2024-01-31 06:34:22 -08:00
|
|
|
const opsError = new NodeOperationError(node, mock(), { message: 'Some operation failed' });
|
|
|
|
const wrapped1 = new NodeOperationError(node, apiError);
|
|
|
|
const wrapped2 = new NodeOperationError(node, opsError);
|
2024-01-16 07:18:34 -08:00
|
|
|
|
2024-06-05 04:21:32 -07:00
|
|
|
expect(wrapped1).toEqual(apiError);
|
|
|
|
expect(wrapped2).toEqual(opsError);
|
2024-01-16 07:18:34 -08:00
|
|
|
});
|
2024-07-26 04:12:42 -07:00
|
|
|
|
|
|
|
it('should obfuscate errors not processed by n8n', () => {
|
|
|
|
const error = new Error('Original error message');
|
|
|
|
const nodeOpError = new NodeOperationError(node, error);
|
|
|
|
|
2024-08-05 06:42:06 -07:00
|
|
|
expect(nodeOpError.obfuscate).toBe(true);
|
|
|
|
expect(nodeOpError.message).toBe('Original error message');
|
2024-07-26 04:12:42 -07:00
|
|
|
expect(nodeOpError.messages).toContain('Original error message');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not obfuscate errors processed by n8n', () => {
|
|
|
|
const appError = new ApplicationError('Processed error message');
|
|
|
|
const nodeOpError = new NodeOperationError(node, appError);
|
|
|
|
|
2024-08-05 06:42:06 -07:00
|
|
|
expect(nodeOpError.obfuscate).toBe(false);
|
2024-07-26 04:12:42 -07:00
|
|
|
expect(nodeOpError.message).toBe('Processed error message');
|
|
|
|
expect(nodeOpError.messages).not.toContain('Processed error message');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not obfuscate string errors', () => {
|
|
|
|
const errorMessage = 'String error message';
|
|
|
|
const nodeOpError = new NodeOperationError(node, errorMessage);
|
|
|
|
|
2024-08-05 06:42:06 -07:00
|
|
|
expect(nodeOpError.obfuscate).toBe(false);
|
2024-07-26 04:12:42 -07:00
|
|
|
expect(nodeOpError.message).toBe(errorMessage);
|
|
|
|
expect(nodeOpError.messages).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not obfuscate error if description provided', () => {
|
|
|
|
const error = new Error('Initial error message');
|
|
|
|
const options = { description: 'Error description' };
|
|
|
|
const nodeOpError = new NodeOperationError(node, error, options);
|
|
|
|
|
2024-08-05 06:42:06 -07:00
|
|
|
expect(nodeOpError.obfuscate).toBe(false);
|
2024-07-26 04:12:42 -07:00
|
|
|
expect(nodeOpError.message).toBe('Initial error message');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should respect provided options for message and description', () => {
|
|
|
|
const error = new Error('Initial error message');
|
|
|
|
const options = { message: 'Overridden message', description: 'Error description' };
|
|
|
|
const nodeOpError = new NodeOperationError(node, error, options);
|
|
|
|
|
2024-08-05 06:42:06 -07:00
|
|
|
expect(nodeOpError.obfuscate).toBe(false);
|
2024-07-26 04:12:42 -07:00
|
|
|
expect(nodeOpError.message).toBe('Overridden message');
|
|
|
|
expect(nodeOpError.description).toBe('Error description');
|
|
|
|
});
|
2024-01-16 07:18:34 -08:00
|
|
|
});
|