draft_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. artmdl "go-common/app/interface/openplatform/article/model"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. var (
  9. cats = []*artmdl.Category{
  10. &artmdl.Category{Name: "游戏", ID: 1},
  11. &artmdl.Category{Name: "动漫", ID: 2},
  12. }
  13. draft = artmdl.Draft{
  14. Article: &artmdl.Article{
  15. Meta: &artmdl.Meta{
  16. Category: cats[0],
  17. Title: "隐藏于时区记忆中的,是希望还是绝望!",
  18. Summary: "说起日本校服,第一个浮现在我们脑海中的必然是那象征着青春阳光 蓝白色相称的水手服啦. 拉色短裙配上洁白的直袜",
  19. BannerURL: "http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg",
  20. TemplateID: 1,
  21. State: artmdl.StatePending,
  22. Author: &artmdl.Author{Mid: 8167601, Name: "爱蜜莉雅", Face: "http://i1.hdslb.com/bfs/face/5c6109964e78a84021299cdf71739e21cd7bc208.jpg"},
  23. Reprint: 0,
  24. ImageURLs: []string{"http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg", "http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg", "http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg"},
  25. PublishTime: 1495784507,
  26. Stats: &artmdl.Stats{Favorite: 100, Like: 10, View: 500, Dislike: 1, Share: 99},
  27. },
  28. Content: "test content",
  29. },
  30. Tags: []string{"tag1", "tag2"},
  31. }
  32. )
  33. func Test_Draft(t *testing.T) {
  34. var (
  35. err error
  36. aid int64
  37. c = context.TODO()
  38. )
  39. Convey("creation draft", t, WithService(func(s *Service) {
  40. Convey("AddArtDraft", func() {
  41. aid, err = s.AddArtDraft(c, &draft)
  42. t.Logf("aid: %d", aid)
  43. So(err, ShouldBeNil)
  44. So(aid, ShouldBeGreaterThan, 0)
  45. // t.Logf("result: %+v", aid)
  46. Convey("ArtDraft", func() {
  47. res, err := s.ArtDraft(c, aid, draft.Author.Mid)
  48. So(err, ShouldBeNil)
  49. So(res, ShouldNotBeEmpty)
  50. t.Logf("result: %+v", res.Title)
  51. // t.Logf("result: %+v", res.Content)
  52. Convey("DelArtDraft", func() {
  53. err = s.DelArtDraft(c, aid, draft.Author.Mid)
  54. So(err, ShouldBeNil)
  55. })
  56. })
  57. })
  58. Convey("UpperDrafts", func() {
  59. mid := art.Author.Mid
  60. pn := 1
  61. ps := 10
  62. res2, err := s.UpperDrafts(c, mid, pn, ps)
  63. So(err, ShouldBeNil)
  64. So(res2, ShouldNotBeNil)
  65. // fmt.Println("res2", res2.Page)
  66. // fmt.Println("res2", len(res2.Drafts))
  67. // fmt.Printf("meta %+v:", res2.Drafts[0].Meta)
  68. // fmt.Printf("category %+v", res2.Drafts[0].Category)
  69. })
  70. }))
  71. }