import { TrackingService } from '@fc/tracking' ; import { TrackableEventHandler } from './trackable-event.handler' ; describe ( 'TrackableEventHandler' , ( ) => { TODO see https const trackingServiceMock = { EventsMap : { FC_RECEIVED_DECEASED_RNIPP : { event : 'FC_RECEIVED_DECEASED_RNIPP' , exceptions : [ 'RnippDeceasedException' ] , } , FC_RECEIVED_INVALID_RNIPP : { event : 'FC_RECEIVED_INVALID_RNIPP' , exceptions : [ 'RnippNotFoundMultipleEchoException' , 'RnippNotFoundNoEchoException' , 'RnippNotFoundSingleEchoException' , 'RnippFoundOnlyWithMaritalNameException' , ] , } , } , log : jest . fn ( ) , } as unknown as TrackingService ; const handler = new TrackableEventHandler ( trackingServiceMock ) ; beforeEach ( ( ) => { jest . resetAllMocks ( ) ; jest . restoreAllMocks ( ) ; } ) ; describe ( 'handle' , ( ) => { it ( 'should call log function if exception found in event map' , ( ) => { const eventMock = { context : { exception : { constructor : 'RnippDeceasedException' , } , } , } ; jest . spyOn ( trackingServiceMock , 'log' ) ; handler . handle ( eventMock ) ; expect ( trackingServiceMock . log ) . toHaveBeenCalledTimes ( 1 ) ; } ) ; it ( 'should not call log function if no exception found in event map' , ( ) => { const eventMock = { context : { exception : { constructor : 'exceptionNotFound' , } , } , } ; jest . spyOn ( trackingServiceMock , 'log' ) ; handler . handle ( eventMock ) ; expect ( trackingServiceMock . log ) . toHaveBeenCalledTimes ( 0 ) ; } ) ; } ) ; describe ( 'getEventFromMap' , ( ) => { it ( 'should return event map if rnipp throws "desceased" exception' , ( ) => { const RnippDeceasedExceptionMock = { exception : { constructor : 'RnippDeceasedException' , } , } ; const result = handler [ 'getEventFromMap' ] ( RnippDeceasedExceptionMock ) ; expect ( result ) . toMatchObject ( { event : 'FC_RECEIVED_DECEASED_RNIPP' , exceptions : [ 'RnippDeceasedException' ] , } ) ; } ) ; it ( 'should return event map if rnipp throws "not found multiple echo" exception' , ( ) => { const RnippNotFoundMultipleEchoExceptionMock = { exception : { constructor : 'RnippNotFoundMultipleEchoException' , } , } ; const result = handler [ 'getEventFromMap' ] ( RnippNotFoundMultipleEchoExceptionMock ) ; expect ( result ) . toMatchObject ( { event : 'FC_RECEIVED_INVALID_RNIPP' , exceptions : [ 'RnippNotFoundMultipleEchoException' , 'RnippNotFoundNoEchoException' , 'RnippNotFoundSingleEchoException' , 'RnippFoundOnlyWithMaritalNameException' , ] , } ) ; } ) ; it ( 'should return undefined if no context is set' , ( ) => { const result = handler [ 'getEventFromMap' ] ( ) ; expect ( result ) . toBeUndefined ; } ) ; it ( 'should return undefined if there are no class defined (undefined exceptions)' , ( ) => { const ExceptionMock = { } ; const result = handler [ 'getEventFromMap' ] ( ExceptionMock ) ; expect ( result ) . toBeUndefined ; } ) ; it ( 'should return undefined if there are no class defined (undefined constructor)' , ( ) => { const ExceptionMock = { exceptions : { } } ; const result = handler [ 'getEventFromMap' ] ( ExceptionMock ) ; expect ( result ) . toBeUndefined ; } ) ; } ) ; } ) ;