import { ApiAuthenticationDataSource } from '@data' ; import { MockBearerAuthorizationRxAxiosProvider } from '@mocks' ; import { of , throwError } from 'rxjs' ; import { RxAxiosProviderException } from '@core' ; describe ( 'ApiAuthenticationDataSource' , ( ) => { let dataSource ; let provider ; beforeEach ( ( ) => { provider = new MockBearerAuthorizationRxAxiosProvider ( { } ) ; dataSource = new ApiAuthenticationDataSource ( provider ) ; } ) ; it ( 'sign in successfully' , ( done ) => { provider . overrideFunctions = [ 'request' ] ; provider . mockResult = of ( { data : { data : { token : 'test' } } , config : { } , status : 200 , headers : { } , statusText : '' , } ) ; dataSource . signIn ( { } ) . subscribe ( { next : ( response ) => expect ( response . data . token ) . toBe ( 'test' ) , complete : done , } ) ; } ) ; it ( 'sign in failed' , ( done ) => { provider . overrideFunctions = [ 'request' ] ; provider . mockResult = throwError ( new RxAxiosProviderException ( JSON . parse ( '{}' ) ) ) ; dataSource . signIn ( { } ) . subscribe ( { error : ( error ) => { expect ( error ) . toBeInstanceOf ( RxAxiosProviderException ) ; expect ( error . rootCause ) . toStrictEqual ( { } ) ; done ( ) ; } , } ) ; } ) ; } ) ;