Skip to content

Commit

Permalink
tests: add tests for error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
g-tejas committed Jul 10, 2024
1 parent 8df12dd commit cb78de7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/modules/core/__tests__/core.errors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ErrorCodes } from '../core.errors'

describe('core', () => {
describe('error codes', () => {
it('should be 6 digits long', () => {
// iterate through the enum values and verify that they are 6 digits
// not the value but the length of the number representation
const errorCodeValues = Object.values(ErrorCodes).filter(
(value) => typeof value === 'number',
) as number[]

errorCodeValues.forEach((errorCode) => {
expect(String(errorCode).length).toBe(6)
})
})

it('should follow SCREAMING_SNAKE_CASE', () => {
const isScreamingSnakeCase = /^[A-Z0-9]+(_[A-Z0-9]+)*$/

// TS enums put both the key and the value in the enum object
const keys = Object.keys(ErrorCodes).filter((v) => isNaN(Number(v)))

keys.forEach((key) => {
expect(key).toMatch(isScreamingSnakeCase)
})
})
})
})

0 comments on commit cb78de7

Please sign in to comment.