appeal_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. gock "gopkg.in/h2non/gock.v1"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoAddAppeal(t *testing.T) {
  9. convey.Convey("AddAppeal", t, func(convCtx convey.C) {
  10. var (
  11. c = context.Background()
  12. tid = int64(0)
  13. btid = int64(0)
  14. oid = int64(0)
  15. mid = int64(0)
  16. business = int64(0)
  17. content = ""
  18. reason = ""
  19. )
  20. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  21. defer gock.OffAll()
  22. httpMock("POST", d.addAppealURL).Reply(200).JSON(`{"code": 0}`)
  23. err := d.AddAppeal(c, tid, btid, oid, mid, business, content, reason)
  24. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  25. convCtx.So(err, convey.ShouldBeNil)
  26. })
  27. })
  28. })
  29. }
  30. func TestDaoAppealList(t *testing.T) {
  31. convey.Convey("AppealList", t, func(convCtx convey.C) {
  32. var (
  33. c = context.Background()
  34. mid = int64(0)
  35. business = int(0)
  36. )
  37. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  38. defer gock.OffAll()
  39. httpMock("GET", d.appealListURL).Reply(200).JSON(`{"code": 0,"data":[]}`)
  40. as, err := d.AppealList(c, mid, business)
  41. convCtx.Convey("Then err should be nil.as should not be nil.", func(convCtx convey.C) {
  42. convCtx.So(err, convey.ShouldBeNil)
  43. convCtx.So(as, convey.ShouldNotBeNil)
  44. })
  45. httpMock("GET", d.appealListURL).Reply(200).JSON(`{"code": 0}`)
  46. as, err = d.AppealList(c, mid, business)
  47. convCtx.Convey("Then err should be nil.as should be nil.", func(convCtx convey.C) {
  48. convCtx.So(err, convey.ShouldBeNil)
  49. convCtx.So(as, convey.ShouldBeNil)
  50. })
  51. })
  52. })
  53. }