need_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package http
  2. import (
  3. "fmt"
  4. "net/url"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. "go-common/app/admin/main/apm/model/need"
  8. )
  9. var (
  10. _nadduri = "%s/x/admin/apm/need/add"
  11. _nlisturi = "%s/x/admin/apm/need/list"
  12. _nedituri = "%s/x/admin/apm/need/edit"
  13. _nverifyuri = "%s/x/admin/apm/need/verify"
  14. _nthumsupuri = "%s/x/admin/apm/need/thumbsup"
  15. _nvotelisturi = "%s/x/admin/apm/need/vote/list"
  16. )
  17. func TestNeedList(t *testing.T) {
  18. convey.Convey("", t, func() {
  19. params := url.Values{}
  20. params.Set("pn", "1")
  21. params.Set("ps", "5")
  22. res := new(struct {
  23. Code int `json:"code"`
  24. Message string `json:"message"`
  25. Data *need.NListResp `json:"data"`
  26. })
  27. _ = requests("GET", fmt.Sprintf(_nlisturi, _domain), "", params, &res)
  28. t.Logf("res%+v", res.Data)
  29. })
  30. }
  31. func TestNeedAdd(t *testing.T) {
  32. convey.Convey("TestNeedAdd normal", t, func() {
  33. params := url.Values{}
  34. params.Set("title", "dsds")
  35. params.Set("content", "sds")
  36. res := Response{}
  37. _ = requests("POST", fmt.Sprintf(_nadduri, _domain), "", params, &res)
  38. t.Logf("res%+v", res)
  39. convey.So(res.Code, convey.ShouldEqual, 0)
  40. })
  41. //convey.Convey("TestNeedAdd params error", t, func() {
  42. // // params := url.Values{}
  43. // // params.Set("title", "提一个小需求阿斯加德卡萨")
  44. // // res := Response{}
  45. // // _ = requests("POST", fmt.Sprintf(_nadduri, _domain), "", params, &res)
  46. // // t.Logf("res%+v", res)
  47. // // convey.So(res.Code, convey.ShouldEqual, -400)
  48. // //})
  49. }
  50. func TestNeedEdit(t *testing.T) {
  51. convey.Convey("TestNeedEdit", t, func() {
  52. params := url.Values{}
  53. params.Set("title", "fss")
  54. params.Set("content", "fss")
  55. params.Set("id", "26")
  56. res := Response{}
  57. _ = requests("POST", fmt.Sprintf(_nedituri, _domain), "", params, &res)
  58. convey.So(res.Code, convey.ShouldEqual, 0)
  59. })
  60. }
  61. func TestNeedVerify(t *testing.T) {
  62. convey.Convey("TestNeedVerify", t, func() {
  63. params := url.Values{}
  64. params.Set("status", "2")
  65. params.Set("id", "28")
  66. res := Response{}
  67. _ = requests("POST", fmt.Sprintf(_nverifyuri, _domain), "", params, &res)
  68. convey.So(res.Code, convey.ShouldEqual, 70018)
  69. })
  70. }
  71. func TestNeedThumbsUp(t *testing.T) {
  72. convey.Convey("TestNeedThumbsUp", t, func() {
  73. params := url.Values{}
  74. params.Set("req_id", "29")
  75. params.Set("like_type", "1")
  76. res := Response{}
  77. _ = requests("POST", fmt.Sprintf(_nthumsupuri, _domain), "", params, &res)
  78. convey.So(res.Code, convey.ShouldEqual, 0)
  79. })
  80. }
  81. func TestVoteList(t *testing.T) {
  82. convey.Convey("TestVoteList", t, func() {
  83. params := url.Values{}
  84. params.Set("req_id", "11")
  85. params.Set("like_type", "1")
  86. res := new(struct {
  87. Code int `json:"code"`
  88. Message string `json:"message"`
  89. Data *need.VoteListResp `json:"data"`
  90. })
  91. _ = requests("GET", fmt.Sprintf(_nvotelisturi, _domain), "", params, &res)
  92. t.Logf("res%+v", res)
  93. })
  94. }