Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
macgeargear committed Jun 23, 2024
1 parent 61686be commit 716423a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 59 deletions.
2 changes: 1 addition & 1 deletion internal/selection/selection.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *serviceImpl) UpdateSelection(req *dto.UpdateSelectionRequest) (*dto.Upd
if err != nil {
st, ok := status.FromError(err)
if !ok {
s.log.Named("UpdateSelection").Error("FromeError: ", zap.Error(err))
s.log.Named("UpdateSelection").Error("FromError: ", zap.Error(err))
return nil, apperror.InternalServer
}
switch st.Code() {
Expand Down
60 changes: 21 additions & 39 deletions internal/selection/test/selection.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ func (t *SelectionHandlerTest) TestCreateSelectionSuccess() {
Selection: t.Selection,
}

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

selectionSvc := selectionMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)
selectionSvc := selectionMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Bind(t.CreateSelectionReq).Return(nil)
validator.EXPECT().Validate(t.CreateSelectionReq).Return(nil)
Expand All @@ -72,9 +70,7 @@ func (t *SelectionHandlerTest) TestCreateSelectionSuccess() {
func (t *SelectionHandlerTest) TestCreateSelectionInvalidArgument() {
expectedErr := apperror.BadRequestError("invalid argument")

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

context := routerMock.NewMockContext(controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Bind(t.CreateSelectionReq).Return(expectedErr)
context.EXPECT().BadRequestError(expectedErr.Error())
Expand All @@ -86,11 +82,9 @@ func (t *SelectionHandlerTest) TestCreateSelectionInvalidArgument() {
func (t *SelectionHandlerTest) TestCreateSelectionInternalError() {
expectedErr := apperror.InternalServerError("internal error")

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

selectionSvc := selectionMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)
selectionSvc := selectionMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Bind(t.CreateSelectionReq).Return(nil)
validator.EXPECT().Validate(t.CreateSelectionReq).Return(nil)
Expand All @@ -107,11 +101,9 @@ func (t *SelectionHandlerTest) TestFindByStudentIdSelectionSuccess() {
Selection: t.Selection,
}

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

selectionSvc := selectionMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)
selectionSvc := selectionMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Param("id").Return(t.Selection.GroupId)
validator.EXPECT().Validate(t.FindByGroupIdSelectionReq).Return(nil)
Expand All @@ -126,9 +118,7 @@ func (t *SelectionHandlerTest) TestFindByStudentIdSelectionSuccess() {
func (t *SelectionHandlerTest) TestFindByStudentIdSelectionInvalidArgument() {
expectedErr := apperror.BadRequestError("url parameter 'id' not found")

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

context := routerMock.NewMockContext(controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Param("id").Return("")
context.EXPECT().BadRequestError(expectedErr.Error())
Expand All @@ -140,11 +130,9 @@ func (t *SelectionHandlerTest) TestFindByStudentIdSelectionInvalidArgument() {
func (t *SelectionHandlerTest) TestFindByStudentIdSelectionInternalError() {
expectedErr := apperror.InternalServerError("internal error")

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

selectionSvc := selectionMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)
selectionSvc := selectionMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Param("id").Return(t.Selection.GroupId)
validator.EXPECT().Validate(t.FindByGroupIdSelectionReq).Return(nil)
Expand All @@ -161,11 +149,9 @@ func (t *SelectionHandlerTest) TestUpdateSelectionSuccess() {
Success: true,
}

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

selectionSvc := selectionMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)
selectionSvc := selectionMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Bind(t.UpdateSelectionReq).Return(nil)
validator.EXPECT().Validate(t.UpdateSelectionReq).Return(nil)
Expand All @@ -179,9 +165,7 @@ func (t *SelectionHandlerTest) TestUpdateSelectionSuccess() {
func (t *SelectionHandlerTest) TestUpdateSelectionInvalidArgument() {
expectedErr := apperror.BadRequestError("invalid argument")

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

context := routerMock.NewMockContext(controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Bind(t.UpdateSelectionReq).Return(expectedErr)
context.EXPECT().BadRequestError(expectedErr.Error())
Expand All @@ -193,11 +177,9 @@ func (t *SelectionHandlerTest) TestUpdateSelectionInvalidArgument() {
func (t *SelectionHandlerTest) TestUpdateSelectionInternalError() {
expectedErr := apperror.InternalServerError("internal error")

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

selectionSvc := selectionMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)
selectionSvc := selectionMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)

context.EXPECT().Bind(t.UpdateSelectionReq).Return(nil)
validator.EXPECT().Validate(t.UpdateSelectionReq).Return(nil)
Expand Down
37 changes: 18 additions & 19 deletions internal/selection/test/selection.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/isd-sgcu/rpkm67-gateway/internal/selection"
selectionMock "github.com/isd-sgcu/rpkm67-gateway/mocks/client/selection"
selectionProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/backend/selection/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -85,8 +84,8 @@ func (t *SelectionServiceTest) TestCreateSelectionSuccess() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.CreateSelection(t.CreateSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestCreateSelectionInvalidArgument() {
Expand All @@ -102,8 +101,8 @@ func (t *SelectionServiceTest) TestCreateSelectionInvalidArgument() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.CreateSelection(t.CreateSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestCreateSelectionInternalError() {
Expand All @@ -119,8 +118,8 @@ func (t *SelectionServiceTest) TestCreateSelectionInternalError() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.CreateSelection(t.CreateSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestFindByGroupIdSelectionSuccess() {
Expand All @@ -138,8 +137,8 @@ func (t *SelectionServiceTest) TestFindByGroupIdSelectionSuccess() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.FindByGroupIdSelection(t.FindByGroupIdSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestFindByGroupIdSelectionInvalidArgument() {
Expand All @@ -155,8 +154,8 @@ func (t *SelectionServiceTest) TestFindByGroupIdSelectionInvalidArgument() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.FindByGroupIdSelection(t.FindByGroupIdSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestFindByGroupIdSelectionInternalError() {
Expand All @@ -172,8 +171,8 @@ func (t *SelectionServiceTest) TestFindByGroupIdSelectionInternalError() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.FindByGroupIdSelection(t.FindByGroupIdSelectionDtoRequest)

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

}

Expand All @@ -192,8 +191,8 @@ func (t *SelectionServiceTest) TestUpdateSelectionSuccess() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.UpdateSelection(t.UpdateSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestUpdateSelectionInvalidArgument() {
Expand All @@ -209,8 +208,8 @@ func (t *SelectionServiceTest) TestUpdateSelectionInvalidArgument() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.UpdateSelection(t.UpdateSelectionDtoRequest)

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

func (t *SelectionServiceTest) TestUpdateSelectionInternalError() {
Expand All @@ -226,6 +225,6 @@ func (t *SelectionServiceTest) TestUpdateSelectionInternalError() {
svc := selection.NewService(&client, t.logger)
actual, err := svc.UpdateSelection(t.UpdateSelectionDtoRequest)

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

0 comments on commit 716423a

Please sign in to comment.