Skip to content

Commit

Permalink
chore: add test to check for symbol serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Tkacz committed Oct 17, 2024
1 parent a770962 commit 30ae5f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/errors/InternalError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stdSerializers } from 'pino'
import { InternalError, isInternalError } from './InternalError'

describe('InternalError', () => {
Expand All @@ -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({
Expand Down
10 changes: 10 additions & 0 deletions src/errors/PublicNonRecoverableError.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stdSerializers } from 'pino'
import { PublicNonRecoverableError, isPublicNonRecoverableError } from './PublicNonRecoverableError'

describe('PublicNonRecoverableError', () => {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 30ae5f1

Please sign in to comment.