trade_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/growup/model"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestServicetradeDao(t *testing.T) {
  10. convey.Convey("tradeDao", t, func(ctx convey.C) {
  11. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  12. p1 := s.tradeDao()
  13. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  14. ctx.So(p1, convey.ShouldNotBeNil)
  15. })
  16. })
  17. })
  18. }
  19. func TestServiceSyncGoods(t *testing.T) {
  20. convey.Convey("SyncGoods", t, func(ctx convey.C) {
  21. var (
  22. c = context.Background()
  23. gt = int(1)
  24. )
  25. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  26. eff, err := s.SyncGoods(c, gt)
  27. ctx.Convey("Then err should be nil.eff should not be nil.", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. ctx.So(eff, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestServiceGoodsList(t *testing.T) {
  35. convey.Convey("GoodsList", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. from = int(0)
  39. limit = int(20)
  40. )
  41. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  42. total, res, err := s.GoodsList(c, from, limit)
  43. ctx.Convey("Then err should be nil.total,res should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(res, convey.ShouldNotBeNil)
  46. ctx.So(total, convey.ShouldNotBeNil)
  47. })
  48. })
  49. })
  50. }
  51. func TestServiceUpdateGoodsInfo(t *testing.T) {
  52. convey.Convey("UpdateGoodsInfo", t, func(ctx convey.C) {
  53. var (
  54. c = context.Background()
  55. discount = int(100)
  56. ID = int64(1)
  57. )
  58. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  59. p1, err := s.UpdateGoodsInfo(c, discount, ID)
  60. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. ctx.So(p1, convey.ShouldNotBeNil)
  63. })
  64. })
  65. })
  66. }
  67. func TestServiceUpdateGoodsDisplay(t *testing.T) {
  68. convey.Convey("UpdateGoodsDisplay", t, func(ctx convey.C) {
  69. var (
  70. c = context.Background()
  71. status = model.DisplayOff
  72. IDs = []int64{1}
  73. )
  74. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  75. eff, err := s.UpdateGoodsDisplay(c, status, IDs)
  76. ctx.Convey("Then err should be nil.eff should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. ctx.So(eff, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestServiceonlineGoods(t *testing.T) {
  84. convey.Convey("onlineGoods", t, func(ctx convey.C) {
  85. var (
  86. c = context.Background()
  87. IDs = []int64{1}
  88. )
  89. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  90. p1, err := s.onlineGoods(c, IDs)
  91. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  92. ctx.So(err, convey.ShouldBeNil)
  93. ctx.So(p1, convey.ShouldNotBeNil)
  94. })
  95. })
  96. })
  97. }
  98. func TestServiceofflineGoods(t *testing.T) {
  99. convey.Convey("offlineGoods", t, func(ctx convey.C) {
  100. var (
  101. c = context.Background()
  102. IDs = []int64{1}
  103. )
  104. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  105. p1, err := s.offlineGoods(c, IDs)
  106. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(p1, convey.ShouldNotBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestServiceOrderStatistics(t *testing.T) {
  114. convey.Convey("OrderStatistics", t, func(ctx convey.C) {
  115. var (
  116. c = context.Background()
  117. arg = &model.OrderQueryArg{}
  118. )
  119. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  120. data, err := s.OrderStatistics(c, arg)
  121. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(data, convey.ShouldNotBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestServiceorderAll(t *testing.T) {
  129. convey.Convey("orderAll", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. where = "id<10"
  133. )
  134. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  135. orders, err := s.orderAll(c, where)
  136. ctx.Convey("Then err should be nil.orders should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. ctx.So(orders, convey.ShouldNotBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestServiceorderStatistics(t *testing.T) {
  144. convey.Convey("orderStatistics", t, func(ctx convey.C) {
  145. var (
  146. orders = []*model.OrderInfo{}
  147. start = time.Now()
  148. end = time.Now().AddDate(0, 0, -1)
  149. timeType = model.Monthly
  150. )
  151. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  152. p1 := orderStatistics(orders, start, end, timeType)
  153. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  154. ctx.So(p1, convey.ShouldNotBeNil)
  155. })
  156. })
  157. })
  158. }
  159. func TestServiceOrderExport(t *testing.T) {
  160. convey.Convey("OrderExport", t, func(ctx convey.C) {
  161. var (
  162. c = context.Background()
  163. arg = &model.OrderQueryArg{}
  164. from = int(0)
  165. limit = int(0)
  166. )
  167. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  168. res, err := s.OrderExport(c, arg, from, limit)
  169. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  170. ctx.So(err, convey.ShouldBeNil)
  171. ctx.So(res, convey.ShouldNotBeNil)
  172. })
  173. })
  174. })
  175. }
  176. func TestServiceOrderList(t *testing.T) {
  177. convey.Convey("OrderList", t, func(ctx convey.C) {
  178. var (
  179. c = context.Background()
  180. arg = &model.OrderQueryArg{}
  181. from = int(0)
  182. limit = int(0)
  183. )
  184. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  185. total, list, err := s.OrderList(c, arg, from, limit)
  186. ctx.Convey("Then err should be nil.total,list should not be nil.", func(ctx convey.C) {
  187. ctx.So(err, convey.ShouldBeNil)
  188. ctx.So(list, convey.ShouldNotBeNil)
  189. ctx.So(total, convey.ShouldNotBeNil)
  190. })
  191. })
  192. })
  193. }
  194. func TestServicepreprocess(t *testing.T) {
  195. convey.Convey("preprocess", t, func(ctx convey.C) {
  196. var (
  197. c = context.Background()
  198. arg = &model.OrderQueryArg{}
  199. )
  200. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  201. err := preprocess(c, arg)
  202. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  203. ctx.So(err, convey.ShouldBeTrue)
  204. })
  205. })
  206. })
  207. }
  208. func TestServiceorderQueryStr(t *testing.T) {
  209. convey.Convey("orderQueryStr", t, func(ctx convey.C) {
  210. var (
  211. arg = &model.OrderQueryArg{}
  212. )
  213. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  214. p1 := orderQueryStr(arg)
  215. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  216. ctx.So(p1, convey.ShouldNotBeNil)
  217. })
  218. })
  219. })
  220. }