feat(help-center): expose public sitemap

This commit is contained in:
2026-06-06 08:26:10 +08:00
parent 8edfcda947
commit efceb22b4c
8 changed files with 92 additions and 8 deletions
@@ -191,6 +191,29 @@ func (s *PortalHandlerTestSuite) TestPublicGet_NotFoundForArchivedPortal() {
assert.Equal(s.T(), http.StatusNotFound, w.Code)
}
func (s *PortalHandlerTestSuite) TestPublicSitemap_ReturnsPublishedArticleURLs() {
portal := &model.Portal{AccountID: s.account.ID, Name: "Sitemap", Slug: "sitemap", CustomDomain: "help.example.com"}
s.Require().NoError(s.db.Create(portal).Error)
s.Require().NoError(s.db.Create(&model.Article{AccountID: s.account.ID, PortalID: portal.ID, Title: "Published", Slug: "published", Status: "published", Locale: "en"}).Error)
s.Require().NoError(s.db.Create(&model.Article{AccountID: s.account.ID, PortalID: portal.ID, Title: "Draft", Slug: "draft", Status: "draft", Locale: "en"}).Error)
r := gin.New()
r.GET("/hc/:slug/sitemap.xml", s.handler.PublicSitemap)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/hc/sitemap/sitemap.xml", nil)
r.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
assert.Equal(s.T(), "application/xml; charset=utf-8", w.Header().Get("Content-Type"))
body := w.Body.String()
assert.Contains(s.T(), body, `<?xml version="1.0" encoding="UTF-8"?>`)
assert.Contains(s.T(), body, `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`)
assert.Contains(s.T(), body, `<loc>https://help.example.com/hc/sitemap/articles/published</loc>`)
assert.Contains(s.T(), body, `<lastmod>`)
assert.NotContains(s.T(), body, "draft")
}
func (s *PortalHandlerTestSuite) TestUpdate_Success() {
portal := &model.Portal{AccountID: s.account.ID, Name: "update-portal", Slug: "update-slug"}
s.Require().NoError(s.db.Create(portal).Error)