Skip to content

Commit

Permalink
feat: pet svc delete use image's deletebypetid
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Feb 17, 2024
1 parent a3a3933 commit 932ff3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/app/service/pet/pet.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ func (s *Service) Delete(id string) (result *dto.DeleteResponse, err *dto.Respon
}
}
}

_, errSvc := s.imageService.DeleteByPetId(id)
if errSvc != nil {
return nil, errSvc
}

return &dto.DeleteResponse{
Success: res.Success,
}, nil
Expand Down
13 changes: 10 additions & 3 deletions src/app/service/pet/pet.service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,26 @@ func (t *PetServiceTest) TestUpdateUnavailableServiceError() {
}

func (t *PetServiceTest) TestDeleteSuccess() {
protoReq := &petproto.DeletePetRequest{
petProtoReq := &petproto.DeletePetRequest{
Id: t.Pet.Id,
}
protoResp := &petproto.DeletePetResponse{
petProtoResp := &petproto.DeletePetResponse{
Success: true,
}
imageProtoReq := &imgproto.DeleteByPetIdRequest{
PetId: t.Pet.Id,
}
imageProtoResp := &imgproto.DeleteByPetIdResponse{
Success: true,
}

expected := &dto.DeleteResponse{Success: true}

client := &petmock.PetClientMock{}
client.On("Delete", protoReq).Return(protoResp, nil)
client.On("Delete", petProtoReq).Return(petProtoResp, nil)

imageClient := imagemock.ImageClientMock{}
imageClient.On("DeleteByPetId", imageProtoReq).Return(imageProtoResp, nil)

imageSvc := imageSvc.NewService(&imageClient)
svc := NewService(client, imageSvc)
Expand Down

0 comments on commit 932ff3b

Please sign in to comment.