Skip to content

Commit

Permalink
Merge pull request #4 from isd-sgcu/fix/baan-tests-2
Browse files Browse the repository at this point in the history
Fix/baan tests 2
  • Loading branch information
bookpanda authored Jun 23, 2024
2 parents ecc0157 + c444d28 commit 5c01e25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [ ]  New features
- [ ]  Bug fixes
- [ ]  Breaking changes
- [ ] Refactor
## Describe what you have done
-
### New Features
Expand Down
24 changes: 10 additions & 14 deletions internal/baan/test/baan.handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,36 @@ func (t *BaanHandlerTest) SetupTest() {
}

func (t *BaanHandlerTest) TestFindAllBaanSuccess() {
baanSvc := baanMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)
handler := baan.NewHandler(baanSvc, validator, t.logger)

expectedResp := &dto.FindAllBaanResponse{
Baans: t.Baans,
}

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

baanSvc := baanMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)

baanSvc.EXPECT().FindAllBaan(t.FindAllBaanReq).Return(expectedResp, t.Err)
context.EXPECT().JSON(http.StatusOK, expectedResp)

handler := baan.NewHandler(baanSvc, validator, t.logger)
handler.FindAllBaan(context)
}

func (t *BaanHandlerTest) TestFindOneBaanSuccess() {
baanSvc := baanMock.NewMockService(t.controller)
validator := validatorMock.NewMockDtoValidator(t.controller)
context := routerMock.NewMockContext(t.controller)
handler := baan.NewHandler(baanSvc, validator, t.logger)

expectedResp := &dto.FindOneBaanResponse{
Baan: t.Baan,
}

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

baanSvc := baanMock.NewMockService(controller)
validator := validatorMock.NewMockDtoValidator(controller)
context := routerMock.NewMockContext(controller)

context.EXPECT().Param("id").Return(t.ParamMock)
validator.EXPECT().Validate(t.FindOneBaanReq).Return(nil)
baanSvc.EXPECT().FindOneBaan(t.FindOneBaanReq).Return(expectedResp, t.Err)
context.EXPECT().JSON(http.StatusOK, expectedResp)

handler := baan.NewHandler(baanSvc, validator, t.logger)
handler.FindOneBaan(context)
}

Expand Down
24 changes: 10 additions & 14 deletions internal/baan/test/baan.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/dto"
baanMock "github.com/isd-sgcu/rpkm67-gateway/mocks/client/baan"
baanProto "github.com/isd-sgcu/rpkm67-go-proto/rpkm67/backend/baan/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -53,43 +52,40 @@ func (t *BaanServiceTest) SetupTest() {
}

func (t *BaanServiceTest) TestFindAllBaanSuccess() {
client := baanMock.BaanClientMock{}
svc := baan.NewService(&client, t.logger)

protoResp := &baanProto.FindAllBaanResponse{
Baans: t.BaansProto,
}

findAllBaansDto := baan.ProtoToDtoList(protoResp.Baans)

expected := &dto.FindAllBaanResponse{
Baans: findAllBaansDto,
}

client := baanMock.BaanClientMock{}
client.On("FindAllBaan", t.FindAllBaanProtoReq).Return(protoResp, nil)

svc := baan.NewService(&client, t.logger)
actual, err := svc.FindAllBaan(t.FindAllBaanDtoReq)

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

func (t *BaanServiceTest) TestFindOneBaanSuccess() {
client := baanMock.BaanClientMock{}
svc := baan.NewService(&client, t.logger)

protoResp := &baanProto.FindOneBaanResponse{
Baan: t.BaanProto,
}

expected := &dto.FindOneBaanResponse{
Baan: t.BaanDto,
}

client := baanMock.BaanClientMock{}
client.On("FindOneBaan", t.FindOneBaanProtoReq).Return(protoResp, nil)

svc := baan.NewService(&client, t.logger)
actual, err := svc.FindOneBaan(t.FindOneBaanDtoReq)

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

func (t *BaanServiceTest) TearDownTest() {
Expand Down

0 comments on commit 5c01e25

Please sign in to comment.