like_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package like
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/job/main/activity/model/like"
  6. "github.com/smartystreets/goconvey/convey"
  7. "gopkg.in/h2non/gock.v1"
  8. )
  9. func TestLikeLike(t *testing.T) {
  10. convey.Convey("Like", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. sid = int64(10297)
  14. )
  15. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  16. ns, err := d.Like(c, sid)
  17. ctx.Convey("Then err should be nil.ns should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(ns, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestLikeLikeList(t *testing.T) {
  25. convey.Convey("LikeList", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. sid = int64(10297)
  29. offset = int(1)
  30. limit = int(10)
  31. )
  32. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  33. list, err := d.LikeList(c, sid, offset, limit)
  34. ctx.Convey("Then err should be nil.list should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. ctx.So(list, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestLikeLikeCnt(t *testing.T) {
  42. convey.Convey("LikeCnt", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. sid = int64(10297)
  46. )
  47. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  48. count, err := d.LikeCnt(c, sid)
  49. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. ctx.So(count, convey.ShouldNotBeNil)
  52. })
  53. })
  54. })
  55. }
  56. func TestLikeSetObjectStat(t *testing.T) {
  57. convey.Convey("SetObjectStat", t, func(ctx convey.C) {
  58. var (
  59. c = context.Background()
  60. sid = int64(10297)
  61. stat = &like.SubjectTotalStat{}
  62. count = int(10)
  63. )
  64. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  65. defer gock.OffAll()
  66. httpMock("GET", d.setObjStatURL).Reply(200).JSON(`{"code":0}`)
  67. err := d.SetObjectStat(c, sid, stat, count)
  68. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldBeNil)
  70. })
  71. })
  72. })
  73. }
  74. func TestLikeSetViewRank(t *testing.T) {
  75. convey.Convey("SetViewRank", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. sid = int64(10297)
  79. aids = []int64{1, 2}
  80. )
  81. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  82. defer gock.OffAll()
  83. httpMock("GET", d.setViewRankURL).Reply(200).JSON(`{"code":0}`)
  84. err := d.SetViewRank(c, sid, aids)
  85. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. })
  88. })
  89. })
  90. }
  91. func TestLikeSetLikeContent(t *testing.T) {
  92. convey.Convey("SetLikeContent", t, func(ctx convey.C) {
  93. var (
  94. c = context.Background()
  95. id = int64(1)
  96. )
  97. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  98. defer gock.OffAll()
  99. httpMock("GET", d.setLikeContentURL).Reply(200).JSON(`{"code":0}`)
  100. err := d.SetLikeContent(c, id)
  101. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  102. ctx.So(err, convey.ShouldBeNil)
  103. })
  104. })
  105. })
  106. }