import { errors } from 'oidc-provider' ; import { OidcProviderRuntimeException } from './oidc-provider-runtime-exception' ; describe ( 'OidcProviderRuntimeException' , ( ) => { beforeEach ( ( ) => { jest . resetAllMocks ( ) ; } ) ; describe ( 'getCodeFromError' , ( ) => { it ( 'should call return code for given error class' , ( ) => { const error = new errors . SessionNotFound ( 'foo' ) ; const exception = new OidcProviderRuntimeException ( error ) ; const result = exception . getCodeFromError ( error ) ; expect ( result ) . toBe ( 110 ) ; } ) ; it ( 'should call return code for another given error class' , ( ) => { const error = new errors . InvalidClient ( 'foo' ) ; const exception = new OidcProviderRuntimeException ( error ) ; const result = exception . getCodeFromError ( error ) ; expect ( result ) . toBe ( 106 ) ; } ) ; it ( 'should call return code for yet antoher given error class' , ( ) => { const error = new errors . UnsupportedGrantType ( 'foo' ) ; const exception = new OidcProviderRuntimeException ( error ) ; const result = exception . getCodeFromError ( error ) ; expect ( result ) . toBe ( 126 ) ; } ) ; it ( 'shoud return default code if error is not instance of any known error' , ( ) => { const error = new TypeError ( 'foo' ) ; const exception = new OidcProviderRuntimeException ( error ) ; const result = exception . getCodeFromError ( error as errors . OIDCProviderError ) ; expect ( result ) . toBe ( 100 ) ; } ) ; it ( 'shoud return default code if the error is not instance of any known error and an unknown code is provided' , ( ) => { const error = new TypeError ( 'foo' ) ; const exception = new OidcProviderRuntimeException ( error , 666 ) ; const result = exception . getCodeFromError ( error as errors . OIDCProviderError ) ; expect ( result ) . toBe ( 100 ) ; } ) ; } ) ; } ) ;