prize_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package dao
  2. import (
  3. "context"
  4. "math/rand"
  5. "testing"
  6. "go-common/app/service/main/coupon/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoUserCard(t *testing.T) {
  10. convey.Convey("UserCard", t, func(convCtx convey.C) {
  11. var (
  12. c = context.Background()
  13. mid = int64(88895150)
  14. actID = int64(1)
  15. cardType = int8(1)
  16. noMID = int64(-1)
  17. )
  18. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  19. r, err := d.UserCard(c, mid, actID, cardType)
  20. convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
  21. convCtx.So(err, convey.ShouldBeNil)
  22. convCtx.So(r, convey.ShouldNotBeNil)
  23. })
  24. r, err = d.UserCard(c, noMID, actID, cardType)
  25. convCtx.Convey("Then err should be nil.r should be nil.", func(convCtx convey.C) {
  26. convCtx.So(err, convey.ShouldBeNil)
  27. convCtx.So(r, convey.ShouldBeNil)
  28. })
  29. })
  30. })
  31. }
  32. func TestDaoUserCards(t *testing.T) {
  33. convey.Convey("UserCards", t, func(convCtx convey.C) {
  34. var (
  35. c = context.Background()
  36. mid = int64(88895150)
  37. actID = int64(1)
  38. )
  39. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  40. res, err := d.UserCards(c, mid, actID)
  41. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  42. convCtx.So(err, convey.ShouldBeNil)
  43. convCtx.So(res, convey.ShouldNotBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestDaoAddUserCard(t *testing.T) {
  49. convey.Convey("AddUserCard", t, func(convCtx convey.C) {
  50. var (
  51. c = context.Background()
  52. tx, _ = d.BeginTran(context.Background())
  53. uc = &model.CouponUserCard{MID: rand.Int63n(9999999)}
  54. )
  55. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  56. a, err := d.AddUserCard(c, tx, uc)
  57. if err == nil {
  58. if err = tx.Commit(); err != nil {
  59. tx.Rollback()
  60. }
  61. } else {
  62. tx.Rollback()
  63. }
  64. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  65. convCtx.So(err, convey.ShouldBeNil)
  66. convCtx.So(a, convey.ShouldNotBeNil)
  67. })
  68. })
  69. })
  70. }
  71. func TestDaoUpdateUserCard(t *testing.T) {
  72. convey.Convey("UpdateUserCard", t, func(convCtx convey.C) {
  73. var (
  74. c = context.Background()
  75. mid = int64(0)
  76. state = int8(0)
  77. couponToken = ""
  78. )
  79. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  80. a, err := d.UpdateUserCard(c, mid, state, couponToken)
  81. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  82. convCtx.So(err, convey.ShouldBeNil)
  83. convCtx.So(a, convey.ShouldNotBeNil)
  84. })
  85. })
  86. })
  87. }
  88. func TestDaoClose(t *testing.T) {
  89. convey.Convey("TestDaoClose", t, func(convCtx convey.C) {
  90. d.Close()
  91. })
  92. }