cards_test.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package dao
  2. import (
  3. "testing"
  4. "go-common/app/interface/openplatform/article/model"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func Test_MallCard(t *testing.T) {
  8. Convey("normal should get data", t, func() {
  9. data := `{"code":0,"message":"success","data":{"pageNum":1,"pageSize":2,"size":2,"startRow":1,"endRow":2,"total":2,"pages":1,"list":[{"itemsId":1,"brief":"韩版帅气","isLastestVersion":1,"name":"短袖T恤男学生新款韩版衬衫12","img":["//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg","//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg","//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg","//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg"],"onSaleTime":null,"offSaleTime":null,"price":0,"maxPrice":0,"sales":0,"frozenStock":null,"stock":null,"needUserinfoCollection":[1,2,3],"presaleStartOrderTime":0,"presaleEndOrderTime":0,"depositPrice":0,"deliveryTemplateId":0,"tianmaImg":"","version":3},{"itemsId":5,"brief":"韩版帅气","isLastestVersion":1,"name":"短袖T恤男学生新款韩版衬衫","img":["//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg","//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg","//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg","//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg"],"onSaleTime":null,"offSaleTime":null,"price":0,"maxPrice":0,"sales":0,"frozenStock":null,"stock":null,"needUserinfoCollection":[1,2,3],"presaleStartOrderTime":0,"presaleEndOrderTime":0,"depositPrice":0,"deliveryTemplateId":13566,"tianmaImg":"","version":2}],"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1,"firstPage":1,"lastPage":1}}`
  10. httpMock("POST", d.c.Cards.MallURL).Reply(200).JSON(data)
  11. res, err := d.MallCard(ctx(), []int64{1, 5})
  12. So(err, ShouldBeNil)
  13. So(res, ShouldResemble, map[int64]*model.MallCard{
  14. 1: &model.MallCard{
  15. ID: 1,
  16. Name: "短袖T恤男学生新款韩版衬衫12",
  17. Brief: "韩版帅气",
  18. Images: []string{
  19. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  20. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  21. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  22. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  23. },
  24. Price: 0,
  25. },
  26. 5: &model.MallCard{
  27. ID: 5,
  28. Name: "短袖T恤男学生新款韩版衬衫",
  29. Brief: "韩版帅气",
  30. Images: []string{
  31. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  32. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  33. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  34. "//img10.360buyimg.com/n0/jfs/t5392/234/1745592889/186437/4e9da0f7/5913b8dfNcc393bff.jpg",
  35. },
  36. Price: 0,
  37. },
  38. })
  39. })
  40. Convey("code !=0 should get error", t, func() {
  41. data := `{"code":-3,"message":"faild","data":{}}`
  42. httpMock("POST", d.c.Cards.MallURL).Reply(200).JSON(data)
  43. _, err := d.MallCard(ctx(), []int64{1, 5})
  44. So(err, ShouldNotBeNil)
  45. })
  46. }
  47. func Test_TicketCard(t *testing.T) {
  48. Convey("normal get data", t, func() {
  49. data := `{"errno":0,"msg":"","data":{"75":{"id":75,"name":"赵丽颖见面会","status":1,"start_time":1500268460,"end_time":1538284460,"performance_image":"//uat-i1.hdslb.com/bfs/openplatform/201707/imrGbwzlkCYUs.jpeg","is_sale":1,"promo_tags":"1-2","stime":"7/17","etime":"9/30","province_name":"上海市","city_name":"上海市","district_name":"浦东新区","venue_name":"梅赛德斯奔驰文化中心","url":"https://show.bilibili.com/m/platform/detail.html?id=75&from=","price_low":0.01,"price_high":500},"80":{"id":80,"name":"演唱会测试C","status":0,"start_time":1501050922,"end_time":1501137326,"performance_image":"//uat-i0.hdslb.com/bfs/openplatform/201707/imXtcy7Kgllz2.jpeg","is_sale":1,"promo_tags":"1-1","stime":"7/26","etime":"7/27","province_name":"上海市","city_name":"上海市","district_name":"浦东新区","venue_name":"文化中心","url":"https://show.bilibili.com/m/platform/detail.html?id=80&from=","price_low":200,"price_high":500}}}`
  50. httpMock("get", d.c.Cards.TicketURL).Reply(200).JSON(data)
  51. res, err := d.TicketCard(ctx(), []int64{75, 80})
  52. So(err, ShouldBeNil)
  53. So(res, ShouldResemble, map[int64]*model.TicketCard{
  54. 75: &model.TicketCard{
  55. ID: 75,
  56. Name: "赵丽颖见面会",
  57. Image: "//uat-i1.hdslb.com/bfs/openplatform/201707/imrGbwzlkCYUs.jpeg",
  58. StartTime: 1500268460,
  59. EndTime: 1538284460,
  60. Province: "上海市",
  61. City: "上海市",
  62. District: "浦东新区",
  63. Venue: "梅赛德斯奔驰文化中心",
  64. PriceLow: 0.01,
  65. URL: "https://show.bilibili.com/m/platform/detail.html?id=75&from=",
  66. },
  67. 80: &model.TicketCard{
  68. ID: 80,
  69. Name: "演唱会测试C",
  70. Image: "//uat-i0.hdslb.com/bfs/openplatform/201707/imXtcy7Kgllz2.jpeg",
  71. StartTime: 1501050922,
  72. EndTime: 1501137326,
  73. Province: "上海市",
  74. City: "上海市",
  75. District: "浦东新区",
  76. Venue: "文化中心",
  77. PriceLow: 200,
  78. URL: "https://show.bilibili.com/m/platform/detail.html?id=80&from=",
  79. },
  80. })
  81. })
  82. Convey("code != 0 should return error", t, func() {
  83. data := `{"errno":-1,"msg":"","data":{}}`
  84. httpMock("get", d.c.Cards.TicketURL).Reply(200).JSON(data)
  85. res, err := d.TicketCard(ctx(), []int64{75, 80})
  86. So(err, ShouldNotBeNil)
  87. So(res, ShouldBeNil)
  88. })
  89. }
  90. func Test_AudioCard(t *testing.T) {
  91. Convey("normal get data", t, func() {
  92. data := `{"code":0,"msg":"success","data":{"75":{"song_id":75,"title":"【Hanser】星电感应","up_mid":26609612,"up_name":"siroccox","play_num":17,"reply_num":0,"cover_url":"http://i0.hdslb.com/bfs/test/80740468b108a4f1b98316caa02dc8dcf5976caf.jpg"}}}`
  93. httpMock("get", d.c.Cards.AudioURL).Reply(200).JSON(data)
  94. res, err := d.AudioCard(ctx(), []int64{75})
  95. So(err, ShouldBeNil)
  96. So(res, ShouldResemble, map[int64]*model.AudioCard{
  97. 75: &model.AudioCard{
  98. ID: 75,
  99. Title: "【Hanser】星电感应",
  100. UpMid: 26609612,
  101. UpName: "siroccox",
  102. Play: 17,
  103. Reply: 0,
  104. CoverURL: "http://i0.hdslb.com/bfs/test/80740468b108a4f1b98316caa02dc8dcf5976caf.jpg",
  105. },
  106. })
  107. })
  108. Convey("code != 0 should return error", t, func() {
  109. data := `{"code":-1,"msg":"fail","data":{}}}`
  110. httpMock("get", d.c.Cards.AudioURL).Reply(200).JSON(data)
  111. _, err := d.AudioCard(ctx(), []int64{75})
  112. So(err, ShouldNotBeNil)
  113. })
  114. }
  115. func Test_BangumiCard(t *testing.T) {
  116. exp := map[int64]*model.BangumiCard{
  117. 20031: &model.BangumiCard{
  118. ID: 20031,
  119. Image: "http://i0.hdslb.com/bfs/bangumi/77605418c0921578c469201d6384d6a32ed218e9.jpg",
  120. Title: "地狱少女 宵伽",
  121. Rating: struct {
  122. Score float64 `json:"score"`
  123. Count int64 `json:"count"`
  124. }{
  125. Score: 0,
  126. Count: 0,
  127. },
  128. Playable: true,
  129. FollowCount: 0,
  130. PlayCount: 0,
  131. },
  132. }
  133. Convey("seasons", t, func() {
  134. Convey("normal get data", func() {
  135. data := `{"code":0,"message":"success","result":{"season_map":{"20031":{"allow_review":1,"cover":"http://i0.hdslb.com/bfs/bangumi/77605418c0921578c469201d6384d6a32ed218e9.jpg","is_finish":1,"is_started":1,"media_id":11,"playable":true,"season_id":20031,"season_type":1,"season_type_name":"番剧","title":"地狱少女 宵伽","total_count":13}}}}`
  136. httpMock("post", d.c.Cards.BangumiURL).Reply(200).JSON(data)
  137. res, err := d.BangumiCard(ctx(), []int64{20031}, nil)
  138. So(err, ShouldBeNil)
  139. So(res, ShouldResemble, exp)
  140. })
  141. Convey("code != 0 should return error", func() {
  142. data := `{"code":-1,"message":"fail","result":{}}`
  143. httpMock("post", d.c.Cards.BangumiURL).Reply(200).JSON(data)
  144. _, err := d.BangumiCard(ctx(), []int64{20031}, nil)
  145. So(err, ShouldNotBeNil)
  146. })
  147. })
  148. Convey("eps", t, func() {
  149. Convey("normal get data", func() {
  150. data := `{"code":0,"message":"success","result":{"episode_map":{"20031":{"allow_review":1,"cover":"http://i0.hdslb.com/bfs/bangumi/77605418c0921578c469201d6384d6a32ed218e9.jpg","is_finish":1,"is_started":1,"media_id":11,"playable":true,"season_id":20031,"season_type":1,"season_type_name":"番剧","title":"地狱少女 宵伽","total_count":13}}}}`
  151. httpMock("post", d.c.Cards.BangumiURL).Reply(200).JSON(data)
  152. res, err := d.BangumiCard(ctx(), nil, []int64{20031})
  153. So(err, ShouldBeNil)
  154. So(res, ShouldResemble, exp)
  155. })
  156. Convey("code != 0 should return error", func() {
  157. data := `{"code":-1,"message":"fail","result":{}}`
  158. httpMock("post", d.c.Cards.BangumiURL).Reply(200).JSON(data)
  159. _, err := d.BangumiCard(ctx(), nil, []int64{20031})
  160. So(err, ShouldNotBeNil)
  161. })
  162. })
  163. }