import authorisationTrue from "../__mocks__/notification/authorisationTrue.json" ; import captureTrue from "../__mocks__/notification/captureTrue.json" ; import captureFalse from "../__mocks__/notification/captureFalse.json" ; import refundTrue from "../__mocks__/notification/refundTrue.json" ; import refundFalse from "../__mocks__/notification/refundFalse.json" ; import NotificationRequest from "../notification/notificationRequest" ; import { Notification , NotificationRequestItem } from "../typings/notification/models" ; import NotificationEnum = NotificationRequestItem . EventCodeEnum ; import SuccessEnum = NotificationRequestItem . SuccessEnum ; describe ( "Notification Test" , function ( ) : void { it ( "should return authorisation success" , function ( ) : void { const notificationRequest = new NotificationRequest ( authorisationTrue as unknown as Notification ) ; expect ( notificationRequest . notificationItems ) . toHaveLength ( 1 ) ; if ( notificationRequest . notificationItems ) { const notificationRequestItem = notificationRequest . notificationItems [ 0 ] ; expect ( NotificationEnum . Authorisation ) . toEqual ( notificationRequestItem . eventCode ) ; expect ( notificationRequestItem . success === SuccessEnum . True ) . toBeTruthy ( ) ; expect ( notificationRequestItem . pspReference ) . toEqual ( "123456789" ) ; expect ( notificationRequestItem . additionalData ! . paymentLinkId ) . toEqual ( "ABCDEFG" ) ; } else { fail ( ) ; } } ) ; it ( "should return capture success" , function ( ) : void { const notificationRequest = new NotificationRequest ( captureTrue as unknown as Notification ) ; expect ( notificationRequest . notificationItems ) . toHaveLength ( 1 ) ; if ( notificationRequest . notificationItems ) { const notificationRequestItem = notificationRequest . notificationItems [ 0 ] ; expect ( NotificationEnum . Capture ) . toEqual ( notificationRequestItem . eventCode ) ; expect ( notificationRequestItem . success === SuccessEnum . True ) . toBeTruthy ( ) ; expect ( notificationRequestItem . pspReference ) . toEqual ( "PSP_REFERENCE" ) ; expect ( notificationRequestItem . originalReference ) . toEqual ( "ORIGINAL_PSP" ) ; } else { fail ( ) ; } } ) ; it ( "should return capture fail" , function ( ) : void { const notificationRequest = new NotificationRequest ( captureFalse as unknown as Notification ) ; expect ( notificationRequest . notificationItems ) . toHaveLength ( 1 ) ; if ( notificationRequest . notificationItems ) { const notificationRequestItem = notificationRequest . notificationItems [ 0 ] ; expect ( NotificationEnum . Capture ) . toEqual ( notificationRequestItem . eventCode ) ; expect ( notificationRequestItem . success === SuccessEnum . True ) . toBeFalsy ( ) ; expect ( notificationRequestItem . pspReference ) . toEqual ( "PSP_REFERENCE" ) ; expect ( notificationRequestItem . originalReference ) . toEqual ( "ORIGINAL_PSP" ) ; } else { fail ( ) ; } } ) ; it ( "should return refund success" , function ( ) : void { const notificationRequest = new NotificationRequest ( refundTrue as unknown as Notification ) ; expect ( notificationRequest . notificationItems ) . toHaveLength ( 1 ) ; if ( notificationRequest . notificationItems ) { const notificationRequestItem = notificationRequest . notificationItems [ 0 ] ; expect ( NotificationEnum . Refund ) . toEqual ( notificationRequestItem . eventCode ) ; expect ( notificationRequestItem . success === SuccessEnum . True ) . toBeTruthy ( ) ; expect ( notificationRequestItem . pspReference ) . toEqual ( "PSP_REFERENCE" ) ; expect ( notificationRequestItem . originalReference ) . toEqual ( "ORIGINAL_PSP" ) ; expect ( notificationRequestItem . eventDate ) . toBeDefined ( ) ; } else { fail ( ) ; } } ) ; it ( "should return refund fail" , function ( ) : void { const notificationRequest = new NotificationRequest ( refundFalse as unknown as Notification ) ; expect ( notificationRequest . notificationItems ) . toHaveLength ( 1 ) ; if ( notificationRequest . notificationItems ) { const notificationRequestItem = notificationRequest . notificationItems [ 0 ] ; expect ( NotificationEnum . Refund ) . toEqual ( notificationRequestItem . eventCode ) ; expect ( notificationRequestItem . success === SuccessEnum . True ) . toBeFalsy ( ) ; expect ( notificationRequestItem . pspReference ) . toEqual ( "PSP_REFERENCE" ) ; expect ( notificationRequestItem . originalReference ) . toEqual ( "ORIGINAL_PSP" ) ; expect ( notificationRequestItem . eventDate ) . toBeDefined ( ) ; } else { fail ( ) ; } } ) ; } ) ;