dialog_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/vip/model"
  5. "go-common/library/ecode"
  6. xtime "go-common/library/time"
  7. "testing"
  8. "time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestServiceDialogSave(t *testing.T) {
  12. curr := xtime.Time(time.Now().Unix())
  13. convey.Convey("DialogSave", t, func() {
  14. dlg1 := &model.ConfDialog{ID: 1, StartTime: curr, Operator: "tommy"}
  15. eff, err := s.DialogSave(context.TODO(), dlg1)
  16. convey.So(err, convey.ShouldBeNil)
  17. convey.So(eff, convey.ShouldNotBeNil)
  18. })
  19. convey.Convey("DialogSave2", t, func() {
  20. dlg2 := &model.ConfDialog{ID: 2, StartTime: xtime.Time(time.Now().Unix() + 1), Operator: "tommy"}
  21. _, err := s.DialogSave(context.TODO(), dlg2)
  22. convey.So(err, convey.ShouldEqual, ecode.VipDialogConflictErr)
  23. })
  24. convey.Convey("DialogByID", t, func() {
  25. dlg, err := s.DialogByID(context.TODO(), &model.ArgID{ID: 1})
  26. convey.So(err, convey.ShouldBeNil)
  27. convey.So(dlg, convey.ShouldNotBeNil)
  28. })
  29. convey.Convey("DialogEnable", t, func() {
  30. eff, err := s.DialogEnable(context.TODO(), &model.ConfDialog{ID: 1, Stage: true})
  31. convey.So(err, convey.ShouldBeNil)
  32. convey.So(eff, convey.ShouldNotBeNil)
  33. })
  34. convey.Convey("DialogAll", t, func() {
  35. res, err := s.DialogAll(context.TODO(), 0, 0, "active")
  36. convey.So(err, convey.ShouldBeNil)
  37. convey.So(res, convey.ShouldNotBeNil)
  38. })
  39. }
  40. func TestServiceDialogDel(t *testing.T) {
  41. convey.Convey("DialogDel", t, func() {
  42. eff, err := s.DialogDel(context.TODO(), nil, "")
  43. convey.So(err, convey.ShouldBeNil)
  44. convey.So(eff, convey.ShouldNotBeNil)
  45. })
  46. }
  47. func TestServiceDialogStatus(t *testing.T) {
  48. convey.Convey("dialogStatus padding", t, func() {
  49. v := &model.ConfDialog{Stage: true, StartTime: xtime.Time(time.Now().AddDate(1, 1, 1).Unix())}
  50. res := dialogStatus(v)
  51. convey.So(res, convey.ShouldEqual, "padding")
  52. })
  53. convey.Convey("dialogStatus active", t, func() {
  54. v := &model.ConfDialog{Stage: true}
  55. res := dialogStatus(v)
  56. convey.So(res, convey.ShouldEqual, "active")
  57. v.StartTime = xtime.Time(time.Now().AddDate(-1, 1, 1).Unix())
  58. res = dialogStatus(v)
  59. convey.So(res, convey.ShouldEqual, "active")
  60. v.EndTime = xtime.Time(time.Now().AddDate(1, 1, 1).Unix())
  61. res = dialogStatus(v)
  62. convey.So(res, convey.ShouldEqual, "active")
  63. })
  64. convey.Convey("dialogStatus inactive", t, func() {
  65. v := &model.ConfDialog{Stage: false}
  66. res := dialogStatus(v)
  67. convey.So(res, convey.ShouldEqual, "inactive")
  68. v.EndTime = xtime.Time(time.Now().AddDate(-1, 1, 1).Unix())
  69. res = dialogStatus(v)
  70. convey.So(res, convey.ShouldEqual, "inactive")
  71. })
  72. }