user_test.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/service/main/vip/model"
  7. xtime "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoVipInfo(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. mid = int64(0)
  14. )
  15. convey.Convey("VipInfo", t, func(ctx convey.C) {
  16. r, err := d.VipInfo(c, mid)
  17. ctx.Convey("Error should be nil", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. })
  20. ctx.Convey("r should not be nil", func(ctx convey.C) {
  21. ctx.So(r, convey.ShouldNotBeNil)
  22. })
  23. })
  24. }
  25. func TestDaoUpdateVipTypeAndStatus(t *testing.T) {
  26. var (
  27. c = context.TODO()
  28. mid = int64(0)
  29. vipStatus = int32(0)
  30. vipType = int32(0)
  31. )
  32. convey.Convey("UpdateVipTypeAndStatus", t, func(ctx convey.C) {
  33. ret, err := d.UpdateVipTypeAndStatus(c, mid, vipStatus, vipType)
  34. ctx.Convey("Error should be nil", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. })
  37. ctx.Convey("ret should not be nil", func(ctx convey.C) {
  38. ctx.So(ret, convey.ShouldNotBeNil)
  39. })
  40. })
  41. }
  42. func TestDaoSelChangeHistoryCount(t *testing.T) {
  43. var (
  44. c = context.TODO()
  45. arg = &model.ArgChangeHistory{}
  46. )
  47. convey.Convey("SelChangeHistoryCount", t, func(ctx convey.C) {
  48. count, err := d.SelChangeHistoryCount(c, arg)
  49. ctx.Convey("Error should be nil", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. ctx.Convey("count should not be nil", func(ctx convey.C) {
  53. ctx.So(count, convey.ShouldNotBeNil)
  54. })
  55. })
  56. }
  57. func TestDaoSelChangeHistory(t *testing.T) {
  58. var (
  59. c = context.TODO()
  60. arg = &model.ArgChangeHistory{}
  61. )
  62. convey.Convey("SelChangeHistory", t, func(ctx convey.C) {
  63. _, err := d.SelChangeHistory(c, arg)
  64. ctx.Convey("Error should be nil", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. })
  67. })
  68. }
  69. func TestDaoTxUpdateChannelID(t *testing.T) {
  70. var (
  71. c = context.TODO()
  72. mid = int64(0)
  73. payChannelID = int32(0)
  74. ver = int64(0)
  75. oldVer = int64(0)
  76. )
  77. convey.Convey("TxUpdateChannelID", t, func(ctx convey.C) {
  78. tx, err := d.StartTx(c)
  79. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. })
  82. defer tx.Commit()
  83. err = d.TxUpdateChannelID(tx, mid, payChannelID, ver, oldVer)
  84. ctx.Convey("Error should be nil", func(ctx convey.C) {
  85. ctx.So(err, convey.ShouldBeNil)
  86. })
  87. })
  88. }
  89. func TestDaoTxDupUserDiscount(t *testing.T) {
  90. var (
  91. c = context.TODO()
  92. mid = int64(0)
  93. discountID = int64(0)
  94. orderNo = ""
  95. status = int8(0)
  96. )
  97. convey.Convey("TxDupUserDiscount", t, func(ctx convey.C) {
  98. tx, err := d.StartTx(c)
  99. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  100. ctx.So(err, convey.ShouldBeNil)
  101. })
  102. defer tx.Commit()
  103. err = d.TxDupUserDiscount(tx, mid, discountID, orderNo, status)
  104. ctx.Convey("Error should be nil", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. })
  107. })
  108. }
  109. func TestDaoUpdatePayType(t *testing.T) {
  110. var (
  111. c = context.TODO()
  112. mid = int64(0)
  113. payType = int8(0)
  114. ver = int64(0)
  115. oldVer = int64(0)
  116. )
  117. convey.Convey("UpdatePayType", t, func(ctx convey.C) {
  118. tx, err := d.StartTx(c)
  119. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  120. ctx.So(err, convey.ShouldBeNil)
  121. })
  122. defer tx.Commit()
  123. a, err := d.UpdatePayType(tx, mid, payType, ver, oldVer)
  124. ctx.Convey("Error should be nil", func(ctx convey.C) {
  125. ctx.So(err, convey.ShouldBeNil)
  126. })
  127. ctx.Convey("a should not be nil", func(ctx convey.C) {
  128. ctx.So(a, convey.ShouldNotBeNil)
  129. })
  130. })
  131. }
  132. func TestDaoSelVipChangeHistory(t *testing.T) {
  133. var (
  134. c = context.TODO()
  135. relationID = ""
  136. )
  137. convey.Convey("SelVipChangeHistory", t, func(ctx convey.C) {
  138. r, err := d.SelVipChangeHistory(c, relationID)
  139. ctx.Convey("Error should be nil", func(ctx convey.C) {
  140. ctx.So(err, convey.ShouldBeNil)
  141. })
  142. ctx.Convey("r should not be nil", func(ctx convey.C) {
  143. ctx.So(r, convey.ShouldNotBeNil)
  144. })
  145. })
  146. }
  147. func TestDaoInsertVipChangeHistory(t *testing.T) {
  148. var (
  149. c = context.TODO()
  150. r = &model.VipChangeHistory{}
  151. )
  152. convey.Convey("InsertVipChangeHistory", t, func(ctx convey.C) {
  153. tx, err := d.StartTx(c)
  154. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  155. ctx.So(err, convey.ShouldBeNil)
  156. })
  157. defer tx.Commit()
  158. id, err := d.InsertVipChangeHistory(tx, r)
  159. ctx.Convey("Error should be nil", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. })
  162. ctx.Convey("id should not be nil", func(ctx convey.C) {
  163. ctx.So(id, convey.ShouldNotBeNil)
  164. })
  165. })
  166. }
  167. func TestDaoTxSelVipUserInfo(t *testing.T) {
  168. var (
  169. c = context.TODO()
  170. mid = int64(20606508)
  171. )
  172. convey.Convey("TxSelVipUserInfo", t, func(ctx convey.C) {
  173. tx, err := d.StartTx(c)
  174. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  175. ctx.So(err, convey.ShouldBeNil)
  176. })
  177. defer tx.Commit()
  178. r, err := d.TxSelVipUserInfo(tx, mid)
  179. ctx.Convey("Error should be nil", func(ctx convey.C) {
  180. ctx.So(err, convey.ShouldBeNil)
  181. })
  182. ctx.Convey("r should not be nil", func(ctx convey.C) {
  183. ctx.So(r, convey.ShouldNotBeNil)
  184. })
  185. })
  186. }
  187. func TestDaoTxAddIosVipUserInfo(t *testing.T) {
  188. var (
  189. c = context.TODO()
  190. r = &model.VipInfoDB{
  191. Mid: time.Now().Unix(),
  192. VipType: 1,
  193. VipPayType: 1,
  194. VipStatus: 0,
  195. VipStartTime: xtime.Time(time.Now().Unix()),
  196. VipOverdueTime: xtime.Time(time.Now().Unix()),
  197. AnnualVipOverdueTime: xtime.Time(time.Now().Unix()),
  198. VipRecentTime: xtime.Time(time.Now().Unix()),
  199. }
  200. )
  201. convey.Convey("TxAddIosVipUserInfo", t, func(ctx convey.C) {
  202. tx, err := d.StartTx(c)
  203. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  204. ctx.So(err, convey.ShouldBeNil)
  205. })
  206. eff, err := d.TxAddIosVipUserInfo(tx, r)
  207. err = tx.Commit()
  208. ctx.Convey("Error should be nil", func(ctx convey.C) {
  209. ctx.So(err, convey.ShouldBeNil)
  210. })
  211. ctx.Convey("eff should not be nil", func(ctx convey.C) {
  212. ctx.So(eff, convey.ShouldNotBeNil)
  213. })
  214. err = d.InsertVipUserInfo(tx, r)
  215. ctx.Convey("Error should not be nil", func(ctx convey.C) {
  216. ctx.So(err, convey.ShouldNotBeNil)
  217. })
  218. })
  219. }
  220. func TestDaoTxUpdateIosUserInfo(t *testing.T) {
  221. var (
  222. c = context.TODO()
  223. iosTime = xtime.Time(time.Now().Unix())
  224. mid = int64(0)
  225. )
  226. convey.Convey("TxUpdateIosUserInfo", t, func(ctx convey.C) {
  227. tx, err := d.StartTx(c)
  228. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  229. ctx.So(err, convey.ShouldBeNil)
  230. })
  231. defer tx.Commit()
  232. eff, err := d.TxUpdateIosUserInfo(tx, iosTime, mid)
  233. ctx.Convey("Error should be nil", func(ctx convey.C) {
  234. ctx.So(err, convey.ShouldBeNil)
  235. })
  236. ctx.Convey("eff should not be nil", func(ctx convey.C) {
  237. ctx.So(eff, convey.ShouldNotBeNil)
  238. })
  239. })
  240. }
  241. func TestDaoTxUpdateIosRenewUserInfo(t *testing.T) {
  242. var (
  243. c = context.TODO()
  244. paychannelID = int64(1)
  245. ver = int64(1)
  246. oldVer = int64(123)
  247. mid = int64(20606508)
  248. payType = int8(1)
  249. )
  250. convey.Convey("TxUpdateIosRenewUserInfo", t, func(ctx convey.C) {
  251. tx, err := d.StartTx(c)
  252. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  253. ctx.So(err, convey.ShouldBeNil)
  254. })
  255. defer tx.Commit()
  256. err = d.TxUpdateIosRenewUserInfo(tx, paychannelID, ver, oldVer, mid, payType)
  257. ctx.Convey("Error should be nil", func(ctx convey.C) {
  258. ctx.So(err, convey.ShouldBeNil)
  259. })
  260. })
  261. }
  262. func TestDaoUpdateVipUserInfo(t *testing.T) {
  263. var (
  264. c = context.TODO()
  265. r = &model.VipInfoDB{
  266. Mid: 206065080,
  267. VipType: 1,
  268. VipPayType: 1,
  269. VipStatus: 0,
  270. VipStartTime: xtime.Time(time.Now().Unix()),
  271. VipOverdueTime: xtime.Time(time.Now().Unix()),
  272. AnnualVipOverdueTime: xtime.Time(time.Now().Unix()),
  273. VipRecentTime: xtime.Time(time.Now().Unix()),
  274. }
  275. ver = int64(0)
  276. )
  277. convey.Convey("UpdateVipUserInfo", t, func(ctx convey.C) {
  278. tx, err := d.StartTx(c)
  279. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  280. ctx.So(err, convey.ShouldBeNil)
  281. })
  282. defer tx.Commit()
  283. a, err := d.UpdateVipUserInfo(tx, r, ver)
  284. ctx.Convey("Error should be nil", func(ctx convey.C) {
  285. ctx.So(err, convey.ShouldBeNil)
  286. })
  287. ctx.Convey("a should not be nil", func(ctx convey.C) {
  288. ctx.So(a, convey.ShouldNotBeNil)
  289. })
  290. })
  291. }