import { AuthenticationClient } from "clients/authentication" ; import { chance , request } from "_/helpers" ; import { mockRegisterRequest } from "_/mocks/common" ; import { mockVerificationCode } from "_/mocks/verification" ; describe ( "POST /register/:code" , ( ) => { const auth = new AuthenticationClient ( ) ; it ( "should return empty body" , async ( ) => { const user = mockRegisterRequest ( ) ; const { id } = await auth . register ( user . email , user . password ) ; return request . post ( `/register/${ id }` ) . set ( "Content-Type" , "application/json" ) . expect ( 204 , "" ) ; } ) ; it ( "should return error for malformed request" , ( ) => { const { id } = mockVerificationCode ( "register" ) ; return request . post ( `/register/${ id }` ) . set ( "Content-Type" , "application/json" ) . send ( `/${ chance . string ( ) }` ) . expect ( 400 , { type : "TypeError" , message : "Invalid request" } ) ; } ) ; it ( "should return error for invalid request" , ( ) => { const { id } = mockVerificationCode ( "register" ) ; return request . post ( `/register/${ id }` ) . set ( "Content-Type" , "application/json" ) . send ( `{ "${ chance . word ( ) }": "${ chance . string ( ) }" }` ) . expect ( 400 , { type : "TypeError" , message : "Invalid request" } ) ; } ) ; it ( "should return error for invalid verification code" , ( ) => { const { id } = mockVerificationCode ( "register" ) ; return request . post ( `/register/${ id }` ) . set ( "Content-Type" , "application/json" ) . expect ( 403 , { type : "Error" , message : "Invalid verification code" } ) ; } ) ; } ) ;