From e16b6ce81c39631e2cf06580ed958611ca6250b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 16 Oct 2024 11:46:18 +0200 Subject: [PATCH] add unit tests for beforeSend --- .../cli/src/__tests__/error-reporting.test.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/cli/src/__tests__/error-reporting.test.ts diff --git a/packages/cli/src/__tests__/error-reporting.test.ts b/packages/cli/src/__tests__/error-reporting.test.ts new file mode 100644 index 0000000000..b08a7b3747 --- /dev/null +++ b/packages/cli/src/__tests__/error-reporting.test.ts @@ -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(); + }); + }); +});