diff --git a/src/app/handler/auth/auth.handler.go b/src/app/handler/auth/auth.handler.go index 92bfa5e..015b743 100644 --- a/src/app/handler/auth/auth.handler.go +++ b/src/app/handler/auth/auth.handler.go @@ -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) } diff --git a/src/app/handler/auth/auth.handler_test.go b/src/app/handler/auth/auth.handler_test.go index 31a081a..4fded7d 100644 --- a/src/app/handler/auth/auth.handler_test.go +++ b/src/app/handler/auth/auth.handler_test.go @@ -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) +} diff --git a/src/main.go b/src/main.go index 50973fc..c0f0bc7 100644 --- a/src/main.go +++ b/src/main.go @@ -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) diff --git a/src/mocks/service/auth/auth.mock.go b/src/mocks/service/auth/auth.mock.go index 43dd28f..a1b9288 100644 --- a/src/mocks/service/auth/auth.mock.go +++ b/src/mocks/service/auth/auth.mock.go @@ -66,10 +66,10 @@ func (mr *MockServiceMockRecorder) SignIn(arg0 interface{}) *gomock.Call { } // SignOut mocks base method. -func (m *MockService) SignOut(arg0 string) (bool, *dto.ResponseErr) { +func (m *MockService) SignOut(arg0 string) (*dto.SignOutResponse, *dto.ResponseErr) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignOut", arg0) - ret0, _ := ret[0].(bool) + ret0, _ := ret[0].(*dto.SignOutResponse) ret1, _ := ret[1].(*dto.ResponseErr) return ret0, ret1 }