From 30ae5f166443b9262fc0648ee9da010ef3b7dc44 Mon Sep 17 00:00:00 2001 From: Mateusz Tkacz Date: Thu, 17 Oct 2024 11:30:02 +0200 Subject: [PATCH] chore: add test to check for symbol serialization --- src/errors/InternalError.spec.ts | 12 +++++++++++- src/errors/PublicNonRecoverableError.spec.ts | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/errors/InternalError.spec.ts b/src/errors/InternalError.spec.ts index 9e68c9e..ecdde79 100644 --- a/src/errors/InternalError.spec.ts +++ b/src/errors/InternalError.spec.ts @@ -1,3 +1,4 @@ +import { stdSerializers } from 'pino' import { InternalError, isInternalError } from './InternalError' describe('InternalError', () => { @@ -17,7 +18,16 @@ describe('InternalError', () => { expect(isInternalError(err)).toBe(true) }) - it('detects if error is public for extended error', () => { + it('does not expose INTERNAL_ERROR_KEY symbol', () => { + const err = new InternalError({ + message: 'Unknown', + errorCode: 'INTERNAL_ERROR', + }) + + expect(stdSerializers.err(err)).not.toHaveProperty('Symbol(INTERNAL_ERROR_KEY)') + }) + + it('detects if error is internal for extended error', () => { class ExtendedInternalError extends InternalError { constructor() { super({ diff --git a/src/errors/PublicNonRecoverableError.spec.ts b/src/errors/PublicNonRecoverableError.spec.ts index f3fd5a1..af78c0c 100644 --- a/src/errors/PublicNonRecoverableError.spec.ts +++ b/src/errors/PublicNonRecoverableError.spec.ts @@ -1,3 +1,4 @@ +import { stdSerializers } from 'pino' import { PublicNonRecoverableError, isPublicNonRecoverableError } from './PublicNonRecoverableError' describe('PublicNonRecoverableError', () => { @@ -26,6 +27,15 @@ describe('PublicNonRecoverableError', () => { expect(isPublicNonRecoverableError(err)).toBe(true) }) + it('does not expose PUBLIC_NON_RECOVERABLE_ERROR_KEY symbol', () => { + const err = new PublicNonRecoverableError({ + message: 'Unknown', + errorCode: 'PUBLIC_ERROR', + }) + + expect(stdSerializers.err(err)).not.toHaveProperty('Symbol(PUBLIC_NON_RECOVERABLE_ERROR_KEY)') + }) + it('detects if error is public for extended error', () => { class ExtendedPublicNonRecoverableError extends PublicNonRecoverableError { constructor() {