import { ResetVerificationParameters as Parameters , ResetVerificationRequest as Request } from "common" ; import { post } from "handlers/reset/verify" ; import { mockManagementClientChangePasswordWithError , mockManagementClientChangePasswordWithSuccess } from "_/mocks/clients" ; import { mockResetVerifyRequest } from "_/mocks/common" ; import { mockAPIGatewayProxyEvent } from "_/mocks/vendor/aws-lambda" ; import { mockVerificationClaimWithError , mockVerificationClaimWithResult , mockVerificationCode } from "_/mocks/verification" ; describe ( "handlers/reset/verify" , ( ) => { describe ( "post" , ( ) => { const { password } = mockResetVerifyRequest ( ) ; const code = mockVerificationCode ( ) ; const event = mockAPIGatewayProxyEvent < Parameters , Request > ( { body : { password } , pathParameters : { code : code . id } } ) ; it ( "should resolve with empty body" , async ( ) => { const claimMock = mockVerificationClaimWithResult ( code ) ; const changePasswordMock = mockManagementClientChangePasswordWithSuccess ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 204 ) ; expect ( body ) . toEqual ( "" ) ; expect ( claimMock ) . toHaveBeenCalledWith ( "reset" , code . id ) ; expect ( changePasswordMock ) . toHaveBeenCalledWith ( code . subject , password ) ; } ) ; it ( "should resolve with password policy error" , async ( ) => { const claimMock = mockVerificationClaimWithError ( ) ; const { statusCode , body } = await post ( mockAPIGatewayProxyEvent < Parameters , Request > ( { body : { password : "" } } ) ) ; expect ( statusCode ) . toEqual ( 400 ) ; expect ( body ) . toEqual ( JSON . stringify ( { type : "Error" , message : "Password must be at least 8 letters long, " + "contain a capital letter, " + "contain a lowercase letter, " + "contain a number, " + "and contain a special character" } ) ) ; expect ( claimMock ) . not . toHaveBeenCalledWith ( ) ; } ) ; it ( "should resolve with verification error" , async ( ) => { const claimMock = mockVerificationClaimWithError ( ) ; const changePasswordMock = mockManagementClientChangePasswordWithSuccess ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 403 ) ; expect ( body ) . toEqual ( JSON . stringify ( { type : "Error" , message : "claim" } ) ) ; expect ( claimMock ) . toHaveBeenCalledWith ( "reset" , code . id ) ; expect ( changePasswordMock ) . not . toHaveBeenCalled ( ) ; } ) ; it ( "should resolve with management client error" , async ( ) => { const claimMock = mockVerificationClaimWithResult ( code ) ; const changePasswordMock = mockManagementClientChangePasswordWithError ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 403 ) ; expect ( body ) . toEqual ( JSON . stringify ( { type : "Error" , message : "changePassword" } ) ) ; expect ( claimMock ) . toHaveBeenCalledWith ( "reset" , code . id ) ; expect ( changePasswordMock ) . toHaveBeenCalledWith ( code . subject , password ) ; } ) ; } ) ; } ) ;