import { HttpStatusCode , ActionParamExceptionMiddleware , ActionParamException , ActionParamExceptionCode } from '../../../index' ; describe ( 'modules.builtin.middlewares.parse.exception.middleware.spec' , ( ) => { it ( 'invoke.sends_json_when_err_instanceof_ActionParamException' , ( ) => { let responseResult ; let statusCode ; let invoked = false ; let next = ( ) => invoked = true ; let res = { status : code => { statusCode = code ; return res ; } , json : data => responseResult = data } ; let err = new ActionParamException ( 'a' , 'b' , 'c' , 'd' , ActionParamExceptionCode . boolean ) ; new ActionParamExceptionMiddleware ( ) . invoke ( err , null , res , next ) ; expect ( responseResult ) . toEqual ( { value : err . value , message : err . message } ) ; expect ( statusCode ) . toBe ( HttpStatusCode . badRequest ) ; expect ( invoked ) . toBeFalsy ( ) ; } ) ; it ( 'invoke.next(err)_when_result_not_instanceof_ActionParamException' , ( ) => { let responseResult ; let statusCode ; let ex ; let next = err => ex = err ; let res = { status : code => { statusCode = code ; return res ; } , json : data => responseResult = data } ; new ActionParamExceptionMiddleware ( ) . invoke ( { test : 'true' } , null , res , next ) ; expect ( responseResult ) . toBe ( undefined ) ; expect ( statusCode ) . toBe ( undefined ) ; expect ( ex ) . toEqual ( { test : 'true' } ) ; } ) ; } ) ;