api_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package data
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestDataTags(t *testing.T) {
  9. convey.Convey("Tags", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. mid = int64(0)
  13. tid = uint16(0)
  14. title = ""
  15. filename = ""
  16. desc = ""
  17. cover = ""
  18. )
  19. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  20. defer gock.OffAll()
  21. httpMock("GET", d.tagURI).Reply(200).BodyString(`
  22. {
  23. "code":0,
  24. "data": {"tags" : ["1"]}
  25. }`)
  26. no, err := d.Tags(c, mid, tid, title, filename, desc, cover)
  27. ctx.Convey("Then err should be nil.no should not be nil.", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. ctx.So(no, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDataTagsWithChecked(t *testing.T) {
  35. convey.Convey("TagsWithChecked", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. mid = int64(0)
  39. tid = uint16(0)
  40. title = ""
  41. filename = ""
  42. desc = ""
  43. cover = ""
  44. tagFrom = int8(0)
  45. )
  46. defer gock.OffAll()
  47. httpMock("GET", d.tagV2URI).Reply(200).BodyString(`
  48. {
  49. "code":0,
  50. "data": {"tags" : []}
  51. }`)
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. no, err := d.TagsWithChecked(c, mid, tid, title, filename, desc, cover, tagFrom)
  54. ctx.Convey("Then err should be nil.no should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(no, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestDataRecommendCovers(t *testing.T) {
  62. convey.Convey("RecommendCovers", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. mid = int64(0)
  66. fns = []string{}
  67. )
  68. defer gock.OffAll()
  69. httpMock("GET", d.coverBFSURI).Reply(200).BodyString(`
  70. {
  71. "code":0,
  72. "data": ["1"]
  73. }`)
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. cvs, err := d.RecommendCovers(c, mid, fns)
  76. ctx.Convey("Then err should be nil.cvs should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. ctx.So(cvs, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }