pay_order_test.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/tv/internal/model"
  5. "math/rand"
  6. "strconv"
  7. "testing"
  8. "time"
  9. xtime "go-common/library/time"
  10. "github.com/smartystreets/goconvey/convey"
  11. )
  12. func TestDaoPayOrderById(t *testing.T) {
  13. convey.Convey("PayOrderById", t, func(ctx convey.C) {
  14. var (
  15. c = context.Background()
  16. id = 20
  17. )
  18. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  19. po, err := d.PayOrderByID(c, id)
  20. ctx.Convey("Then err should be nil.po should not be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(po, convey.ShouldNotBeNil)
  23. })
  24. })
  25. })
  26. }
  27. func TestDaoPayOrderByOrderNo(t *testing.T) {
  28. convey.Convey("PayOrderByOrderNo", t, func(ctx convey.C) {
  29. var (
  30. c = context.Background()
  31. orderNo = "T123456789"
  32. )
  33. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  34. po, err := d.PayOrderByOrderNo(c, orderNo)
  35. ctx.Convey("Then err should be nil.po should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(po, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestDaoPayOrdersByMid(t *testing.T) {
  43. convey.Convey("PayOrdersByMid", t, func(ctx convey.C) {
  44. var (
  45. c = context.Background()
  46. mid = int(27515308)
  47. pn = int(1)
  48. ps = int(10)
  49. )
  50. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  51. res, total, err := d.PayOrdersByMid(c, mid, pn, ps)
  52. ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(total, convey.ShouldNotBeNil)
  55. ctx.So(res, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }
  60. func TestDaoPayOrdersByMidAndStatus(t *testing.T) {
  61. convey.Convey("PayOrdersByMidAndStatus", t, func(ctx convey.C) {
  62. var (
  63. c = context.Background()
  64. mid = int(27515308)
  65. status = int8(1)
  66. pn = int(1)
  67. ps = int(10)
  68. )
  69. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  70. res, total, err := d.PayOrdersByMidAndStatus(c, mid, status, pn, ps)
  71. ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(total, convey.ShouldNotBeNil)
  74. ctx.So(res, convey.ShouldNotBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestDaoPayOrdersByMidAndStatusAndCtime(t *testing.T) {
  80. convey.Convey("PayOrdersByMidAndStatusAndCtime", t, func(ctx convey.C) {
  81. var (
  82. c = context.Background()
  83. mid = int64(27515308)
  84. status = int8(1)
  85. from = xtime.Time(time.Now().Add(-time.Hour * 24).Unix())
  86. to = xtime.Time(time.Now().Unix())
  87. pn = int(1)
  88. ps = int(10)
  89. )
  90. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  91. res, total, err := d.PayOrdersByMidAndStatusAndCtime(c, mid, status, from, to, pn, ps)
  92. ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. ctx.So(total, convey.ShouldNotBeNil)
  95. ctx.So(res, convey.ShouldNotBeNil)
  96. })
  97. })
  98. })
  99. }
  100. func TestDaoTxInsertPayOrder(t *testing.T) {
  101. convey.Convey("TxInsertPayOrder", t, func(ctx convey.C) {
  102. var (
  103. c = context.Background()
  104. tx, _ = d.BeginTran(c)
  105. po = &model.PayOrder{
  106. OrderNo: "T123456789",
  107. Platform: 1,
  108. OrderType: 1,
  109. Mid: 27515308,
  110. BuyMonths: 1,
  111. ProductId: "wx345678",
  112. Quantity: 1,
  113. Status: 1,
  114. PaymentMoney: 100,
  115. PaymentType: "wechat",
  116. Ver: 1,
  117. Token: "TOKEN:123456789",
  118. AppChannel: "master",
  119. }
  120. )
  121. d.TxInsertPayOrder(c, tx, po)
  122. po.OrderNo = "T" + strconv.Itoa(rand.Int()/100000)
  123. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  124. id, err := d.TxInsertPayOrder(c, tx, po)
  125. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  126. ctx.So(err, convey.ShouldBeNil)
  127. ctx.So(id, convey.ShouldNotBeNil)
  128. })
  129. })
  130. ctx.Reset(func() {
  131. tx.Commit()
  132. })
  133. })
  134. }
  135. func TestDaoUnpaidNotCallbackOrder(t *testing.T) {
  136. convey.Convey("UnpaidNotCallbackOrder", t, func(ctx convey.C) {
  137. var (
  138. c = context.Background()
  139. stime xtime.Time
  140. etime = xtime.Time(time.Now().Unix())
  141. ps = int(500)
  142. pn = int(1)
  143. )
  144. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  145. res, err := d.UnpaidNotCallbackOrder(c, stime, etime, pn, ps)
  146. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  147. ctx.So(err, convey.ShouldBeNil)
  148. ctx.So(res, convey.ShouldNotBeNil)
  149. })
  150. })
  151. })
  152. }
  153. func TestDaoTxUpdatePayOrder(t *testing.T) {
  154. convey.Convey("TxUpdatePayOrder", t, func(ctx convey.C) {
  155. var (
  156. c = context.Background()
  157. tx, _ = d.BeginTran(c)
  158. )
  159. po, _ := d.PayOrderByID(c, 60)
  160. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  161. err := d.TxUpdatePayOrder(c, tx, po)
  162. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  163. ctx.So(err, convey.ShouldBeNil)
  164. })
  165. })
  166. ctx.Reset(func() {
  167. tx.Commit()
  168. })
  169. })
  170. }