import { RegisterVerificationParameters as Parameters , RegisterVerificationRequest as Request } from "common" ; import { post } from "handlers/register/verify" ; import { mockManagementClientVerifyUserWithError , mockManagementClientVerifyUserWithSuccess } from "_/mocks/clients" ; import { mockAPIGatewayProxyEvent } from "_/mocks/vendor/aws-lambda" ; import { mockVerificationClaimWithError , mockVerificationClaimWithResult , mockVerificationCode } from "_/mocks/verification" ; describe ( "handlers/register/verify" , ( ) => { describe ( "post" , ( ) => { const code = mockVerificationCode ( ) ; const event = mockAPIGatewayProxyEvent < Parameters , Request > ( { pathParameters : { code : code . id } } ) ; it ( "should resolve with empty body" , async ( ) => { const claimMock = mockVerificationClaimWithResult ( code ) ; const verifyUserMock = mockManagementClientVerifyUserWithSuccess ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 204 ) ; expect ( body ) . toEqual ( "" ) ; expect ( claimMock ) . toHaveBeenCalledWith ( "register" , code . id ) ; expect ( verifyUserMock ) . toHaveBeenCalledWith ( code . subject ) ; } ) ; it ( "should resolve with verification error" , async ( ) => { const claimMock = mockVerificationClaimWithError ( ) ; const verifyUserMock = mockManagementClientVerifyUserWithSuccess ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 403 ) ; expect ( body ) . toEqual ( JSON . stringify ( { type : "Error" , message : "claim" } ) ) ; expect ( claimMock ) . toHaveBeenCalledWith ( "register" , code . id ) ; expect ( verifyUserMock ) . not . toHaveBeenCalled ( ) ; } ) ; it ( "should resolve with management client error" , async ( ) => { const claimMock = mockVerificationClaimWithResult ( code ) ; const changePasswordMock = mockManagementClientVerifyUserWithError ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 403 ) ; expect ( body ) . toEqual ( JSON . stringify ( { type : "Error" , message : "verifyUser" } ) ) ; expect ( claimMock ) . toHaveBeenCalledWith ( "register" , code . id ) ; expect ( changePasswordMock ) . toHaveBeenCalledWith ( code . subject ) ; } ) ; } ) ; } ) ;