order_test.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "math/rand"
  6. "testing"
  7. "time"
  8. "go-common/app/service/main/vip/model"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestDaoBeginTran(t *testing.T) {
  12. var (
  13. c = context.TODO()
  14. )
  15. convey.Convey("BeginTran", t, func(ctx convey.C) {
  16. tx, err := d.BeginTran(c)
  17. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. })
  20. ctx.Convey("tx should not be nil", func(ctx convey.C) {
  21. ctx.So(tx, convey.ShouldNotBeNil)
  22. })
  23. })
  24. }
  25. func TestDaoOrderCount(t *testing.T) {
  26. var (
  27. c = context.TODO()
  28. mid = int64(20606508)
  29. status = int8(1)
  30. )
  31. convey.Convey("OrderCount", t, func(ctx convey.C) {
  32. count, err := d.OrderCount(c, mid, status)
  33. ctx.Convey("Error should be nil", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. })
  36. ctx.Convey("count should not be nil", func(ctx convey.C) {
  37. ctx.So(count, convey.ShouldNotBeNil)
  38. })
  39. })
  40. }
  41. func TestDaoOrderList(t *testing.T) {
  42. var (
  43. c = context.TODO()
  44. mid = int64(20606508)
  45. status = int8(1)
  46. pn = int(1)
  47. ps = int(20)
  48. )
  49. convey.Convey("OrderList", t, func(ctx convey.C) {
  50. _, err := d.OrderList(c, mid, status, pn, ps)
  51. ctx.Convey("Error should be nil", func(ctx convey.C) {
  52. ctx.So(err, convey.ShouldBeNil)
  53. })
  54. })
  55. }
  56. func TestDaoOrderInfo(t *testing.T) {
  57. var (
  58. c = context.TODO()
  59. orderNo = "12345"
  60. )
  61. convey.Convey("OrderInfo", t, func(ctx convey.C) {
  62. _, err := d.OrderInfo(c, orderNo)
  63. ctx.Convey("Error should be nil", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. })
  66. })
  67. }
  68. func TestDaoDiscountSQL(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. mid = int64(20606508)
  72. discountID = int64(2)
  73. )
  74. convey.Convey("DiscountSQL", t, func(ctx convey.C) {
  75. _, err := d.DiscountSQL(c, mid, discountID)
  76. ctx.Convey("Error should be nil", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. }
  81. func TestDaoPriceMapping(t *testing.T) {
  82. var (
  83. c = context.TODO()
  84. monthID = int64(1)
  85. platform = int8(1)
  86. )
  87. convey.Convey("PriceMapping", t, func(ctx convey.C) {
  88. _, err := d.PriceMapping(c, monthID, platform)
  89. ctx.Convey("Error should be nil", func(ctx convey.C) {
  90. ctx.So(err, convey.ShouldBeNil)
  91. })
  92. })
  93. }
  94. func TestDaoTxAddOrder(t *testing.T) {
  95. var (
  96. c = context.TODO()
  97. p = &model.PayOrder{
  98. OrderNo: fmt.Sprintf("%d_%d", time.Now().Unix(), rand.Int31()),
  99. AppID: 1,
  100. Platform: 1,
  101. OrderType: 1,
  102. AppSubID: "a",
  103. Mid: 20606508,
  104. ToMid: 1,
  105. BuyMonths: 1,
  106. Money: 1.0,
  107. Status: 1,
  108. PayType: 1,
  109. RechargeBp: 1.0,
  110. ThirdTradeNo: "209",
  111. Ver: 1,
  112. UserIP: []byte("127.0.0.1"),
  113. }
  114. )
  115. convey.Convey("TxAddOrder", t, func(ctx convey.C) {
  116. tx, err := d.StartTx(c)
  117. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  118. ctx.So(err, convey.ShouldBeNil)
  119. })
  120. ctx.Convey("TxAddOrder Error should be nil", func(ctx convey.C) {
  121. id, err := d.TxAddOrder(tx, p)
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(id, convey.ShouldNotBeNil)
  124. err = tx.Commit()
  125. ctx.So(err, convey.ShouldBeNil)
  126. })
  127. })
  128. }
  129. func TestDaoAllMonthByOrder(t *testing.T) {
  130. var (
  131. c = context.TODO()
  132. orderStr = ""
  133. )
  134. convey.Convey("AllMonthByOrder", t, func(ctx convey.C) {
  135. res, err := d.AllMonthByOrder(c, orderStr)
  136. ctx.Convey("Error should be nil", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. })
  139. ctx.Convey("res should not be nil", func(ctx convey.C) {
  140. ctx.So(res, convey.ShouldNotBeNil)
  141. })
  142. })
  143. }
  144. func TestDaoTxUpdateOrderStatus(t *testing.T) {
  145. var (
  146. c = context.TODO()
  147. status = int8(0)
  148. payType = ""
  149. thirdTradeNO = ""
  150. orderNO = ""
  151. )
  152. convey.Convey("TxUpdateOrderStatus", 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. err = d.TxUpdateOrderStatus(c, tx, status, payType, thirdTradeNO, orderNO)
  159. ctx.Convey("Error should be nil", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. })
  162. })
  163. }
  164. func TestDaoTxUpdatePayOrder(t *testing.T) {
  165. var (
  166. c = context.TODO()
  167. o = &model.OrderInfo{
  168. OrderNo: "12345",
  169. AppID: 1,
  170. OrderType: 2,
  171. Platform: 1,
  172. Mid: 20606508,
  173. ToMid: 20606509,
  174. BuyMonths: 1,
  175. Money: 3.0,
  176. Status: 1,
  177. PayType: "1",
  178. RechargeBP: 3.0,
  179. ThirdTradeNo: "456",
  180. Ver: 23,
  181. AppSubID: "1234",
  182. }
  183. ver = int64(0)
  184. )
  185. convey.Convey("TxUpdatePayOrder", t, func(ctx convey.C) {
  186. tx, err := d.StartTx(c)
  187. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  188. ctx.So(err, convey.ShouldBeNil)
  189. })
  190. defer tx.Commit()
  191. err = d.TxUpdatePayOrder(tx, o, ver)
  192. ctx.Convey("Error should be nil", func(ctx convey.C) {
  193. ctx.So(err, convey.ShouldBeNil)
  194. })
  195. })
  196. }
  197. func TestDaoTxUpdateIosPayOrder(t *testing.T) {
  198. var (
  199. c = context.TODO()
  200. o = &model.OrderInfo{
  201. OrderNo: "12345",
  202. AppID: 1,
  203. OrderType: 2,
  204. Platform: 1,
  205. Mid: 20606508,
  206. ToMid: 20606509,
  207. BuyMonths: 1,
  208. Money: 3.0,
  209. Status: 1,
  210. PayType: "1",
  211. RechargeBP: 3.0,
  212. ThirdTradeNo: "456",
  213. Ver: 23,
  214. AppSubID: "1234",
  215. }
  216. ver = int64(0)
  217. )
  218. convey.Convey("TxUpdateIosPayOrder", t, func(ctx convey.C) {
  219. tx, err := d.StartTx(c)
  220. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  221. ctx.So(err, convey.ShouldBeNil)
  222. })
  223. defer tx.Commit()
  224. err = d.TxUpdateIosPayOrder(tx, o, ver)
  225. ctx.Convey("Error should be nil", func(ctx convey.C) {
  226. ctx.So(err, convey.ShouldBeNil)
  227. })
  228. })
  229. }
  230. func TestDaoTxUpdatePayOrderStatus(t *testing.T) {
  231. var (
  232. c = context.TODO()
  233. status = int8(0)
  234. id = int64(0)
  235. ver = int64(0)
  236. )
  237. convey.Convey("TxUpdatePayOrderStatus", t, func(ctx convey.C) {
  238. tx, err := d.StartTx(c)
  239. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  240. ctx.So(err, convey.ShouldBeNil)
  241. })
  242. defer tx.Commit()
  243. a, err := d.TxUpdatePayOrderStatus(tx, status, id, ver)
  244. ctx.Convey("Error should be nil", func(ctx convey.C) {
  245. ctx.So(err, convey.ShouldBeNil)
  246. })
  247. ctx.Convey("a should not be nil", func(ctx convey.C) {
  248. ctx.So(a, convey.ShouldNotBeNil)
  249. })
  250. })
  251. }
  252. func TestDaoTxAddOrderLog(t *testing.T) {
  253. var (
  254. c = context.TODO()
  255. mid = int64(0)
  256. orderNo = ""
  257. status = int8(0)
  258. )
  259. convey.Convey("TxAddOrderLog", t, func(ctx convey.C) {
  260. tx, err := d.StartTx(c)
  261. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  262. ctx.So(err, convey.ShouldBeNil)
  263. })
  264. defer tx.Commit()
  265. olog := new(model.VipPayOrderLog)
  266. olog.Mid = mid
  267. olog.Status = status
  268. olog.OrderNo = orderNo
  269. err = d.TxAddOrderLog(tx, olog)
  270. ctx.Convey("Error should be nil", func(ctx convey.C) {
  271. ctx.So(err, convey.ShouldBeNil)
  272. })
  273. })
  274. }
  275. func TestDaoPayOrderLast(t *testing.T) {
  276. var (
  277. c = context.TODO()
  278. mid = int64(0)
  279. status = int8(0)
  280. orderTypes = int64(0)
  281. )
  282. convey.Convey("PayOrderLast", t, func(ctx convey.C) {
  283. _, err := d.PayOrderLast(c, mid, status, orderTypes)
  284. ctx.Convey("Error should be nil", func(ctx convey.C) {
  285. ctx.So(err, convey.ShouldBeNil)
  286. })
  287. })
  288. }
  289. func TestDaoSelOldPayOrder(t *testing.T) {
  290. var (
  291. c = context.TODO()
  292. orderNo = ""
  293. )
  294. convey.Convey("SelOldPayOrder", t, func(ctx convey.C) {
  295. _, err := d.SelOldPayOrder(c, orderNo)
  296. ctx.Convey("Error should be nil", func(ctx convey.C) {
  297. ctx.So(err, convey.ShouldBeNil)
  298. })
  299. })
  300. }