bangumi_test.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoBangumiContent(t *testing.T) {
  9. httpMock("GET", "http://uat-bangumi.bilibili.co/ext/internal/archive/channel/content").Reply(http.StatusOK).JSON(`
  10. {
  11. "code": 0,
  12. "message": "success",
  13. "result": [
  14. {
  15. "akira": "11的期望",
  16. "alias": "qwdkhj qwknd,qwjdbhqwdjkbqw,qkjcxsa,jcb,sacb,askjcbscajbsakhc",
  17. "copyright": "bilibili",
  18. "cover_image": "http://i0.hdslb.com/bfs/bangumi/4f84b91e5b90e99d8b96a336385af7d84c308b48.jpg",
  19. "display_address": "https://www.bilibili.com/bangumi/play/ss20017?bsource=baidu_os",
  20. "download_address": "http://app.bilibili.com?bsource=baidu_os",
  21. "duration": 21,
  22. "episodes": [
  23. {
  24. "cover": "http://i0.hdslb.com/bfs/archive/496ea8899680d4a80d163d2edb401b23.jpg",
  25. "duration": 0,
  26. "id": 116664,
  27. "index": 1,
  28. "play_url": "https://www.bilibili.com/bangumi/play/ep116664?bsource=baidu_os",
  29. "pub_real_time": "2018-08-07 00:00:00",
  30. "title": "第二集"
  31. },
  32. {
  33. "cover": "http://i0.hdslb.com/bfs/archive/496ea8899680d4a80d163d2edb401b23.jpg",
  34. "duration": 0,
  35. "id": 116865,
  36. "index": 2,
  37. "play_url": "https://www.bilibili.com/bangumi/play/ep116865?bsource=baidu_os",
  38. "pub_real_time": "2018-09-10 04:00:00",
  39. "title": "9.10zuixin"
  40. },
  41. {
  42. "cover": "http://i0.hdslb.com/bfs/archive/1fda382339317a7f6c918827b261965c24cac831.jpg",
  43. "duration": 0,
  44. "id": 117307,
  45. "index": 3,
  46. "play_url": "https://www.bilibili.com/bangumi/play/ep117307?bsource=baidu_os",
  47. "pub_real_time": "2018-11-07 11:23:00",
  48. "title": "不可播,就不玩了,找邱穗姬"
  49. }
  50. ],
  51. "intro": "kate_sponsor_谁都不能动dqw qwd ",
  52. "is_finish": 0,
  53. "media_id": 2130686907,
  54. "name": "免费时承包,转付费后随便看的番",
  55. "play_count": 0,
  56. "premieredate": "2018",
  57. "pub_real_time": 1541560980,
  58. "pub_time": "2018-04-02 00:00:00",
  59. "season": {
  60. "id": 20017,
  61. "index": 1,
  62. "pay_price": 0.0,
  63. "paymentstatus": 1,
  64. "title": "第一季",
  65. "total_count": 6
  66. },
  67. "seasonId": 20017,
  68. "season_series": [
  69. {
  70. "id": 20017,
  71. "index": 1,
  72. "title": "免费时承包,转付费后随便看的番"
  73. },
  74. {
  75. "id": 33409,
  76. "index": 2,
  77. "title": "介绍姜姜的小店的故事"
  78. }
  79. ],
  80. "staff": {},
  81. "tag": [],
  82. "type": 1
  83. }
  84. ],
  85. "total": 13
  86. }
  87. `)
  88. convey.Convey("BangumiContent", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. pn = int(1)
  92. ps = int(10)
  93. typ = int8(1)
  94. appkey = "douban"
  95. )
  96. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  97. resp, err := d.BangumiContent(c, pn, ps, typ, appkey)
  98. ctx.Convey("Then err should be nil.resp should not be nil.", func(ctx convey.C) {
  99. ctx.So(err, convey.ShouldBeNil)
  100. ctx.So(resp, convey.ShouldNotBeEmpty)
  101. })
  102. })
  103. })
  104. }
  105. func TestDaoBangumiOff(t *testing.T) {
  106. resp := `
  107. {
  108. "code": 0,
  109. "message": "success",
  110. "ttl": 1,
  111. "data": [
  112. {
  113. "name": "中二病也要谈恋爱!恋",
  114. "seasonid": 4349,
  115. "type": 1
  116. },
  117. {
  118. "name": "天空與海洋之間(僅限港澳台地區)",
  119. "seasonid": 25687,
  120. "type": 1
  121. },
  122. {
  123. "name": "只要別西卜大小姐喜歡就好(僅限港澳台地區)",
  124. "seasonid": 25836,
  125. "type": 1
  126. },
  127. {
  128. "name": "嫁给非人类",
  129. "seasonid": 25711,
  130. "type": 1
  131. },
  132. {
  133. "name": "Tokyo Guru: re (Part 2)(僅限港澳台地區)",
  134. "seasonid": 25727,
  135. "type": 1
  136. },
  137. {
  138. "name": "產子救世錄(僅限港澳台地區)",
  139. "seasonid": 25959,
  140. "type": 1
  141. },
  142. {
  143. "name": "精灵宝可梦 日月",
  144. "seasonid": 5707,
  145. "type": 1
  146. },
  147. {
  148. "name": "剧场版「吸血鬼仆人 - Alice in the Garden -」",
  149. "seasonid": 25951,
  150. "type": 1
  151. },
  152. {
  153. "name": "",
  154. "seasonid": 25958,
  155. "type": 1
  156. },
  157. {
  158. "name": "新战神金刚:传奇的保护神 第七季",
  159. "seasonid": 25411,
  160. "type": 1
  161. },
  162. {
  163. "name": "告诉我魔法钟摆~莉露莉露妖精莉露~",
  164. "seasonid": 24579,
  165. "type": 1
  166. },
  167. {
  168. "name": "草莓棉花糖 OVA 第1期",
  169. "seasonid": 4828,
  170. "type": 1
  171. },
  172. {
  173. "name": "NEKOPARA EXTRA 小猫篇(猫娘乐园)",
  174. "seasonid": 25152,
  175. "type": 1
  176. },
  177. {
  178. "name": "新战神金刚:传奇的保护神 第六季",
  179. "seasonid": 25013,
  180. "type": 1
  181. },
  182. {
  183. "name": "闪电十一人 第一季 日语",
  184. "seasonid": 24833,
  185. "type": 1
  186. },
  187. {
  188. "name": "致命紫罗兰编号044",
  189. "seasonid": 24779,
  190. "type": 1
  191. },
  192. {
  193. "name": "灰与幻想的格林姆迦尔 OVA",
  194. "seasonid": 24745,
  195. "type": 1
  196. },
  197. {
  198. "name": "tsetfj",
  199. "seasonid": 24660,
  200. "type": 1
  201. },
  202. {
  203. "name": "未来卡 神搭档对战",
  204. "seasonid": 24416,
  205. "type": 1
  206. },
  207. {
  208. "name": "明日之丈",
  209. "seasonid": 24332,
  210. "type": 1
  211. }
  212. ]
  213. }
  214. `
  215. httpMock("GET", "http://uat-bangumi.bilibili.co/ext/internal/archive/channel/content/offshelve").Reply(http.StatusOK).JSON(resp)
  216. convey.Convey("BangumiOff", t, func(ctx convey.C) {
  217. var (
  218. c = context.Background()
  219. pn = int(1)
  220. ps = int(10)
  221. typ = int8(1)
  222. appkey = ""
  223. ts = int64(0)
  224. )
  225. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  226. resp, err := d.BangumiOff(c, pn, ps, typ, appkey, ts)
  227. ctx.Convey("Then err should be nil.resp should not be nil.", func(ctx convey.C) {
  228. ctx.So(err, convey.ShouldBeNil)
  229. ctx.So(resp, convey.ShouldNotBeEmpty)
  230. })
  231. })
  232. })
  233. }