user_info_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/tv/internal/model"
  5. "math/rand"
  6. "testing"
  7. "time"
  8. xtime "go-common/library/time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestDaoRawUserInfoByMid(t *testing.T) {
  12. convey.Convey("RawUserInfoByMid", t, func(ctx convey.C) {
  13. var (
  14. c = context.Background()
  15. mid = int64(27515308)
  16. )
  17. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  18. ui, err := d.RawUserInfoByMid(c, mid)
  19. ctx.Convey("Then err should be nil.ui should not be nil.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(ui, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestDaoTxInsertUserInfo(t *testing.T) {
  27. convey.Convey("TxInsertUserInfo", t, func(ctx convey.C) {
  28. var (
  29. c = context.Background()
  30. tx, _ = d.BeginTran(c)
  31. ui = &model.UserInfo{
  32. Mid: int64(rand.Int() / 10000000000),
  33. Ver: 1,
  34. VipType: 1,
  35. OverdueTime: xtime.Time(time.Now().Unix() + 60*60*24*31),
  36. }
  37. )
  38. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  39. id, err := d.TxInsertUserInfo(c, tx, ui)
  40. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. ctx.So(id, convey.ShouldNotBeNil)
  43. })
  44. })
  45. ctx.Reset(func() {
  46. tx.Commit()
  47. })
  48. })
  49. }
  50. func TestDaoTxUpdateUserInfo(t *testing.T) {
  51. convey.Convey("TxUpdateUserInfo", t, func(ctx convey.C) {
  52. var (
  53. c = context.Background()
  54. tx, _ = d.BeginTran(c)
  55. ui = &model.UserInfo{
  56. Mid: 27515308,
  57. Ver: 1,
  58. VipType: 1,
  59. OverdueTime: xtime.Time(time.Now().Unix() + 60*60*24*31),
  60. }
  61. )
  62. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  63. err := d.TxUpdateUserInfo(c, tx, ui)
  64. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. })
  67. })
  68. ctx.Reset(func() {
  69. tx.Commit()
  70. })
  71. })
  72. }
  73. func TestDaoTxUpdateUserStatus(t *testing.T) {
  74. convey.Convey("TxUpdateUserStatus", t, func(ctx convey.C) {
  75. var (
  76. c = context.Background()
  77. tx, _ = d.BeginTran(c)
  78. ui = &model.UserInfo{
  79. Mid: 27515308,
  80. Status: 1,
  81. }
  82. )
  83. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  84. err := d.TxUpdateUserStatus(c, tx, ui)
  85. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. })
  88. })
  89. ctx.Reset(func() {
  90. tx.Commit()
  91. })
  92. })
  93. }
  94. func TestDaoTxUpdateUserPayType(t *testing.T) {
  95. convey.Convey("TxUpdateUserPayType", t, func(ctx convey.C) {
  96. var (
  97. c = context.Background()
  98. tx, _ = d.BeginTran(c)
  99. ui = &model.UserInfo{
  100. Mid: 27515308,
  101. PayType: 1,
  102. }
  103. )
  104. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  105. err := d.TxUpdateUserPayType(c, tx, ui)
  106. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. })
  109. })
  110. ctx.Reset(func() {
  111. tx.Commit()
  112. })
  113. })
  114. }