import { SessionClient } from "clients/session" ; import { chance } from "_/helpers" ; import { mockCognitoGlobalSignOutWithError , mockCognitoGlobalSignOutWithSuccess , restoreCognitoGlobalSignOut } from "_/mocks/vendor/aws-sdk" ; describe ( "clients/session" , ( ) => { describe ( "SessionClient" , ( ) => { describe ( "#signOut" , ( ) => { const token = chance . hash ( { length : 128 } ) ; afterEach ( ( ) => { restoreCognitoGlobalSignOut ( ) ; } ) ; it ( "should resolve with no result" , async ( ) => { mockCognitoGlobalSignOutWithSuccess ( ) ; const session = new SessionClient ( token ) ; expect ( await session . signOut ( ) ) . toBeUndefined ( ) ; } ) ; it ( "should sign out user" , async ( ) => { const globalSignOutMock = mockCognitoGlobalSignOutWithSuccess ( ) ; const session = new SessionClient ( token ) ; await session . signOut ( ) ; expect ( globalSignOutMock ) . toHaveBeenCalledWith ( { AccessToken : token } ) ; } ) ; it ( "should reject on AWS Cognito error" , async ( done ) => { const errMock = new Error ( ) ; const globalSignOutMock = mockCognitoGlobalSignOutWithError ( errMock ) ; try { const session = new SessionClient ( token ) ; await session . signOut ( ) ; done . fail ( ) ; } catch ( err ) { expect ( globalSignOutMock ) . toHaveBeenCalled ( ) ; expect ( err ) . toBe ( errMock ) ; done ( ) ; } } ) ; } ) ; } ) ; } ) ;