Skip to content

Commit

Permalink
feat: implement sign out handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitiwat-owen committed Jan 2, 2024
1 parent 1ec6406 commit 7d742c6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/app/handler/auth/auth.handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ func (h *Handler) SignIn(c router.IContext) {
c.JSON(http.StatusOK, response)
}

func (h *Handler) Signout(c router.IContext) {
func (h *Handler) SignOut(c router.IContext) {
token := c.Token()

response, respErr := h.service.SignOut(token)
if respErr != nil {
c.JSON(respErr.StatusCode, respErr)
return
}

c.JSON(http.StatusOK, response)
}
46 changes: 46 additions & 0 deletions src/app/handler/auth/auth.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,49 @@ func (t *AuthHandlerTest) TestSignInServiceError() {

handler.SignIn(context)
}

func (t *AuthHandlerTest) TestSignOutSuccess() {
token := faker.Word()
signOutResponse := &dto.SignOutResponse{
IsSuccess: true,
}

controller := gomock.NewController(t.T())

authSvc := mock_auth.NewMockService(controller)
userSvc := mock_user.NewMockService(controller)
validator := mock_validator.NewMockIDtoValidator(controller)
context := mock_router.NewMockIContext(controller)

context.EXPECT().Token().Return(token)
authSvc.EXPECT().SignOut(token).Return(signOutResponse)
context.EXPECT().JSON(http.StatusOK, signOutResponse)

handler := NewHandler(authSvc, userSvc, validator)

handler.SignOut(context)
}

func (t *AuthHandlerTest) TestSignOutServiceError() {
token := faker.Word()
errResponse := &dto.ResponseErr{
StatusCode: http.StatusInternalServerError,
Message: constant.InternalErrorMessage,
Data: nil,
}

controller := gomock.NewController(t.T())

authSvc := mock_auth.NewMockService(controller)
userSvc := mock_user.NewMockService(controller)
validator := mock_validator.NewMockIDtoValidator(controller)
context := mock_router.NewMockIContext(controller)

handler := NewHandler(authSvc, userSvc, validator)

context.EXPECT().Token().Return(token)
authSvc.EXPECT().SignOut(token).Return(errResponse)
context.EXPECT().JSON(http.StatusInternalServerError, errResponse)

handler.SignOut(context)
}
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func main() {

r.PostAuth("/signup", authHandler.Signup)
r.PostAuth("/signin", authHandler.SignIn)
r.PostAuth("/signout", authHandler.Signout)
r.PostAuth("/signout", authHandler.SignOut)
r.PostAuth("/me", authHandler.Validate)
r.PostAuth("/refreshToken", authHandler.RefreshToken)

Expand Down
4 changes: 2 additions & 2 deletions src/mocks/service/auth/auth.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d742c6

Please sign in to comment.