import { Callback } from "aws-lambda" ; import { mock , restore } from "aws-sdk-mock" ; import { chance } from "_/helpers" ; param spy return function mockCognitoInitiateAuth ( spy ) { mock ( "CognitoIdentityServiceProvider" , "initiateAuth" , ( data , cb ) => { cb ( undefined , spy ( data ) ) ; } ) ; return spy ; } return export function mockCognitoInitiateAuthWithCredentials ( ) { return mockCognitoInitiateAuth ( jasmine . createSpy ( "initiateAuth" ) . and . returnValue ( { AuthenticationResult : { AccessToken : chance . hash ( { length : 128 } ) , IdToken : chance . hash ( { length : 128 } ) , RefreshToken : chance . hash ( { length : 128 } ) } } ) ) ; } return export function mockCognitoInitiateAuthWithToken ( ) { return mockCognitoInitiateAuth ( jasmine . createSpy ( "initiateAuth" ) . and . returnValue ( { AuthenticationResult : { AccessToken : chance . hash ( { length : 128 } ) , IdToken : chance . hash ( { length : 128 } ) } } ) ) ; } param challenge return export function mockCognitoInitiateAuthWithChallenge ( challenge = chance . string ( ) ) { return mockCognitoInitiateAuth ( jasmine . createSpy ( "initiateAuth" ) . and . returnValue ( { ChallengeName : challenge } ) ) ; } param err return export function mockCognitoInitiateAuthWithError ( err = new Error ( "initiateAuth" ) ) { return mockCognitoInitiateAuth ( jasmine . createSpy ( "initiateAuth" ) . and . callFake ( ( ) => { throw err ; } ) ) ; } /**
 * Restore `CognitoIdentityServiceProvider.initiateAuth`
 */ export function restoreCognitoInitiateAuth ( ) { restore ( "CognitoIdentityServiceProvider" , "initiateAuth" ) ; }