creation_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package dao
  2. import (
  3. "testing"
  4. "go-common/app/interface/openplatform/article/model"
  5. . "github.com/smartystreets/goconvey/convey"
  6. )
  7. func Test_Articles(t *testing.T) {
  8. var (
  9. c = ctx()
  10. aid int64
  11. art = model.Article{
  12. Meta: &model.Meta{
  13. ID: 0,
  14. Title: "1",
  15. Summary: "2",
  16. BannerURL: "https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg",
  17. TemplateID: 1,
  18. State: 0,
  19. Category: &model.Category{ID: 1},
  20. Author: &model.Author{Mid: 123},
  21. Reprint: 0,
  22. ImageURLs: []string{"https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg", "https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg", "https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg"},
  23. OriginImageURLs: []string{"https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg", "https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg", "https://i0.hdslb.com/bfs/archive/b5727f244d5c7a34c1c0e78f49765d09ff30c129.jpg"},
  24. },
  25. Content: "content",
  26. }
  27. )
  28. Convey("creation article operations", t, func() {
  29. Convey("add article", func() {
  30. tx, err := d.BeginTran(c)
  31. So(err, ShouldBeNil)
  32. var meta = &model.Meta{}
  33. *meta = *art.Meta
  34. aid, err = d.TxAddArticleMeta(c, tx, meta, 0)
  35. So(err, ShouldBeNil)
  36. err = d.TxAddArticleContent(c, tx, aid, art.Content, []string{})
  37. So(err, ShouldBeNil)
  38. err = tx.Commit()
  39. So(err, ShouldBeNil)
  40. Convey("get article", func() {
  41. res, err1 := d.CreationArticleMeta(c, aid)
  42. So(err1, ShouldBeNil)
  43. art.ID = aid
  44. res.Ctime = 0
  45. So(res, ShouldResemble, art.Meta)
  46. content, err2 := d.CreationArticleContent(c, aid)
  47. So(err2, ShouldBeNil)
  48. So(content, ShouldEqual, art.Content)
  49. })
  50. Convey("list should not be empty", func() {
  51. res, err1 := d.UpperArticlesMeta(c, art.Author.Mid, 0, 1)
  52. So(err1, ShouldBeNil)
  53. So(res, ShouldNotBeEmpty)
  54. })
  55. Convey("count should > 0", func() {
  56. var cnt = &model.CreationArtsType{}
  57. cnt, err = d.UpperArticlesTypeCount(c, 8167601)
  58. So(err, ShouldBeNil)
  59. So(cnt.All, ShouldBeGreaterThan, 0)
  60. })
  61. Convey("update state", func() {
  62. err = d.UpdateArticleState(c, aid, model.StateLock)
  63. So(err, ShouldBeNil)
  64. res3, err := d.CreationArticleMeta(c, aid)
  65. So(err, ShouldBeNil)
  66. So(res3.State, ShouldEqual, model.StateLock)
  67. })
  68. Convey("delete article", func() {
  69. tx, err := d.BeginTran(c)
  70. err = d.TxDeleteArticleContent(c, tx, aid)
  71. So(err, ShouldBeNil)
  72. err = d.TxDeleteArticleMeta(c, tx, aid)
  73. So(err, ShouldBeNil)
  74. err = tx.Commit()
  75. Convey("article not be present", func() {
  76. res, err := d.CreationArticleMeta(c, aid)
  77. So(err, ShouldBeNil)
  78. So(res, ShouldBeNil)
  79. content, err := d.CreationArticleContent(c, aid)
  80. So(err, ShouldBeNil)
  81. So(content, ShouldBeEmpty)
  82. })
  83. })
  84. Convey("update article", func() {
  85. art := model.Article{
  86. Meta: &model.Meta{
  87. ID: aid,
  88. Title: "new",
  89. Summary: "new",
  90. BannerURL: "https://i0.hdslb.com/bfs/archive/1.jpg",
  91. TemplateID: 4,
  92. State: 2,
  93. Category: &model.Category{ID: 2},
  94. Author: &model.Author{Mid: 123},
  95. Reprint: 0,
  96. ImageURLs: []string{"https://i0.hdslb.com/bfs/archive/2.jpg"},
  97. OriginImageURLs: []string{"https://i0.hdslb.com/bfs/archive/3.jpg"},
  98. },
  99. Content: "new",
  100. }
  101. tx, err := d.BeginTran(c)
  102. var meta = &model.Meta{}
  103. *meta = *art.Meta
  104. err = d.TxUpdateArticleMeta(c, tx, meta)
  105. So(err, ShouldBeNil)
  106. err = d.TxUpdateArticleContent(c, tx, aid, art.Content, []string{})
  107. So(err, ShouldBeNil)
  108. err = tx.Commit()
  109. So(err, ShouldBeNil)
  110. Convey("article should be updated", func() {
  111. res, err := d.CreationArticleMeta(c, aid)
  112. So(err, ShouldBeNil)
  113. art.Ctime = res.Ctime // ignore ctime
  114. So(res, ShouldResemble, art.Meta)
  115. content, err := d.CreationArticleContent(c, aid)
  116. So(err, ShouldBeNil)
  117. So(content, ShouldEqual, art.Content)
  118. })
  119. })
  120. })
  121. })
  122. }