like_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. thumbupMdl "go-common/app/service/main/thumbup/model"
  6. thumbup "go-common/app/service/main/thumbup/rpc/client"
  7. "github.com/golang/mock/gomock"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func Test_isLike(t *testing.T) {
  11. var (
  12. mid = int64(1)
  13. aid = int64(2)
  14. state = int8(1)
  15. )
  16. Convey("get data", t, WithMock(t, func(mockCtrl *gomock.Controller) {
  17. mock := thumbup.NewMockThumbupRPC(mockCtrl)
  18. s.thumbupRPC = mock
  19. arg := &thumbupMdl.ArgHasLike{Business: "article", MessageIDs: []int64{aid}, Mid: mid}
  20. mock.EXPECT().HasLike(gomock.Any(), arg).Return(map[int64]int8{aid: state}, nil)
  21. res, err := s.isLike(context.TODO(), mid, aid)
  22. So(err, ShouldBeNil)
  23. So(res, ShouldEqual, state)
  24. }))
  25. }
  26. func Test_HadLikesByMid(t *testing.T) {
  27. var (
  28. mid = int64(1)
  29. aids = []int64{2, 2000}
  30. state = map[int64]int8{2: 1, 2000: 0}
  31. )
  32. Convey("get data", t, WithMock(t, func(mockCtrl *gomock.Controller) {
  33. mock := thumbup.NewMockThumbupRPC(mockCtrl)
  34. s.thumbupRPC = mock
  35. arg := &thumbupMdl.ArgHasLike{Business: "article", MessageIDs: aids, Mid: mid}
  36. mock.EXPECT().HasLike(gomock.Any(), arg).Return(state, nil)
  37. res, err := s.HadLikesByMid(context.TODO(), mid, aids)
  38. So(err, ShouldBeNil)
  39. So(res, ShouldResemble, state)
  40. }))
  41. }