mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
add unit tests for beforeSend
This commit is contained in:
parent
0e288a9acb
commit
e16b6ce81c
48
packages/cli/src/__tests__/error-reporting.test.ts
Normal file
48
packages/cli/src/__tests__/error-reporting.test.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { QueryFailedError } from '@n8n/typeorm';
|
||||
import { AxiosError } from 'axios';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { ApplicationError } from 'n8n-workflow';
|
||||
|
||||
import { ErrorReporting } from '../error-reporting';
|
||||
|
||||
describe('ErrorReporting', () => {
|
||||
const errorReporting = new ErrorReporting(mock(), mock());
|
||||
|
||||
describe('beforeSend', () => {
|
||||
it('should return null if originalException is an AxiosError', () => {
|
||||
const hint = { originalException: new AxiosError() };
|
||||
expect(errorReporting.beforeSend(mock(), hint)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if originalException is a QueryFailedError with SQLITE_FULL or SQLITE_IOERR message', () => {
|
||||
const hint = {
|
||||
originalException: new QueryFailedError('', [], new Error('SQLITE_FULL error')),
|
||||
};
|
||||
expect(errorReporting.beforeSend(mock(), hint)).toBeNull();
|
||||
|
||||
hint.originalException = new QueryFailedError('', [], new Error('SQLITE_IOERR error'));
|
||||
expect(errorReporting.beforeSend(mock(), hint)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if originalException is an ApplicationError with level warning', () => {
|
||||
const hint = { originalException: new ApplicationError('Test error', { level: 'warning' }) };
|
||||
expect(errorReporting.beforeSend(mock(), hint)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return event if originalException is an ApplicationError with level error', () => {
|
||||
const hint = { originalException: new ApplicationError('Test error', { level: 'error' }) };
|
||||
expect(errorReporting.beforeSend(mock(), hint)).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if originalException is an Error with a non-unique stack', () => {
|
||||
const hint = { originalException: new Error('Test error') };
|
||||
errorReporting.beforeSend(mock(), hint);
|
||||
expect(errorReporting.beforeSend(mock(), hint)).toBeNull();
|
||||
});
|
||||
|
||||
it('should return event if originalException is an Error with a unique stack', () => {
|
||||
const hint = { originalException: new Error('Test error') };
|
||||
expect(errorReporting.beforeSend(mock(), hint)).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue