activity_test.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/growup/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoGetActivityByName(t *testing.T) {
  9. convey.Convey("GetActivityByName", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. name = "test"
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. Exec(c, "INSERT INTO creative_activity(name) VALUES('test')")
  16. _, err := d.GetActivityByName(c, name)
  17. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestDaoActivityCount(t *testing.T) {
  24. convey.Convey("ActivityCount", t, func(ctx convey.C) {
  25. var (
  26. c = context.Background()
  27. query = ""
  28. )
  29. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  30. count, err := d.ActivityCount(c, query)
  31. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(count, convey.ShouldNotBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestDaoGetActivities(t *testing.T) {
  39. convey.Convey("GetActivities", t, func(ctx convey.C) {
  40. var (
  41. c = context.Background()
  42. query = ""
  43. from = int(0)
  44. limit = int(10)
  45. )
  46. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  47. acs, err := d.GetActivities(c, query, from, limit)
  48. ctx.Convey("Then err should be nil.acs should not be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. ctx.So(acs, convey.ShouldNotBeNil)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoTxGetActivityByName(t *testing.T) {
  56. convey.Convey("TxGetActivityByName", t, func(ctx convey.C) {
  57. var (
  58. tx, _ = d.BeginTran(context.Background())
  59. name = "test"
  60. )
  61. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  62. defer tx.Commit()
  63. id, err := d.TxGetActivityByName(tx, name)
  64. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. ctx.So(id, convey.ShouldNotBeNil)
  67. })
  68. })
  69. })
  70. }
  71. func TestDaoTxInsertActivity(t *testing.T) {
  72. convey.Convey("TxInsertActivity", t, func(ctx convey.C) {
  73. var (
  74. tx, _ = d.BeginTran(context.Background())
  75. ac = &model.CActivity{
  76. Name: "test1",
  77. }
  78. update = ""
  79. )
  80. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  81. defer tx.Commit()
  82. Exec(context.Background(), "DELETE FROM creative_activity WHERE name = 'test1'")
  83. rows, err := d.TxInsertActivity(tx, ac, update)
  84. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  85. ctx.So(err, convey.ShouldBeNil)
  86. ctx.So(rows, convey.ShouldNotBeNil)
  87. })
  88. })
  89. })
  90. }
  91. func TestDaoGetActivityBonus(t *testing.T) {
  92. convey.Convey("GetActivityBonus", t, func(ctx convey.C) {
  93. var (
  94. c = context.Background()
  95. ids = []int64{111}
  96. )
  97. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  98. Exec(c, "INSERT INTO activity_bonus(activity_id,ranking,bonus_money) VALUES(111, 1, 1)")
  99. _, err := d.GetActivityBonus(c, ids)
  100. ctx.Convey("Then err should be nil.brs should not be nil.", func(ctx convey.C) {
  101. ctx.So(err, convey.ShouldBeNil)
  102. })
  103. })
  104. })
  105. }
  106. func TestDaoTxInsertActivityBonusBatch(t *testing.T) {
  107. convey.Convey("TxInsertActivityBonusBatch", t, func(ctx convey.C) {
  108. var (
  109. c = context.Background()
  110. tx, _ = d.BeginTran(c)
  111. vals = "(1112, 10, 10)"
  112. )
  113. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  114. defer tx.Commit()
  115. rows, err := d.TxInsertActivityBonusBatch(tx, vals)
  116. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  117. ctx.So(err, convey.ShouldBeNil)
  118. ctx.So(rows, convey.ShouldNotBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestDaoUpActivityStateCount(t *testing.T) {
  124. convey.Convey("UpActivityStateCount", t, func(ctx convey.C) {
  125. var (
  126. c = context.Background()
  127. id = int64(111)
  128. states = []int64{1, 2, 3}
  129. )
  130. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  131. Exec(c, "INSERT INTO up_activity(activity_id, mid, state) VALUES(111, 1001, 2) ON DUPLICATE KEY UPDATE state = 2")
  132. count, err := d.UpActivityStateCount(c, id, states)
  133. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(count, convey.ShouldNotBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestDaoListUpActivity(t *testing.T) {
  141. convey.Convey("ListUpActivity", t, func(ctx convey.C) {
  142. var (
  143. c = context.Background()
  144. id = int64(111)
  145. from = int(0)
  146. limit = int(10)
  147. )
  148. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  149. ups, err := d.ListUpActivity(c, id, from, limit)
  150. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  151. ctx.So(err, convey.ShouldBeNil)
  152. ctx.So(ups, convey.ShouldNotBeNil)
  153. })
  154. })
  155. })
  156. }
  157. func TestDaoListUpActivitySuccess(t *testing.T) {
  158. convey.Convey("ListUpActivitySuccess", t, func(ctx convey.C) {
  159. var (
  160. c = context.Background()
  161. id = int64(111)
  162. mid = int64(1001)
  163. from = int(0)
  164. limit = int(10)
  165. )
  166. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  167. ups, err := d.ListUpActivitySuccess(c, id, mid, from, limit)
  168. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  169. ctx.So(err, convey.ShouldBeNil)
  170. ctx.So(ups, convey.ShouldNotBeNil)
  171. })
  172. })
  173. })
  174. }
  175. func TestDaoUpdateUpActivityState(t *testing.T) {
  176. convey.Convey("UpdateUpActivityState", t, func(ctx convey.C) {
  177. var (
  178. c = context.Background()
  179. activityID = int64(111)
  180. mids = []int64{1001}
  181. oldState = int(2)
  182. newState = int(3)
  183. )
  184. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  185. Exec(c, "INSERT INTO up_activity(activity_id, mid, state) VALUES(111, 1001, 2) ON DUPLICATE KEY UPDATE state = 2")
  186. rows, err := d.UpdateUpActivityState(c, activityID, mids, oldState, newState)
  187. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  188. ctx.So(err, convey.ShouldBeNil)
  189. ctx.So(rows, convey.ShouldNotBeNil)
  190. })
  191. })
  192. })
  193. }
  194. func TestDaoTxUpdateUpActivityState(t *testing.T) {
  195. convey.Convey("TxUpdateUpActivityState", t, func(ctx convey.C) {
  196. var (
  197. c = context.Background()
  198. tx, _ = d.BeginTran(c)
  199. activityID = int64(111)
  200. mids = []int64{1001}
  201. oldState = int(2)
  202. newState = int(3)
  203. )
  204. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  205. defer tx.Commit()
  206. Exec(c, "INSERT INTO up_activity(activity_id, mid, state) VALUES(111, 1001, 2) ON DUPLICATE KEY UPDATE state = 2")
  207. rows, err := d.TxUpdateUpActivityState(tx, activityID, mids, oldState, newState)
  208. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  209. ctx.So(err, convey.ShouldBeNil)
  210. ctx.So(rows, convey.ShouldNotBeNil)
  211. })
  212. })
  213. })
  214. }