feat(help-center): expose public article show
This commit is contained in:
@@ -245,6 +245,75 @@ func (s *ArticleHandlerTestSuite) TestPublicSearch_NotFoundForArchivedPortal() {
|
||||
assert.Equal(s.T(), http.StatusNotFound, w.Code)
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestPublicShow_ReturnsArticleBySlug() {
|
||||
portal := &model.Portal{AccountID: s.account.ID, Name: "Show Portal", Slug: "show-portal"}
|
||||
s.Require().NoError(s.db.Create(portal).Error)
|
||||
category := &model.Category{AccountID: s.account.ID, PortalID: portal.ID, Name: "Guides", Slug: "guides", Locale: "en"}
|
||||
s.Require().NoError(s.db.Create(category).Error)
|
||||
article := &model.Article{AccountID: s.account.ID, PortalID: portal.ID, CategoryID: &category.ID, Title: "Install", Slug: "install", Content: "Install content", Status: "published", Locale: "en"}
|
||||
s.Require().NoError(s.db.Create(article).Error)
|
||||
|
||||
r := gin.New()
|
||||
r.GET("/hc/:slug/articles/:article_slug", s.handler.PublicArticle)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/hc/show-portal/articles/install", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
var payload map[string]any
|
||||
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &payload))
|
||||
assert.Equal(s.T(), "install", payload["slug"])
|
||||
assert.Equal(s.T(), "Install content", payload["content"])
|
||||
assert.Equal(s.T(), "hc/show-portal/articles/install", payload["link"])
|
||||
assert.Equal(s.T(), "guides", payload["category"].(map[string]any)["slug"])
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestPublicMarkdown_ReturnsOnlyPublishedMarkdown() {
|
||||
portal := &model.Portal{AccountID: s.account.ID, Name: "Markdown Portal", Slug: "markdown-portal"}
|
||||
s.Require().NoError(s.db.Create(portal).Error)
|
||||
s.Require().NoError(s.db.Create(&model.Article{AccountID: s.account.ID, PortalID: portal.ID, Title: "Markdown", Slug: "markdown", Content: "# Raw markdown", Status: "published", Locale: "en"}).Error)
|
||||
s.Require().NoError(s.db.Create(&model.Article{AccountID: s.account.ID, PortalID: portal.ID, Title: "Draft", Slug: "markdown-draft", Content: "draft", Status: "draft", Locale: "en"}).Error)
|
||||
|
||||
r := gin.New()
|
||||
r.GET("/hc/:slug/articles/:article_slug", s.handler.PublicArticle)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/hc/markdown-portal/articles/markdown.md", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
assert.Equal(s.T(), "text/markdown; charset=utf-8", w.Header().Get("Content-Type"))
|
||||
assert.Equal(s.T(), "# Raw markdown", w.Body.String())
|
||||
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("GET", "/hc/markdown-portal/articles/markdown-draft.md", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusNotFound, w.Code)
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestPublicTrackingPixel_IncrementsPublishedArticleViews() {
|
||||
portal := &model.Portal{AccountID: s.account.ID, Name: "Pixel Portal", Slug: "pixel-portal"}
|
||||
s.Require().NoError(s.db.Create(portal).Error)
|
||||
article := &model.Article{AccountID: s.account.ID, PortalID: portal.ID, Title: "Pixel", Slug: "pixel", Content: "pixel", Status: "published", Locale: "en", Views: 3}
|
||||
s.Require().NoError(s.db.Create(article).Error)
|
||||
|
||||
r := gin.New()
|
||||
r.GET("/hc/:slug/articles/:article_slug", s.handler.PublicArticle)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/hc/pixel-portal/articles/pixel.png", nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
assert.Equal(s.T(), "image/png", w.Header().Get("Content-Type"))
|
||||
assert.NotEmpty(s.T(), w.Body.Bytes())
|
||||
var updated model.Article
|
||||
s.Require().NoError(s.db.First(&updated, article.ID).Error)
|
||||
assert.Equal(s.T(), 4, updated.Views)
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestStatusCounts_BadRequest_InvalidPortalID() {
|
||||
r := gin.New()
|
||||
r.GET("/api/v1/accounts/:account_id/portals/:portal_id/articles/status_counts", s.handler.StatusCounts)
|
||||
|
||||
Reference in New Issue
Block a user