welfare_test.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/vip/model"
  6. "go-common/library/log"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoWelfareTypeAdd(t *testing.T) {
  10. convey.Convey("WelfareTypeAdd", t, func(ctx convey.C) {
  11. var (
  12. wt = &model.WelfareType{ID: 1000000, Name: "utTestAdd"}
  13. )
  14. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  15. err := d.WelfareTypeAdd(wt)
  16. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestDaoWelfareTypeUpd(t *testing.T) {
  23. convey.Convey("WelfareTypeUpd", t, func(ctx convey.C) {
  24. var (
  25. wt = &model.WelfareType{ID: 1000000, Name: "utTestUpd"}
  26. )
  27. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  28. err := d.WelfareTypeUpd(wt)
  29. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. })
  32. })
  33. })
  34. }
  35. func TestDaoWelfareTypeState(t *testing.T) {
  36. convey.Convey("WelfareTypeState", t, func(ctx convey.C) {
  37. var (
  38. tx = d.BeginGormTran(context.Background())
  39. id = int(1000000)
  40. state = int(1)
  41. operId = int(0)
  42. operName = "utTest"
  43. )
  44. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  45. err := d.WelfareTypeState(tx, id, state, operId, operName)
  46. tx.Commit()
  47. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestDaoWelfareTypeList(t *testing.T) {
  54. convey.Convey("WelfareTypeList", t, func(ctx convey.C) {
  55. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  56. wts, err := d.WelfareTypeList()
  57. ctx.Convey("Then err should be nil.wts should not be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. ctx.So(wts, convey.ShouldNotBeNil)
  60. })
  61. })
  62. })
  63. }
  64. func TestDaoWelfareAdd(t *testing.T) {
  65. convey.Convey("WelfareAdd", t, func(ctx convey.C) {
  66. var (
  67. wt = &model.Welfare{ID: 100000, Tid: 100000, WelfareName: "utTestAdd"}
  68. )
  69. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  70. err := d.WelfareAdd(wt)
  71. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. })
  74. })
  75. })
  76. }
  77. func TestDaoWelfareUpd(t *testing.T) {
  78. convey.Convey("WelfareUpd", t, func(ctx convey.C) {
  79. var (
  80. wt = &model.WelfareReq{ID: 100000, Tid: 100000, WelfareName: "utTestUpd"}
  81. )
  82. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  83. err := d.WelfareUpd(wt)
  84. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  85. ctx.So(err, convey.ShouldBeNil)
  86. })
  87. })
  88. })
  89. }
  90. func TestDaoWelfareState(t *testing.T) {
  91. convey.Convey("WelfareState", t, func(ctx convey.C) {
  92. var (
  93. id = int(100000)
  94. state = int(1)
  95. operId = int(0)
  96. operName = "utTest"
  97. )
  98. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  99. err := d.WelfareState(id, state, operId, operName)
  100. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  101. ctx.So(err, convey.ShouldBeNil)
  102. })
  103. })
  104. })
  105. }
  106. func TestDaoResetWelfareTid(t *testing.T) {
  107. convey.Convey("ResetWelfareTid", t, func(ctx convey.C) {
  108. var (
  109. tx = d.BeginGormTran(context.Background())
  110. tid = int(100000)
  111. )
  112. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  113. err := d.ResetWelfareTid(tx, tid)
  114. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. })
  117. })
  118. })
  119. }
  120. func TestDaoWelfareList(t *testing.T) {
  121. convey.Convey("WelfareList", t, func(ctx convey.C) {
  122. var (
  123. tid = int(100000)
  124. )
  125. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  126. ws, err := d.WelfareList(tid)
  127. ctx.Convey("Then err should be nil.ws should not be nil.", func(ctx convey.C) {
  128. ctx.So(err, convey.ShouldBeNil)
  129. ctx.So(ws, convey.ShouldNotBeNil)
  130. })
  131. })
  132. })
  133. }
  134. func TestDaoWelfareBatchSave(t *testing.T) {
  135. convey.Convey("WelfareBatchSave", t, func(ctx convey.C) {
  136. var (
  137. wcb = &model.WelfareCodeBatch{ID: 100000, BatchName: "utTest"}
  138. )
  139. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  140. err := d.WelfareBatchSave(wcb)
  141. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. })
  144. })
  145. })
  146. }
  147. func TestDaoWelfareBatchList(t *testing.T) {
  148. convey.Convey("WelfareBatchList", t, func(ctx convey.C) {
  149. var (
  150. wid = int(100000)
  151. )
  152. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  153. wbs, err := d.WelfareBatchList(wid)
  154. ctx.Convey("Then err should be nil.wbs should not be nil.", func(ctx convey.C) {
  155. ctx.So(err, convey.ShouldBeNil)
  156. ctx.So(wbs, convey.ShouldNotBeNil)
  157. })
  158. })
  159. })
  160. }
  161. func TestDaoWelfareBatchState(t *testing.T) {
  162. convey.Convey("WelfareBatchState", t, func(ctx convey.C) {
  163. var (
  164. tx = d.BeginGormTran(context.Background())
  165. id = int(100000)
  166. state = int(1)
  167. operId = int(0)
  168. operName = "utTest"
  169. )
  170. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  171. err := d.WelfareBatchState(tx, id, state, operId, operName)
  172. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  173. ctx.So(err, convey.ShouldBeNil)
  174. })
  175. })
  176. })
  177. }
  178. func TestDaoWelfareCodeBatchInsert(t *testing.T) {
  179. convey.Convey("WelfareCodeBatchInsert", t, func(ctx convey.C) {
  180. var (
  181. wcs = []*model.WelfareCode{}
  182. wc = new(model.WelfareCode)
  183. )
  184. wc.Code = "utTest"
  185. wc.Bid = 1000000
  186. wc.Wid = 1000000
  187. wcs = append(wcs, wc)
  188. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  189. err := d.WelfareCodeBatchInsert(wcs)
  190. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  191. ctx.So(err, convey.ShouldBeNil)
  192. })
  193. })
  194. d.delCode()
  195. })
  196. }
  197. func (d *Dao) delCode() {
  198. codeInfo := &model.WelfareCode{
  199. Bid: 1000000,
  200. Wid: 1000000,
  201. Code: "utTest",
  202. }
  203. if err := d.vip.Where("bid = ? and wid =? and code = ?", codeInfo.Bid, codeInfo.Wid, codeInfo.Code).Delete(codeInfo).Error; err != nil {
  204. log.Error("DelUser error(%v)", err)
  205. }
  206. }
  207. func TestDaoWelfareCodeStatus(t *testing.T) {
  208. convey.Convey("WelfareCodeStatus", t, func(ctx convey.C) {
  209. var (
  210. tx = d.BeginGormTran(context.Background())
  211. bid = int(100000)
  212. state = int(1)
  213. )
  214. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  215. err := d.WelfareCodeStatus(tx, bid, state)
  216. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  217. ctx.So(err, convey.ShouldBeNil)
  218. })
  219. })
  220. })
  221. }
  222. func TestDaogetBatchInsertSQL(t *testing.T) {
  223. convey.Convey("getBatchInsertSQL", t, func(ctx convey.C) {
  224. var (
  225. buff = []*model.WelfareCode{}
  226. )
  227. buff = append(buff, new(model.WelfareCode))
  228. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  229. stmt, valueArgs := getBatchInsertSQL(buff)
  230. ctx.Convey("Then stmt,valueArgs should not be nil.", func(ctx convey.C) {
  231. ctx.So(valueArgs, convey.ShouldNotBeNil)
  232. ctx.So(stmt, convey.ShouldNotBeNil)
  233. })
  234. })
  235. })
  236. }