1
1
// eslint-disable-next-line no-restricted-imports,@seedcompany/no-restricted-imports
2
2
import * as Nest from '@nestjs/common' ;
3
+ import * as Fastify from 'fastify' ;
3
4
import { InputException , ServerException } from '~/common' ;
4
5
import { ConstraintError } from '../database' ;
5
6
import { ExceptionNormalizer } from './exception.normalizer' ;
@@ -10,6 +11,23 @@ describe('ExceptionNormalizer', () => {
10
11
const orig = sut . normalize . bind ( sut ) ;
11
12
sut . normalize = ( ...args ) => JSON . parse ( JSON . stringify ( orig ( ...args ) ) ) ;
12
13
14
+ describe ( 'Fastify' , ( ) => {
15
+ it ( 'Client' , ( ) => {
16
+ const ex = new Fastify . errorCodes . FST_ERR_CTP_BODY_TOO_LARGE ( ) ;
17
+ const res = sut . normalize ( { ex } ) ;
18
+ expect ( res . message ) . toEqual ( 'Request body is too large' ) ;
19
+ expect ( res . code ) . toEqual ( 'FST_ERR_CTP_BODY_TOO_LARGE' ) ;
20
+ expect ( res . codes ) . toEqual ( [ 'FST_ERR_CTP_BODY_TOO_LARGE' , 'Client' ] ) ;
21
+ } ) ;
22
+ it ( 'Server' , ( ) => {
23
+ const ex = new Fastify . errorCodes . FST_ERR_HOOK_INVALID_TYPE ( ) ;
24
+ const res = sut . normalize ( { ex } ) ;
25
+ expect ( res . message ) . toEqual ( 'The hook name must be a string' ) ;
26
+ expect ( res . code ) . toEqual ( 'FST_ERR_HOOK_INVALID_TYPE' ) ;
27
+ expect ( res . codes ) . toEqual ( [ 'FST_ERR_HOOK_INVALID_TYPE' , 'Server' ] ) ;
28
+ } ) ;
29
+ } ) ;
30
+
13
31
describe ( 'HttpException' , ( ) => {
14
32
it ( 'simple' , ( ) => {
15
33
const ex = new Nest . NotFoundException ( ) ;
0 commit comments