import { AppError } from "./app-error.model" ; describe ( "AppError" , ( ) => { it ( "should have been registered to be used" , ( done ) => { const genuineErrorCode = AppError . FT_NO_ACTIVITIES ; const genuineErrorMessage = "No minimum required activities!" ; const appError = new AppError ( genuineErrorCode , genuineErrorMessage ) ; expect ( appError ) . not . toBeNull ( ) ; expect ( appError . code ) . toBe ( genuineErrorCode ) ; expect ( appError . message ) . toBe ( genuineErrorMessage ) ; done ( ) ; } ) ; it ( "should not be used if not registered" , ( done ) => { const myErrorCode = "MY_ERR_01" ; const myErrorMessage = "This is error message" ; const call = ( ) => { new AppError ( myErrorCode , myErrorMessage ) ; } ; expect ( call ) . toThrow ( new Error ( myErrorCode + " error is not registered" ) ) ; done ( ) ; } ) ; it ( "should not be used if duplicate" , ( done ) => { const genuineErrorCode = AppError . FT_NO_ACTIVITIES ; const genuineErrorMessage = "No minimum required activities!" ; const fakeAppError = new AppError ( genuineErrorCode , genuineErrorMessage ) ; const duplicateErrorCode = "FAKE_DUPLICATE" ; fakeAppError . _codes = [ AppError . FT_NO_ACTIVITIES , duplicateErrorCode , duplicateErrorCode , ] ; const call = ( ) => { fakeAppError . checkForDuplicatesErrors ( ) ; } ; expect ( call ) . toThrow ( new Error ( duplicateErrorCode + " error codes are duplicated" ) ) ; done ( ) ; } ) ; } ) ;