diff --git a/internal/selection/selection.service.go b/internal/selection/selection.service.go index a049e81..583509d 100644 --- a/internal/selection/selection.service.go +++ b/internal/selection/selection.service.go @@ -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() { diff --git a/internal/selection/test/selection.handler_test.go b/internal/selection/test/selection.handler_test.go index 532b84f..daad7b6 100644 --- a/internal/selection/test/selection.handler_test.go +++ b/internal/selection/test/selection.handler_test.go @@ -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) @@ -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()) @@ -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) @@ -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) @@ -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()) @@ -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) @@ -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) @@ -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()) @@ -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) diff --git a/internal/selection/test/selection.service_test.go b/internal/selection/test/selection.service_test.go index 11f2b8f..4fbf3d7 100644 --- a/internal/selection/test/selection.service_test.go +++ b/internal/selection/test/selection.service_test.go @@ -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" @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -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() { @@ -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) } @@ -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() { @@ -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() { @@ -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) }