reply_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/admin/main/reply/conf"
  6. "go-common/app/admin/main/reply/model"
  7. "testing"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestReply(t *testing.T) {
  11. c := context.Background()
  12. Convey("reply del and recover", t, WithService(func(s *Service) {
  13. sub, err := s.subject(c, 5464686, 1)
  14. So(err, ShouldBeNil)
  15. rp, err := s.reply(c, 5464686, 894717392)
  16. So(err, ShouldBeNil)
  17. err = s.adminDeleteReply(c, 23, []int64{5464686, 5464686}, []int64{894733824, 894733816}, 0, 1, 0, true, "test", "test", 0, 0)
  18. So(err, ShouldBeNil)
  19. rp2, err := s.reply(c, 5464686, 894733824)
  20. So(err, ShouldBeNil)
  21. So(rp2.State, ShouldEqual, 3)
  22. rp2, err = s.reply(c, 5464686, 894733816)
  23. So(err, ShouldBeNil)
  24. So(rp2.State, ShouldEqual, 3)
  25. rp2, err = s.reply(c, 5464686, 894717392)
  26. So(err, ShouldBeNil)
  27. So((rp2.RCount - rp.RCount), ShouldEqual, -2)
  28. sub2, err := s.subject(c, 5464686, 1)
  29. So(err, ShouldBeNil)
  30. So((sub2.ACount - sub.ACount), ShouldEqual, -2)
  31. err = s.AdminRecoverReply(c, 23, "asd", 5464686, 894733824, 1, "test")
  32. So(err, ShouldBeNil)
  33. err = s.AdminRecoverReply(c, 23, "sad", 5464686, 894733816, 1, "test")
  34. So(err, ShouldBeNil)
  35. rp2, err = s.reply(c, 5464686, 894733824)
  36. So(err, ShouldBeNil)
  37. So(rp2.State, ShouldEqual, 0)
  38. rp2, err = s.reply(c, 5464686, 894733816)
  39. So(err, ShouldBeNil)
  40. So(rp2.State, ShouldEqual, 0)
  41. rp2, err = s.reply(c, 5464686, 894717392)
  42. So(err, ShouldBeNil)
  43. So((rp2.RCount - rp.RCount), ShouldEqual, 0)
  44. sub2, err = s.subject(c, 5464686, 1)
  45. So(err, ShouldBeNil)
  46. So((sub2.ACount - sub.ACount), ShouldEqual, 0)
  47. alog, err := s.dao.AdminLog(c, 894733824)
  48. So(err, ShouldBeNil)
  49. So(alog.State, ShouldEqual, 3)
  50. alog, err = s.dao.AdminLog(c, 894733816)
  51. So(err, ShouldBeNil)
  52. So(alog.State, ShouldEqual, 3)
  53. }))
  54. Convey("reply top", t, WithService(func(s *Service) {
  55. err := s.AddTop(c, 23, "asd", 5464686, 894717392, 1, 1)
  56. So(err, ShouldBeNil)
  57. rp, err := s.reply(c, 5464686, 894717392)
  58. So(err, ShouldBeNil)
  59. So(rp.IsTop(), ShouldBeTrue)
  60. sub, err := s.subject(c, 5464686, 1)
  61. So(err, ShouldBeNil)
  62. So(sub.AttrVal(model.SubAttrTopAdmin), ShouldEqual, model.AttrYes)
  63. err = s.AddTop(c, 23, "asd", 5464686, 894717392, 1, 0)
  64. So(err, ShouldBeNil)
  65. rp, err = s.reply(c, 5464686, 894717392)
  66. So(err, ShouldBeNil)
  67. So(rp.IsTop(), ShouldBeFalse)
  68. sub, err = s.subject(c, 5464686, 1)
  69. So(err, ShouldBeNil)
  70. So(sub.AttrVal(model.SubAttrTopAdmin), ShouldEqual, model.AttrNo)
  71. }))
  72. Convey("reply pass", t, WithService(func(s *Service) {
  73. s.dao.UpdateReplyState(c, 5464686, 894717384, model.StatePending)
  74. err := s.adminPassReply(c, 23, "sds", []int64{5464686}, []int64{894717384}, 1, "test")
  75. So(err, ShouldBeNil)
  76. rp, err := s.reply(c, 5464686, 894717392)
  77. So(err, ShouldBeNil)
  78. So(rp.State, ShouldEqual, model.StateNormal)
  79. }))
  80. }
  81. func TestAddReplyConfig(t *testing.T) {
  82. var (
  83. bs []byte
  84. err error
  85. id int64
  86. typ = int32(1)
  87. oid = int64(1)
  88. adminID = int64(1)
  89. category = int32(1)
  90. operator = string("管理员001")
  91. c = context.Background()
  92. config = &model.Config{}
  93. )
  94. s := New(conf.Conf)
  95. config.Oid = oid
  96. config.Type = typ
  97. config.Category = category
  98. config.AdminID = adminID
  99. config.Operator = operator
  100. configValue := map[string]int64{
  101. "showentry": 0,
  102. "showadmin": 1,
  103. }
  104. if bs, err = json.Marshal(configValue); err == nil {
  105. config.Config = string(bs)
  106. }
  107. if id, err = s.AddReplyConfig(c, config); err != nil {
  108. t.Errorf("d.AddConfig error(%v)", err)
  109. }
  110. t.Logf("d.AddReplyConfig result(%d)", id)
  111. }