Skip to content

Commit

Permalink
fix: sign out
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitiwat-owen committed Dec 28, 2023
1 parent 192599b commit ce783fb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 46 deletions.
3 changes: 0 additions & 3 deletions src/internal/constant/common.constant.go

This file was deleted.

7 changes: 2 additions & 5 deletions src/internal/service/auth/auth.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ func (s *serviceImpl) SignIn(_ context.Context, request *authProto.SignInRequest
}

func (s *serviceImpl) SignOut(_ context.Context, request *authProto.SignOutRequest) (*authProto.SignOutResponse, error) {
err := s.cacheRepo.AddSetMember(constant.BlacklistTokenCacheKey, request.Token)
if err != nil {
return nil, status.Error(codes.Internal, constant.InternalServerErrorMessage)
}

// validate
// remove cache
return &authProto.SignOutResponse{IsSuccess: true}, nil
}

Expand Down
41 changes: 3 additions & 38 deletions src/internal/service/auth/auth.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,45 +388,10 @@ func (t *AuthServiceTest) TestRefreshTokenCreateCredentialFailed() {}
func (t *AuthServiceTest) TestRefreshTokenUpdateTokenFailed() {}

func (t *AuthServiceTest) TestSignOutSuccess() {
expected := &authProto.SignOutResponse{
IsSuccess: true,
}

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

userRepo := user.UserRepositoryMock{}
tokenService := token.TokenServiceMock{}
bcryptUtil := utils.BcryptUtilMock{}
cacheRepo := mock_cache.NewMockRepository(controller)

cacheRepo.EXPECT().AddSetMember(constant.BlacklistTokenCacheKey, t.signOutRequest.Token).Return(nil)

authSvc := NewService(&userRepo, &tokenService, &bcryptUtil, cacheRepo)
actual, err := authSvc.SignOut(t.ctx, t.signOutRequest)

assert.Nil(t.T(), err)
assert.Equal(t.T(), expected, actual)
}

func (t *AuthServiceTest) TestSignOutAddCacheFailed() {
setError := errors.New("Internal server error")
expected := status.Error(codes.Internal, constant.InternalServerErrorMessage)

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

userRepo := user.UserRepositoryMock{}
tokenService := token.TokenServiceMock{}
bcryptUtil := utils.BcryptUtilMock{}
cacheRepo := mock_cache.NewMockRepository(controller)

cacheRepo.EXPECT().AddSetMember(constant.BlacklistTokenCacheKey, t.signOutRequest.Token).Return(setError)

authSvc := NewService(&userRepo, &tokenService, &bcryptUtil, cacheRepo)
actual, err := authSvc.SignOut(t.ctx, t.signOutRequest)
func (t *AuthServiceTest) TestSignOutValidateFailed() {
}

st, ok := status.FromError(err)
assert.Nil(t.T(), actual)
assert.Equal(t.T(), codes.Internal, st.Code())
assert.True(t.T(), ok)
assert.Equal(t.T(), expected.Error(), err.Error())
func (t *AuthServiceTest) TestSignOutRemoveTokenCacheFailed() {
}

0 comments on commit ce783fb

Please sign in to comment.