change_history_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/tv/internal/model"
  5. xtime "go-common/library/time"
  6. "testing"
  7. "time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoUserChangeHistoryByID(t *testing.T) {
  11. convey.Convey("UserChangeHistoryByID", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. id = int32(10)
  15. )
  16. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  17. uch, err := d.UserChangeHistoryByID(c, id)
  18. ctx.Convey("Then err should be nil.uch should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(uch, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoUserChangeHistorysByMid(t *testing.T) {
  26. convey.Convey("UserChangeHistorysByMid", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. mid = int64(27515308)
  30. pn = int32(1)
  31. ps = int32(10)
  32. )
  33. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  34. res, total, err := d.UserChangeHistorysByMid(c, mid, pn, ps)
  35. ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(total, convey.ShouldNotBeNil)
  38. ctx.So(res, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoUserChangeHistorysByMidAndCtime(t *testing.T) {
  44. convey.Convey("UserChangeHistorysByMidAndCtime", t, func(ctx convey.C) {
  45. var (
  46. c = context.Background()
  47. mid = int64(27515308)
  48. from = xtime.Time(0)
  49. to = xtime.Time(time.Now().Unix())
  50. pn = int32(1)
  51. ps = int32(10)
  52. )
  53. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  54. res, total, err := d.UserChangeHistorysByMidAndCtime(c, mid, from, to, pn, ps)
  55. ctx.Convey("Then err should be nil.res,total should not be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(total, convey.ShouldNotBeNil)
  58. ctx.So(res, convey.ShouldNotBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestDaoTxInsertUserChangeHistory(t *testing.T) {
  64. convey.Convey("TxInsertUserChangeHistory", t, func(ctx convey.C) {
  65. var (
  66. c = context.Background()
  67. tx, _ = d.BeginTran(c)
  68. uch = &model.UserChangeHistory{
  69. Mid: 27515308,
  70. ChangeType: model.UserChangeTypeCancelContract,
  71. ChangeTime: xtime.Time(time.Now().Unix()),
  72. OrderNo: "T12345678345678",
  73. Days: 31,
  74. OperatorId: "",
  75. Remark: "test",
  76. }
  77. )
  78. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  79. id, err := d.TxInsertUserChangeHistory(c, tx, uch)
  80. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. ctx.So(id, convey.ShouldNotBeNil)
  83. })
  84. })
  85. ctx.Reset(func() {
  86. tx.Commit()
  87. })
  88. })
  89. }