need_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package dao
  2. import (
  3. "reflect"
  4. "testing"
  5. "go-common/app/admin/main/apm/model/need"
  6. "github.com/bouk/monkey"
  7. "github.com/jinzhu/gorm"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoNeedInfoAdd(t *testing.T) {
  11. convey.Convey("NeedInfoAdd", t, func() {
  12. arg := &need.NAddReq{
  13. Title: "wwe",
  14. Content: "sds",
  15. }
  16. err := d.NeedInfoAdd(arg, "fengshanshan")
  17. convey.So(err, convey.ShouldBeNil)
  18. })
  19. }
  20. func TestDaoNeedInfoList(t *testing.T) {
  21. convey.Convey("NeedInfoList", t, func() {
  22. arg := &need.NListReq{
  23. Status: 1,
  24. Ps: 10,
  25. Pn: 1,
  26. }
  27. res, err := d.NeedInfoList(arg)
  28. t.Logf("res:%+v", res)
  29. convey.So(err, convey.ShouldBeNil)
  30. convey.So(res, convey.ShouldNotBeNil)
  31. })
  32. }
  33. func TestDaoNeedInfoCount(t *testing.T) {
  34. convey.Convey("NeedInfoCount", t, func() {
  35. arg := &need.NListReq{
  36. Status: 1,
  37. }
  38. count, err := d.NeedInfoCount(arg)
  39. t.Logf("count:%+v", count)
  40. convey.So(err, convey.ShouldBeNil)
  41. convey.So(count, convey.ShouldNotBeNil)
  42. })
  43. }
  44. func TestDaoneedInfoCondition(t *testing.T) {
  45. convey.Convey("needInfoCondition", t, func() {
  46. arg := &need.NListReq{}
  47. p1 := d.needInfoCondition(arg)
  48. t.Logf("condition:%+v", p1)
  49. convey.So(p1, convey.ShouldNotBeNil)
  50. })
  51. }
  52. func TestDaoGetNeedInfo(t *testing.T) {
  53. convey.Convey("GetNeedInfo", t, func() {
  54. r, err := d.GetNeedInfo(97)
  55. t.Logf("GetNeedInfo:%+v", r)
  56. convey.So(err, convey.ShouldBeNil)
  57. convey.So(r, convey.ShouldNotBeNil)
  58. })
  59. }
  60. func TestDaoNeedInfoEdit(t *testing.T) {
  61. convey.Convey("NeedInfoEdit", t, func() {
  62. arg := &need.NEditReq{
  63. Content: "dsada",
  64. Title: "fsd",
  65. ID: 28,
  66. }
  67. err := d.NeedInfoEdit(arg)
  68. convey.So(err, convey.ShouldBeNil)
  69. })
  70. }
  71. func TestDaoNeedVerify(t *testing.T) {
  72. convey.Convey("NeedVerify", t, func() {
  73. v := &need.NVerifyReq{
  74. ID: 28,
  75. Status: 2,
  76. }
  77. err := d.NeedVerify(v)
  78. convey.So(err, convey.ShouldBeNil)
  79. })
  80. }
  81. func TestDaoLikeCountsAdd(t *testing.T) {
  82. convey.Convey("LikeCountsAdd", t, func() {
  83. v := &need.Likereq{
  84. ReqID: 148,
  85. LikeType: 1,
  86. }
  87. err := d.LikeCountsStats(v, 1, 0)
  88. convey.So(err, convey.ShouldBeNil)
  89. })
  90. }
  91. func TestDaoGetVoteInfo(t *testing.T) {
  92. convey.Convey("GetVoteInfo", t, func() {
  93. var (
  94. db = &gorm.DB{
  95. Error: nil,
  96. }
  97. v = &need.Likereq{
  98. ReqID: 148,
  99. LikeType: 1,
  100. }
  101. )
  102. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.DB), "Find", func(_ *gorm.DB, _ interface{}, _ ...interface{}) *gorm.DB {
  103. return db
  104. })
  105. defer guard.Unpatch()
  106. res, err := d.GetVoteInfo(v, "fengshanshan")
  107. t.Logf("res:%+v", res)
  108. convey.So(err, convey.ShouldBeNil)
  109. convey.So(res, convey.ShouldNotBeNil)
  110. })
  111. }
  112. func TestDaoUpdateVoteInfo(t *testing.T) {
  113. convey.Convey("UpdateVoteInfo", t, func() {
  114. v := &need.Likereq{
  115. ReqID: 30,
  116. LikeType: 2,
  117. }
  118. err := d.UpdateVoteInfo(v, "fengshanshan")
  119. convey.So(err, convey.ShouldBeNil)
  120. })
  121. }
  122. func TestDaoVoteInfoList(t *testing.T) {
  123. convey.Convey("VoteInfoList", t, func() {
  124. arg := &need.Likereq{
  125. ReqID: 11,
  126. LikeType: 2,
  127. }
  128. res, err := d.VoteInfoList(arg)
  129. t.Logf("res:%+v", res)
  130. convey.So(err, convey.ShouldBeNil)
  131. convey.So(res, convey.ShouldNotBeNil)
  132. })
  133. }
  134. func TestDaoVoteInfoCounts(t *testing.T) {
  135. convey.Convey("VoteInfoCounts", t, func() {
  136. arg := &need.Likereq{
  137. ReqID: 11,
  138. LikeType: 1,
  139. }
  140. count, err := d.VoteInfoCounts(arg)
  141. t.Logf("count:%+v", count)
  142. convey.So(err, convey.ShouldBeNil)
  143. convey.So(count, convey.ShouldNotBeNil)
  144. })
  145. }