weeklyhonor_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. wkhmdl "go-common/app/interface/main/creative/model/weeklyhonor"
  6. upgrpc "go-common/app/service/main/up/api/v1"
  7. xtime "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. mtime = xtime.Time(wkhmdl.LatestSunday().Unix())
  12. c = context.Background()
  13. rawUpActives = []*upgrpc.UpActivity{
  14. {Mid: 1, Activity: 4}, {Mid: 2, Activity: 4}, {Mid: 3, Activity: 4}, {Mid: 4, Activity: 3}, {Mid: 5, Activity: 4}, {Mid: 6, Activity: 1}, {Mid: 7, Activity: 1}, {Mid: 24, Activity: 2},
  15. }
  16. mockHls = []*wkhmdl.HonorLog{
  17. // lev:SSR clicked
  18. {
  19. ID: 1,
  20. MID: 1,
  21. HID: 1,
  22. MTime: mtime,
  23. },
  24. // lev:SR & BlackList clicked
  25. {
  26. ID: 2,
  27. MID: 2,
  28. HID: 9,
  29. MTime: mtime,
  30. },
  31. // lev:R clicked
  32. {
  33. ID: 3,
  34. MID: 3,
  35. HID: 17,
  36. MTime: mtime,
  37. },
  38. // lev:A
  39. {
  40. ID: 4,
  41. MID: 4,
  42. HID: 26,
  43. MTime: mtime,
  44. },
  45. // lev:B clicked
  46. {
  47. ID: 5,
  48. MID: 5,
  49. HID: 35,
  50. MTime: mtime,
  51. },
  52. // lev:C clicked
  53. {
  54. ID: 6,
  55. MID: 6,
  56. HID: 46,
  57. MTime: mtime,
  58. },
  59. // lev:D
  60. {
  61. ID: 7,
  62. MID: 7,
  63. HID: 56,
  64. MTime: mtime,
  65. },
  66. // BlackList clicked
  67. {
  68. ID: 8,
  69. MID: 24,
  70. HID: 50,
  71. },
  72. }
  73. clickMap = map[int64]int32{
  74. 1: 1,
  75. 2: 1,
  76. 3: 1,
  77. 5: 1,
  78. 6: 1,
  79. 24: 1,
  80. }
  81. )
  82. func TestServiceSendMsg(t *testing.T) {
  83. convey.Convey("SendMsg", t, func(ctx convey.C) {
  84. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  85. // mock
  86. s.honDao.MockUpActivesList(rawUpActives, 0, nil)
  87. s.honDao.MockUpCount(1, nil)
  88. s.honDao.MockLatestHonorLogs(mockHls, nil)
  89. s.honDao.MockClickCounts(clickMap, nil)
  90. s.honDao.MockSendNotify(nil)
  91. // test
  92. s.SendMsg()
  93. ctx.Convey("No return values", func(ctx convey.C) {
  94. })
  95. })
  96. })
  97. }
  98. func TestServiceFlushHonor(t *testing.T) {
  99. convey.Convey("FlushHonor", t, func(ctx convey.C) {
  100. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  101. // mock
  102. s.honDao.MockUpActivesList(rawUpActives, 0, nil)
  103. mockStat := wkhmdl.HonorStat{
  104. Play: 100,
  105. PlayLastW: 100,
  106. }
  107. s.honDao.MockHonorStat(&mockStat, nil)
  108. // test
  109. s.FlushHonor()
  110. ctx.Convey("No return values", func(ctx convey.C) {
  111. })
  112. })
  113. })
  114. }
  115. func TestServiceupsertHonor(t *testing.T) {
  116. convey.Convey("upsertHonor", t, func(ctx convey.C) {
  117. var (
  118. c = context.Background()
  119. mids = []int64{}
  120. )
  121. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  122. err := s.upsertHonor(c, mids)
  123. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  124. ctx.So(err, convey.ShouldBeNil)
  125. })
  126. })
  127. })
  128. }
  129. func TestServiceTestSendMsg(t *testing.T) {
  130. convey.Convey("TestSendMsg", t, func(ctx convey.C) {
  131. var (
  132. c = context.Background()
  133. mids = []int64{}
  134. )
  135. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  136. err := s.TestSendMsg(c, mids)
  137. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  138. ctx.So(err, convey.ShouldBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestServicefilterMids(t *testing.T) {
  144. convey.Convey("filterUnActiveMids", t, func(ctx convey.C) {
  145. var (
  146. filteredMids = []int64{1, 2, 3, 4, 6}
  147. )
  148. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  149. s.honDao.MockUpCount(1, nil)
  150. s.honDao.MockLatestHonorLogs(mockHls, nil)
  151. s.honDao.MockClickCounts(clickMap, nil)
  152. mids, err := s.filterMids(c, rawUpActives)
  153. ctx.Convey("Then err should be nil.mids should not be nil.", func(ctx convey.C) {
  154. ctx.So(err, convey.ShouldBeNil)
  155. sunday := wkhmdl.LatestSunday()
  156. if isOddWeek(sunday) {
  157. filteredMids = append(filteredMids, 7)
  158. }
  159. ctx.So(mids, convey.ShouldResemble, filteredMids)
  160. })
  161. })
  162. })
  163. }