import { RegisterRequest as Request } from "common" ; import { post } from "handlers/register" ; import { mockAuthenticationClientRegisterWithError , mockAuthenticationClientRegisterWithSuccess } from "_/mocks/clients" ; import { mockRegisterRequest } from "_/mocks/common/events/register" ; import { mockAPIGatewayProxyEvent } from "_/mocks/vendor/aws-lambda" ; describe ( "handlers/register" , ( ) => { describe ( "post" , ( ) => { const { email , password } = mockRegisterRequest ( ) ; const event = mockAPIGatewayProxyEvent < Request > ( { body : { email , password } } ) ; it ( "should resolve with empty body" , async ( ) => { const registerMock = mockAuthenticationClientRegisterWithSuccess ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 204 ) ; expect ( body ) . toEqual ( "" ) ; expect ( registerMock ) . toHaveBeenCalledWith ( email , password ) ; } ) ; it ( "should resolve with password policy error" , async ( ) => { const registerMock = mockAuthenticationClientRegisterWithError ( ) ; const { statusCode , body } = await post ( mockAPIGatewayProxyEvent < Request > ( { body : { email , 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 ( registerMock ) . not . toHaveBeenCalled ( ) ; } ) ; it ( "should resolve with authentication client error" , async ( ) => { const registerMock = mockAuthenticationClientRegisterWithError ( ) ; const { statusCode , body } = await post ( event ) ; expect ( statusCode ) . toEqual ( 400 ) ; expect ( body ) . toEqual ( JSON . stringify ( { type : "Error" , message : "register" } ) ) ; expect ( registerMock ) . toHaveBeenCalledWith ( email , password ) ; } ) ; } ) ; } ) ;