Skip to content

Commit

Permalink
feat: test upload success
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Feb 2, 2024
1 parent 5b8a678 commit 8146ed8
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/app/service/image/image.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import (

type ImageServiceTest struct {
suite.Suite
Images []*imageProto.Image
PetId uuid.UUID
Image *imageProto.Image
Images []*imageProto.Image
PetId uuid.UUID
UploadProtoReq *imageProto.UploadImageRequest
UploadDtoReq *dto.UploadImageRequest

NotFoundErr *dto.ResponseErr
UnavailableServiceErr *dto.ResponseErr
Expand All @@ -33,6 +36,12 @@ func TestImageService(t *testing.T) {

func (t *ImageServiceTest) SetupTest() {
t.PetId = uuid.New()
t.Image = &imageProto.Image{
Id: faker.UUIDDigit(),
PetId: t.PetId.String(),
ImageUrl: faker.URL(),
ObjectKey: faker.Word(),
}
t.Images = []*imageProto.Image{
{
Id: faker.UUIDDigit(),
Expand All @@ -57,6 +66,17 @@ func (t *ImageServiceTest) SetupTest() {
},
}

t.UploadProtoReq = &imageProto.UploadImageRequest{
Filename: faker.Name(),
Data: []byte{1, 2, 3, 4, 5},
PetId: t.PetId.String(),
}
t.UploadDtoReq = &dto.UploadImageRequest{
Filename: t.UploadProtoReq.Filename,
File: t.UploadProtoReq.Data,
PetId: t.UploadProtoReq.PetId,
}

t.NotFoundErr = &dto.ResponseErr{
StatusCode: http.StatusNotFound,
Message: constant.PetNotFoundMessage,
Expand Down Expand Up @@ -150,3 +170,21 @@ func (t *ImageServiceTest) TestFindByPetIdInternalError() {
assert.Nil(t.T(), actual)
assert.Equal(t.T(), expected, err)
}

func (t *ImageServiceTest) TestUploadSuccess() {
protoReq := t.UploadProtoReq
protoResp := &imageProto.UploadImageResponse{
Image: t.Image,
}

expected := utils.ProtoToDto(t.Image)

client := imageMock.ImageClientMock{}
client.On("Upload", protoReq).Return(protoResp, nil)

svc := NewService(&client)
actual, err := svc.Upload(t.UploadDtoReq)

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

0 comments on commit 8146ed8

Please sign in to comment.