coupon_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "testing"
  6. "time"
  7. "go-common/app/admin/main/coupon/conf"
  8. "go-common/app/admin/main/coupon/model"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. c = context.TODO()
  13. s *Service
  14. )
  15. func init() {
  16. var (
  17. err error
  18. )
  19. flag.Set("conf", "../cmd/coupon-admin.toml")
  20. if err = conf.Init(); err != nil {
  21. panic(err)
  22. }
  23. c = context.Background()
  24. if s == nil {
  25. s = New(conf.Conf)
  26. }
  27. time.Sleep(time.Second)
  28. }
  29. // go test -test.v -test.run TestAddBatchInfo
  30. func TestAddBatchInfo(t *testing.T) {
  31. Convey("TestAddBatchInfo ", t, func() {
  32. var err error
  33. b := new(model.CouponBatchInfo)
  34. b.AppID = int64(1)
  35. b.Name = "name"
  36. b.MaxCount = int64(100)
  37. b.CurrentCount = int64(0)
  38. b.StartTime = time.Now().Unix()
  39. b.ExpireTime = time.Now().Unix() + int64(10000000)
  40. err = s.AddBatchInfo(c, b)
  41. So(err, ShouldBeNil)
  42. })
  43. }
  44. // go test -test.v -test.run TestBatchList
  45. func TestBatchList(t *testing.T) {
  46. Convey("TestBatchList ", t, func() {
  47. var err error
  48. _, err = s.BatchList(c, &model.ArgBatchList{AppID: 1})
  49. So(err, ShouldBeNil)
  50. })
  51. }
  52. // go test -test.v -test.run TestSalaryCoupon
  53. func TestSalaryCoupon(t *testing.T) {
  54. Convey("TestSalaryCoupon ", t, func() {
  55. var (
  56. err error
  57. mid int64 = 1
  58. ct int64 = 2
  59. token = "test03"
  60. count = 20
  61. )
  62. err = s.SalaryCoupon(c, mid, ct, count, token)
  63. So(err, ShouldBeNil)
  64. })
  65. }
  66. func TestService_CouponViewBatchAdd(t *testing.T) {
  67. Convey("view batch add ", t, func() {
  68. arg := new(model.ArgCouponViewBatch)
  69. arg.AppID = 1
  70. arg.Name = "观影券test"
  71. arg.StartTime = time.Now().Unix()
  72. arg.ExpireTime = time.Now().AddDate(0, 0, 12).Unix()
  73. arg.Operator = "admin"
  74. arg.MaxCount = -1
  75. arg.LimitCount = -1
  76. err := s.CouponViewBatchAdd(c, arg)
  77. So(err, ShouldBeNil)
  78. })
  79. }
  80. func TestService_CouponViewbatchSave(t *testing.T) {
  81. Convey("view batch save", t, func() {
  82. arg := new(model.ArgCouponViewBatch)
  83. arg.ID = 47
  84. arg.AppID = 1
  85. arg.Name = "观影券test"
  86. arg.StartTime = time.Now().Unix()
  87. arg.ExpireTime = time.Now().AddDate(0, 0, 12).Unix()
  88. arg.Operator = "admin"
  89. arg.MaxCount = 100
  90. arg.LimitCount = -1
  91. err := s.CouponViewbatchSave(c, arg)
  92. So(err, ShouldBeNil)
  93. })
  94. }
  95. func TestService_CouponViewBlock(t *testing.T) {
  96. Convey("coupon view block", t, func() {
  97. mid := int64(39)
  98. couponToken := "326209901520180419161313"
  99. err := s.CouponViewBlock(c, mid, couponToken)
  100. So(err, ShouldBeNil)
  101. })
  102. }
  103. func TestService_CouponViewUnblock(t *testing.T) {
  104. Convey("coupon view un block", t, func() {
  105. mid := int64(39)
  106. couponToken := "326209901520180419161313"
  107. err := s.CouponViewUnblock(c, mid, couponToken)
  108. So(err, ShouldBeNil)
  109. })
  110. }
  111. func TestService_CouponViewList(t *testing.T) {
  112. Convey("coupon view list", t, func() {
  113. arg := new(model.ArgSearchCouponView)
  114. arg.Mid = 39
  115. arg.AppID = 1
  116. res, count, err := s.CouponViewList(c, arg)
  117. t.Logf("res:%+v count:%+v", res, count)
  118. So(err, ShouldBeNil)
  119. })
  120. }