creation_test.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. artmdl "go-common/app/interface/openplatform/article/model"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. categories = []*artmdl.Category{
  12. &artmdl.Category{Name: "游戏", ID: 1},
  13. &artmdl.Category{Name: "动漫", ID: 2},
  14. }
  15. art = artmdl.Article{
  16. Meta: &artmdl.Meta{
  17. Category: categories[0],
  18. Title: "隐藏于时区记忆中的,是希望还是绝望!",
  19. Summary: "说起日本校服,第一个浮现在我们脑海中的必然是那象征着青春阳光 蓝白色相称的水手服啦. 拉色短裙配上洁白的直袜",
  20. BannerURL: "http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg",
  21. TemplateID: 4,
  22. State: artmdl.StatePending,
  23. Author: &artmdl.Author{Mid: 8167601, Name: "爱蜜莉雅", Face: "http://i1.hdslb.com/bfs/face/5c6109964e78a84021299cdf71739e21cd7bc208.jpg"},
  24. Reprint: 0,
  25. ImageURLs: []string{"http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg"},
  26. OriginImageURLs: []string{"http://i2.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg"},
  27. PublishTime: 1495784507,
  28. Stats: &artmdl.Stats{Favorite: 100, Like: 10, View: 500, Dislike: 1, Share: 99},
  29. Attributes: 2,
  30. Words: 555,
  31. Dynamic: "dynamic",
  32. Tags: []*artmdl.Tag{&artmdl.Tag{Name: "tag"}},
  33. },
  34. Content: "海奉是一个风景优美的地方,但并不在沿海。数量众多的旅行家笔记显示,海奉是一片死火山群。那里坐落着世界上最高的山峰——奈文摩尔峰,峰顶终年积雪。其它沉睡的火山围坐在他的周围,高低不同,错落有致。火山口往往积蓄湖水,形成湖泊,当地人称之为“镜湖”。每到雨季,经过连续的降雨,湖中的水便会溢出,从山顶冲下,形成“水山爆发”的情景。山脚下是海奉人的村落,那里的房子全部以木头搭建,巧妙的避开河水的必经之路。海奉人以木工闻名,无论是精巧的木头机械还是美丽的木雕都不在话下。此外,每一个海奉人都戴着一枚木制的十字架,那是由海奉独有的铁木制成,绝不出售给外人,因而成为海奉人的标志。但是故事并不发生在海奉,这些描写仅是因为主角是海奉人。船还在航行。天色昏暗,雨从来没有停过。船舱紧闭,窗口透出一丝微弱的光。“您是海奉人吗?”山本真奈美借着微弱的灯光盯着他的十字架。",
  35. }
  36. )
  37. func Test_Creation(t *testing.T) {
  38. var (
  39. err error
  40. aid int64
  41. c = context.TODO()
  42. )
  43. Convey("creation article", t, WithService(func(s *Service) {
  44. res := &artmdl.Article{
  45. Meta: &artmdl.Meta{
  46. Title: "title",
  47. Category: &artmdl.Category{ID: 39},
  48. Author: &artmdl.Author{Mid: art.Author.Mid},
  49. Tags: []*artmdl.Tag{&artmdl.Tag{Name: "tag"}},
  50. TemplateID: 1,
  51. },
  52. }
  53. Convey("AddArticle", func() {
  54. art.Title = fmt.Sprintf("隐藏于时区记忆中的,是希望还是绝望!_%v", time.Now().UnixNano())
  55. aid, err = s.AddArticle(c, &art, 0, 0, "")
  56. So(err, ShouldBeNil)
  57. So(aid, ShouldBeGreaterThan, 0)
  58. err = s.SetStat(c, aid, &artmdl.Stats{
  59. View: 10,
  60. Reply: 9,
  61. Like: 5,
  62. })
  63. So(err, ShouldBeNil)
  64. Convey("CreationArticle", func() {
  65. res, err = s.CreationArticle(c, aid, art.Author.Mid)
  66. So(err, ShouldBeNil)
  67. So(res, ShouldNotBeEmpty)
  68. })
  69. Convey("UpdateArticleDB", func() {
  70. art2 := &artmdl.Article{Meta: &artmdl.Meta{}}
  71. *art2 = art
  72. art2.ID = aid
  73. art2.ImageURLs = []string{"http://i2.hdslb.com/bfs/archive/00.jpg"}
  74. art2.OriginImageURLs = []string{"http://i2.hdslb.com/bfs/archive/01.jpg"}
  75. art2.Dynamic = "update 2"
  76. err = s.updateArticleDB(c, art2)
  77. So(err, ShouldBeNil)
  78. res, err = s.CreationArticle(c, art2.ID, art2.Author.Mid)
  79. So(err, ShouldBeNil)
  80. So(res.Dynamic, ShouldEqual, art2.Dynamic)
  81. So(res.ImageURLs, ShouldResemble, []string{"https://i0.hdslb.com/bfs/archive/00.jpg"})
  82. So(res.OriginImageURLs, ShouldResemble, []string{"https://i0.hdslb.com/bfs/archive/01.jpg"})
  83. })
  84. Convey("UpdateArticle", func() {
  85. // res.Content = art.Content
  86. // res.ID = aid
  87. // err = s.UpdateArticle(c, res, 0, 0, "")
  88. // So(err, ShouldBeNil)
  89. err = s.dao.UpdateArticleState(c, aid, artmdl.StateOpen)
  90. So(err, ShouldBeNil)
  91. Convey("DelArticle", func() {
  92. err = s.DelArticle(c, aid, art.Author.Mid)
  93. So(err, ShouldBeNil)
  94. })
  95. })
  96. })
  97. Convey("CreationUpperArticlesMeta", func() {
  98. mid := art.Author.Mid
  99. group := 0
  100. category := 1
  101. sortType := 1
  102. pn := 1
  103. ps := 10
  104. res2, err := s.CreationUpperArticlesMeta(c, mid, group, category, sortType, pn, ps, "")
  105. So(err, ShouldBeNil)
  106. So(res2, ShouldNotBeNil)
  107. })
  108. }))
  109. }