diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md new file mode 100644 index 0000000..7748e23 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -0,0 +1,13 @@ +## Change made + +- [ ]  New features +- [ ]  Bug fixes +- [ ]  Breaking changes +## Describe what you have done +- +### New Features +- +### Fix +- +### Others +- \ No newline at end of file diff --git a/internal/constant/error.constant.go b/internal/constant/error.constant.go index 8bc79f9..61efcea 100644 --- a/internal/constant/error.constant.go +++ b/internal/constant/error.constant.go @@ -4,3 +4,5 @@ const InvalidTokenErrorMessage = "Invalid token" const IncorrectEmailPasswordErrorMessage = "Incorrect email or password" const DuplicateEmailErrorMessage = "Duplicate email" const InternalServerErrorMessage = "Internal server error" + +const UserNotFoundErrorMessage = "User not found" diff --git a/internal/service/user/user.service.go b/internal/service/user/user.service.go index fe9036e..0c9e28a 100644 --- a/internal/service/user/user.service.go +++ b/internal/service/user/user.service.go @@ -3,6 +3,7 @@ package user import ( "context" "errors" + "github.com/isd-sgcu/johnjud-auth/internal/constant" "github.com/isd-sgcu/johnjud-auth/internal/domain/model" "github.com/isd-sgcu/johnjud-auth/internal/utils" @@ -29,6 +30,9 @@ func (s *serviceImpl) FindOne(_ context.Context, request *proto.FindOneUserReque err := s.repo.FindById(request.Id, &raw) if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, status.Error(codes.NotFound, constant.UserNotFoundErrorMessage) + } return nil, status.Error(codes.Internal, "Find one user failed") } diff --git a/internal/service/user/user.service_test.go b/internal/service/user/user.service_test.go index 70dd9ac..44ea3bf 100644 --- a/internal/service/user/user.service_test.go +++ b/internal/service/user/user.service_test.go @@ -3,12 +3,13 @@ package user import ( "context" "errors" + "testing" + "time" + "github.com/isd-sgcu/johnjud-auth/cfgldr" "github.com/isd-sgcu/johnjud-auth/internal/domain/model" mock "github.com/isd-sgcu/johnjud-auth/mocks/repository/user" "github.com/isd-sgcu/johnjud-auth/mocks/utils" - "testing" - "time" "github.com/go-faker/faker/v4" "github.com/google/uuid" @@ -99,6 +100,21 @@ func (t *UserServiceTest) TestFindOneSuccess() { assert.Equal(t.T(), want, actual) } +func (t *UserServiceTest) TestFindOneNotFoundErr() { + repo := &mock.UserRepositoryMock{} + repo.On("FindById", t.User.ID.String(), &model.User{}).Return(nil, gorm.ErrRecordNotFound) + + brcyptUtil := &utils.BcryptUtilMock{} + srv := NewService(repo, brcyptUtil) + actual, err := srv.FindOne(context.Background(), &proto.FindOneUserRequest{Id: t.User.ID.String()}) + + st, ok := status.FromError(err) + + assert.True(t.T(), ok) + assert.Nil(t.T(), actual) + assert.Equal(t.T(), codes.NotFound, st.Code()) +} + func (t *UserServiceTest) TestFindOneInternalErr() { repo := &mock.UserRepositoryMock{} repo.On("FindById", t.User.ID.String(), &model.User{}).Return(nil, errors.New("Not found user"))