statistics_test.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. package up
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/mcn/model"
  6. xtime "go-common/library/time"
  7. "github.com/smartystreets/goconvey/convey"
  8. "gopkg.in/h2non/gock.v1"
  9. )
  10. func TestUpMcnDataOverview(t *testing.T) {
  11. convey.Convey("McnDataOverview", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. date = xtime.Time(1542124800)
  15. )
  16. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  17. m, err := d.McnDataOverview(c, date)
  18. ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(m, convey.ShouldBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestUpMcnRankFansOverview(t *testing.T) {
  26. convey.Convey("McnRankFansOverview", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. dataType = model.DataType(2)
  30. date = xtime.Time(1542124800)
  31. topLen = int(5)
  32. )
  33. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  34. mrf, mids, err := d.McnRankFansOverview(c, dataType, date, topLen)
  35. ctx.Convey("Then err should be nil.mrf,mids should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(mids, convey.ShouldBeNil)
  38. ctx.So(mrf, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestUpMcnRankArchiveLikesOverview(t *testing.T) {
  44. convey.Convey("McnRankArchiveLikesOverview", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. dataType = model.DataType(2)
  48. date = xtime.Time(1542124800)
  49. topLen = int(5)
  50. )
  51. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  52. ras, mids, avids, tids, err := d.McnRankArchiveLikesOverview(c, dataType, date, topLen)
  53. ctx.Convey("Then err should be nil.ras,mids,avids,tids should not be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. ctx.So(tids, convey.ShouldBeNil)
  56. ctx.So(avids, convey.ShouldBeNil)
  57. ctx.So(mids, convey.ShouldBeNil)
  58. ctx.So(ras, convey.ShouldBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestUpMcnDataTypeSummary(t *testing.T) {
  64. convey.Convey("McnDataTypeSummary", t, func(ctx convey.C) {
  65. var (
  66. c = context.Background()
  67. date = xtime.Time(1542124800)
  68. )
  69. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  70. mmd, tids, err := d.McnDataTypeSummary(c, date)
  71. ctx.Convey("Then err should be nil.mmd,tids should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(tids, convey.ShouldBeNil)
  74. ctx.So(mmd, convey.ShouldNotBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestUpArcTopDataStatistics(t *testing.T) {
  80. convey.Convey("ArcTopDataStatistics", t, func(ctx convey.C) {
  81. var (
  82. c = context.Background()
  83. arg = &model.McnGetRankReq{}
  84. )
  85. arg.SignID = 214
  86. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  87. defer gock.OffAll()
  88. result := `
  89. {
  90. "message":"0",
  91. "code":0,
  92. "data":{
  93. "type_list":[
  94. {
  95. "tid":1,
  96. "name":"视频"
  97. }
  98. ],
  99. "result":[
  100. {
  101. "data_type":1,
  102. "likes_increase":13,
  103. "likes_accumulate":13,
  104. "play_increase":7,
  105. "archive_id":10110514,
  106. "archive_title":"不同清晰度",
  107. "pic":"http://i1.hdslb.com/bfs/archive/3348cb2cb34423f936916444a0a77e59f9daf1d",
  108. "tid_name":"日常",
  109. "tid":21,
  110. "ctime":1535362150,
  111. "author":{
  112. "face":"http://static.hdslb.com/images/member/noface.gif",
  113. "mid":27515266,
  114. "name":"Testeew还觉得是发货"
  115. },
  116. "stat":{
  117. "view":0
  118. }
  119. }
  120. ]
  121. },
  122. "ttl":1
  123. }`
  124. httpMock("GET", d.arcTopURL).Reply(200).JSON(result)
  125. reply, err := d.ArcTopDataStatistics(c, arg)
  126. ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
  127. ctx.So(err, convey.ShouldBeNil)
  128. ctx.So(reply, convey.ShouldNotBeNil)
  129. })
  130. })
  131. })
  132. }
  133. func TestUpDataFans(t *testing.T) {
  134. convey.Convey("DataFans", t, func(ctx convey.C) {
  135. var (
  136. c = context.Background()
  137. arg = &model.McnCommonReq{SignID: 1}
  138. )
  139. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  140. defer gock.OffAll()
  141. result := `{
  142. "message":"",
  143. "code":0,
  144. "data":{
  145. "fans_all":0,
  146. "fans_inc":0,
  147. "act_fans":0,
  148. "fans_dec_all":0,
  149. "fans_dec":0,
  150. "view_fans_rate":0,
  151. "act_fans_rate":0,
  152. "reply_fans_rate":0,
  153. "danmu_fans_rate":0,
  154. "coin_fans_rate":0,
  155. "like_fans_rate":0,
  156. "fav_fans_rate":0,
  157. "share_fans_rate":0,
  158. "live_gift_fans_rate":0,
  159. "live_danmu_fans_rate":0
  160. }
  161. }`
  162. httpMock("GET", d.dataFansURL).Reply(200).JSON(result)
  163. reply, err := d.DataFans(c, arg)
  164. ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
  165. ctx.So(err, convey.ShouldBeNil)
  166. ctx.So(reply, convey.ShouldNotBeNil)
  167. })
  168. })
  169. })
  170. }
  171. func TestUpDataFansBaseAttr(t *testing.T) {
  172. convey.Convey("DataFansBaseAttr", t, func(ctx convey.C) {
  173. var (
  174. c = context.Background()
  175. arg = &model.McnCommonReq{SignID: 1}
  176. )
  177. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  178. defer gock.OffAll()
  179. result := `{
  180. "message":"",
  181. "code":0,
  182. "data":{
  183. "fans_sex":{
  184. "male":0,
  185. "female":0
  186. },
  187. "fans_age":{
  188. "a":0,
  189. "b":0,
  190. "c":0,
  191. "d":0
  192. },
  193. "fans_play_way":{
  194. "app":0,
  195. "pc":0,
  196. "outside":0,
  197. "other":0
  198. }
  199. }
  200. }`
  201. httpMock("GET", d.dataFansBaseAttrURL).Reply(200).JSON(result)
  202. sex, age, playWay, err := d.DataFansBaseAttr(c, arg)
  203. ctx.Convey("Then err should be nil.sex,age,playWay should not be nil.", func(ctx convey.C) {
  204. ctx.So(err, convey.ShouldBeNil)
  205. ctx.So(playWay, convey.ShouldNotBeNil)
  206. ctx.So(age, convey.ShouldNotBeNil)
  207. ctx.So(sex, convey.ShouldNotBeNil)
  208. })
  209. })
  210. })
  211. }
  212. func TestUpDataFansArea(t *testing.T) {
  213. convey.Convey("DataFansArea", t, func(ctx convey.C) {
  214. var (
  215. c = context.Background()
  216. arg = &model.McnCommonReq{SignID: 1}
  217. )
  218. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  219. defer gock.OffAll()
  220. result := `{
  221. "message":"",
  222. "code":0,
  223. "data":{
  224. "result":[
  225. {
  226. "province":"",
  227. "user":0
  228. }
  229. ]
  230. }
  231. }`
  232. httpMock("GET", d.dataFansAreaURL).Reply(200).JSON(result)
  233. reply, err := d.DataFansArea(c, arg)
  234. ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
  235. ctx.So(err, convey.ShouldBeNil)
  236. ctx.So(reply, convey.ShouldNotBeNil)
  237. })
  238. })
  239. })
  240. }
  241. func TestUpDataFansType(t *testing.T) {
  242. convey.Convey("DataFansType", t, func(ctx convey.C) {
  243. var (
  244. c = context.Background()
  245. arg = &model.McnCommonReq{SignID: 1}
  246. )
  247. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  248. defer gock.OffAll()
  249. result := `{
  250. "message":"",
  251. "code":0,
  252. "data":{
  253. "result":[
  254. {
  255. "type_id":0,
  256. "user":0,
  257. "type_name":""
  258. }
  259. ]
  260. }
  261. }`
  262. httpMock("GET", d.dataFansTypeURL).Reply(200).JSON(result)
  263. reply, err := d.DataFansType(c, arg)
  264. ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
  265. ctx.So(err, convey.ShouldBeNil)
  266. ctx.So(reply, convey.ShouldNotBeNil)
  267. })
  268. })
  269. })
  270. }
  271. func TestUpDataFansTag(t *testing.T) {
  272. convey.Convey("DataFansTag", t, func(ctx convey.C) {
  273. var (
  274. c = context.Background()
  275. arg = &model.McnCommonReq{SignID: 1}
  276. )
  277. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  278. defer gock.OffAll()
  279. result := `{
  280. "message":"",
  281. "code":0,
  282. "data":{
  283. "result":[
  284. {
  285. "tag_id":0,
  286. "user":0,
  287. "tag_name":""
  288. }
  289. ]
  290. }
  291. }`
  292. httpMock("GET", d.dataFansTagURL).Reply(200).JSON(result)
  293. reply, err := d.DataFansTag(c, arg)
  294. ctx.Convey("Then err should be nil.reply should not be nil.", func(ctx convey.C) {
  295. ctx.So(err, convey.ShouldBeNil)
  296. ctx.So(reply, convey.ShouldNotBeNil)
  297. })
  298. })
  299. })
  300. }