File tree 3 files changed +45
-0
lines changed
packages/exceptions/src/guards
3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ import ExceptionCode from '@packages/exceptions/enums/exception-code.enum'
2
+ import ExceptionId from '@packages/exceptions/enums/exception-id.enum'
3
+ import type { Testcase } from '@tests/utils/types'
4
+ import testSubject from '../is-exception-id.guard'
5
+
6
+ /**
7
+ * @file Unit Tests - isExceptionId
8
+ * @module exceptions/guards/tests/unit/isExceptionId
9
+ */
10
+
11
+ describe ( 'unit:guards/isExceptionId' , ( ) => {
12
+ type Case = Testcase < boolean > & { value : any }
13
+
14
+ const cases : Case [ ] = [
15
+ { expected : false , value : ExceptionCode . UNAUTHORIZED } ,
16
+ { expected : true , value : ExceptionId . I_AM_A_TEAPOT }
17
+ ]
18
+
19
+ it . each < Case > ( cases ) ( 'should return $expected given $value' , testcase => {
20
+ // Arrange
21
+ const { expected, value } = testcase
22
+
23
+ // Act + Expect
24
+ expect ( testSubject ( value ) ) . toBe ( expected )
25
+ } )
26
+ } )
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
export { default as isExceptionCode } from './is-exception-code.guard'
7
+ export { default as isExceptionId } from './is-exception-id.guard'
7
8
export { default as isExceptionJSON } from './is-exception-json.guard'
8
9
export { default as isException } from './is-exception.guard'
Original file line number Diff line number Diff line change
1
+ import ExceptionId from '@packages/exceptions/enums/exception-id.enum'
2
+
3
+ /**
4
+ * @file Type Guards - isExceptionId
5
+ * @module exceptions/guards/isExceptionId
6
+ */
7
+
8
+ /**
9
+ * Checks if `value` is a valid `ExceptionId`.
10
+ *
11
+ * @param {any } [value] - Value to check
12
+ * @return {boolean } `true` if `ExceptionId`, `false` otherwise
13
+ */
14
+ const isExceptionId = ( value : any = { } ) : value is ExceptionId => {
15
+ return Object . keys ( ExceptionId ) . includes ( value )
16
+ }
17
+
18
+ export default isExceptionId
You can’t perform that action at this time.
0 commit comments