up_test.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. "go-common/app/interface/main/growup/model"
  8. xtime "go-common/library/time"
  9. )
  10. func TestDaoGetAccountState(t *testing.T) {
  11. convey.Convey("GetAccountState", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. table = "up_info_video"
  15. mid = int64(1001)
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. Exec(c, "INSERT INTO up_info_video(mid, account_state, is_deleted) VALUES(1001, 3, 0) ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  19. state, err := d.GetAccountState(c, table, mid)
  20. ctx.Convey("Then err should be nil.state should not be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(state, convey.ShouldNotBeNil)
  23. })
  24. })
  25. })
  26. }
  27. func TestDaoGetUpSignedAt(t *testing.T) {
  28. convey.Convey("GetUpSignedAt", t, func(ctx convey.C) {
  29. var (
  30. c = context.Background()
  31. mid = int64(1001)
  32. )
  33. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  34. Exec(c, "INSERT INTO up_info_video(mid, account_state, is_deleted) VALUES(1001, 3, 0) ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  35. signedAt, err := d.GetUpSignedAt(c, "up_info_video", mid)
  36. ctx.Convey("Then err should be nil.signedAt should not be nil.", func(ctx convey.C) {
  37. ctx.So(err, convey.ShouldBeNil)
  38. ctx.So(signedAt, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoInsertUpInfo(t *testing.T) {
  44. convey.Convey("InsertUpInfo", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. table = "up_info_video"
  48. totalCountField = "total_play_count"
  49. v = &model.UpInfo{
  50. MID: 1002,
  51. AccountState: 3,
  52. }
  53. )
  54. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  55. Exec(c, "DELETE FROM up_info_video WHERE mid = 1002")
  56. rows, err := d.InsertUpInfo(c, table, totalCountField, v)
  57. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. ctx.So(rows, convey.ShouldNotBeNil)
  60. })
  61. })
  62. })
  63. }
  64. func TestDaoTxInsertBgmUpInfo(t *testing.T) {
  65. convey.Convey("TxInsertBgmUpInfo", t, func(ctx convey.C) {
  66. var (
  67. c = context.Background()
  68. tx, _ = d.BeginTran(c)
  69. v = &model.UpInfo{
  70. MID: 1002,
  71. AccountState: 3,
  72. }
  73. )
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. defer tx.Commit()
  76. Exec(c, "DELETE FROM up_info_bgm WHERE mid = 1002")
  77. rows, err := d.TxInsertBgmUpInfo(tx, v)
  78. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. ctx.So(rows, convey.ShouldNotBeNil)
  81. })
  82. })
  83. })
  84. }
  85. func TestDaoTxInsertCreditScore(t *testing.T) {
  86. convey.Convey("TxInsertCreditScore", t, func(ctx convey.C) {
  87. var (
  88. c = context.Background()
  89. tx, _ = d.BeginTran(c)
  90. mid = int64(1001)
  91. )
  92. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  93. defer tx.Commit()
  94. rows, err := d.TxInsertCreditScore(tx, mid)
  95. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. ctx.So(rows, convey.ShouldNotBeNil)
  98. })
  99. })
  100. })
  101. }
  102. func TestDaoBlocked(t *testing.T) {
  103. convey.Convey("Blocked", t, func(ctx convey.C) {
  104. var (
  105. c = context.Background()
  106. mid = int64(1001)
  107. )
  108. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  109. Exec(c, "INSERT INTO up_blocked(mid) VALUES(1001)")
  110. id, err := d.Blocked(c, mid)
  111. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. ctx.So(id, convey.ShouldNotBeNil)
  114. })
  115. })
  116. })
  117. }
  118. func TestDaoWhite(t *testing.T) {
  119. convey.Convey("White", t, func(ctx convey.C) {
  120. var (
  121. c = context.Background()
  122. mid = int64(1001)
  123. )
  124. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  125. Exec(c, "INSERT INTO up_white_list(mid) VALUES(1001)")
  126. m, err := d.White(c, mid)
  127. ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
  128. ctx.So(err, convey.ShouldBeNil)
  129. ctx.So(m, convey.ShouldNotBeNil)
  130. })
  131. })
  132. })
  133. }
  134. func TestDaoAvUpStatus(t *testing.T) {
  135. convey.Convey("AvUpStatus", t, func(ctx convey.C) {
  136. var (
  137. c = context.Background()
  138. mid = int64(1001)
  139. )
  140. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  141. Exec(c, "INSERT INTO up_info_video(mid, account_state, is_deleted) VALUES(1001, 3, 0) ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  142. status, err := d.AvUpStatus(c, mid)
  143. ctx.Convey("Then err should be nil.status should not be nil.", func(ctx convey.C) {
  144. ctx.So(err, convey.ShouldBeNil)
  145. ctx.So(status, convey.ShouldNotBeNil)
  146. })
  147. })
  148. })
  149. }
  150. func TestDaoBgmUpStatus(t *testing.T) {
  151. convey.Convey("BgmUpStatus", t, func(ctx convey.C) {
  152. var (
  153. c = context.Background()
  154. mid = int64(1001)
  155. )
  156. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  157. Exec(c, "INSERT INTO up_info_bgm(mid, account_state, is_deleted) VALUES(1001, 3, 0) ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  158. status, err := d.BgmUpStatus(c, mid)
  159. ctx.Convey("Then err should be nil.status should not be nil.", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. ctx.So(status, convey.ShouldNotBeNil)
  162. })
  163. })
  164. })
  165. }
  166. func TestDaoColumnUpStatus(t *testing.T) {
  167. convey.Convey("ColumnUpStatus", t, func(ctx convey.C) {
  168. var (
  169. c = context.Background()
  170. mid = int64(1001)
  171. )
  172. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  173. Exec(c, "INSERT INTO up_info_column(mid, account_state, is_deleted) VALUES(1001, 3, 0) ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  174. status, err := d.ColumnUpStatus(c, mid)
  175. ctx.Convey("Then err should be nil.status should not be nil.", func(ctx convey.C) {
  176. ctx.So(err, convey.ShouldBeNil)
  177. ctx.So(status, convey.ShouldNotBeNil)
  178. })
  179. })
  180. })
  181. }
  182. func TestDaoCategoryInfo(t *testing.T) {
  183. convey.Convey("CategoryInfo", t, func(ctx convey.C) {
  184. var (
  185. c = context.Background()
  186. mid = int64(0)
  187. )
  188. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  189. nickname, categoryID, err := d.CategoryInfo(c, mid)
  190. ctx.Convey("Then err should be nil.nickname,categoryID should not be nil.", func(ctx convey.C) {
  191. ctx.So(err, convey.ShouldBeNil)
  192. ctx.So(categoryID, convey.ShouldNotBeNil)
  193. ctx.So(nickname, convey.ShouldNotBeNil)
  194. })
  195. })
  196. })
  197. }
  198. func TestDaoFans(t *testing.T) {
  199. convey.Convey("Fans", t, func(ctx convey.C) {
  200. var (
  201. c = context.Background()
  202. mid = int64(1001)
  203. )
  204. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  205. Exec(c, "INSERT INTO up_base_statistics(mid, fans) VALUES(1001, 100)")
  206. fans, err := d.Fans(c, mid)
  207. ctx.Convey("Then err should be nil.fans should not be nil.", func(ctx convey.C) {
  208. ctx.So(err, convey.ShouldBeNil)
  209. ctx.So(fans, convey.ShouldNotBeNil)
  210. })
  211. })
  212. })
  213. }
  214. func TestDaoTxQuit(t *testing.T) {
  215. convey.Convey("TxQuit", t, func(ctx convey.C) {
  216. var (
  217. c = context.Background()
  218. tx, _ = d.BeginTran(c)
  219. table = "up_info_video"
  220. mid = int64(1003)
  221. quitAt = xtime.Time(time.Now().Unix())
  222. expiredIn = xtime.Time(time.Now().Unix())
  223. reason = "test"
  224. )
  225. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  226. defer tx.Commit()
  227. Exec(c, "INSERT INTO up_info_video(mid, account_state, is_deleted) VALUES(1003, 3, 0) ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  228. rows, err := d.TxQuit(tx, table, mid, quitAt, expiredIn, reason)
  229. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  230. ctx.So(err, convey.ShouldBeNil)
  231. ctx.So(rows, convey.ShouldNotBeNil)
  232. })
  233. })
  234. })
  235. }
  236. func TestDaoTxInsertCreditRecord(t *testing.T) {
  237. convey.Convey("TxInsertCreditRecord", t, func(ctx convey.C) {
  238. var (
  239. c = context.Background()
  240. tx, _ = d.BeginTran(c)
  241. cr = &model.CreditRecord{
  242. MID: 1001,
  243. Reason: 1,
  244. }
  245. )
  246. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  247. defer tx.Commit()
  248. Exec(c, "DELETE FROM credit_score_record WHERE mid = 1001")
  249. rows, err := d.TxInsertCreditRecord(tx, cr)
  250. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  251. ctx.So(err, convey.ShouldBeNil)
  252. ctx.So(rows, convey.ShouldNotBeNil)
  253. })
  254. })
  255. })
  256. }
  257. func TestDaoNickname(t *testing.T) {
  258. convey.Convey("Nickname", t, func(ctx convey.C) {
  259. var (
  260. c = context.Background()
  261. mid = int64(1004)
  262. )
  263. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  264. Exec(c, "INSERT INTO up_info_video(mid, account_state, is_deleted, nickname) VALUES(1004, 3, 0, 'test') ON DUPLICATE KEY UPDATE account_state = 3, is_deleted = 0")
  265. nickname, err := d.Nickname(c, mid)
  266. ctx.Convey("Then err should be nil.nickname should not be nil.", func(ctx convey.C) {
  267. ctx.So(err, convey.ShouldBeNil)
  268. ctx.So(nickname, convey.ShouldNotBeNil)
  269. })
  270. })
  271. })
  272. }
  273. func TestDaoCreditScore(t *testing.T) {
  274. convey.Convey("CreditScore", t, func(ctx convey.C) {
  275. var (
  276. c = context.Background()
  277. mid = int64(1001)
  278. )
  279. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  280. Exec(c, "INSERT INTO credit_score(mid, score) VALUES(1001, 100)")
  281. score, err := d.CreditScore(c, mid)
  282. ctx.Convey("Then err should be nil.score should not be nil.", func(ctx convey.C) {
  283. ctx.So(err, convey.ShouldBeNil)
  284. ctx.So(score, convey.ShouldNotBeNil)
  285. })
  286. })
  287. })
  288. }
  289. func TestDaoBgmUpCount(t *testing.T) {
  290. convey.Convey("BgmUpCount", t, func(ctx convey.C) {
  291. var (
  292. c = context.Background()
  293. mid = int64(1001)
  294. )
  295. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  296. Exec(c, "INSERT INTO background_music(mid) VALUES(1001)")
  297. count, err := d.BgmUpCount(c, mid)
  298. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  299. ctx.So(err, convey.ShouldBeNil)
  300. ctx.So(count, convey.ShouldNotBeNil)
  301. })
  302. })
  303. })
  304. }
  305. func TestDaoTxDeductCreditScore(t *testing.T) {
  306. convey.Convey("TxDeductCreditScore", t, func(ctx convey.C) {
  307. var (
  308. c = context.Background()
  309. tx, _ = d.BeginTran(c)
  310. score = int(10)
  311. mid = int64(1001)
  312. )
  313. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  314. defer tx.Commit()
  315. Exec(c, "INSERT INTO credit_score(mid, score) VALUES(1001, 100)")
  316. rows, err := d.TxDeductCreditScore(tx, score, mid)
  317. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  318. ctx.So(err, convey.ShouldBeNil)
  319. ctx.So(rows, convey.ShouldNotBeNil)
  320. })
  321. })
  322. })
  323. }