owl-blogs/rss_test.go

69 lines
2.0 KiB
Go
Raw Normal View History

2022-08-13 13:32:26 +00:00
package owl_test
import (
"h4kor/owl-blogs"
2022-11-06 13:17:14 +00:00
"h4kor/owl-blogs/test/assertions"
2022-08-13 16:47:27 +00:00
"os"
2022-08-13 13:32:26 +00:00
"testing"
)
func TestRenderRSSFeedMeta(t *testing.T) {
user := getTestUser()
user.SetConfig(owl.UserConfig{
Title: "Test Title",
SubTitle: "Test SubTitle",
})
res, err := owl.RenderRSSFeed(user)
assertions.AssertNoError(t, err, "Error rendering RSS feed")
assertions.AssertContains(t, res, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
assertions.AssertContains(t, res, "<rss version=\"2.0\">")
2022-08-13 13:32:26 +00:00
}
func TestRenderRSSFeedUserData(t *testing.T) {
user := getTestUser()
user.SetConfig(owl.UserConfig{
Title: "Test Title",
SubTitle: "Test SubTitle",
})
res, err := owl.RenderRSSFeed(user)
assertions.AssertNoError(t, err, "Error rendering RSS feed")
assertions.AssertContains(t, res, "Test Title")
assertions.AssertContains(t, res, "Test SubTitle")
assertions.AssertContains(t, res, "http://localhost:8080/user/")
2022-08-13 13:32:26 +00:00
}
2022-08-13 16:47:27 +00:00
func TestRenderRSSFeedPostData(t *testing.T) {
user := getTestUser()
2022-10-13 18:33:00 +00:00
post, _ := user.CreateNewPost("testpost", false)
2022-08-13 16:47:27 +00:00
content := "---\n"
content += "title: Test Post\n"
content += "date: 2015-01-01\n"
content += "---\n"
content += "This is a test"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
res, err := owl.RenderRSSFeed(user)
assertions.AssertNoError(t, err, "Error rendering RSS feed")
assertions.AssertContains(t, res, "Test Post")
assertions.AssertContains(t, res, post.FullUrl())
assertions.AssertContains(t, res, "Thu, 01 Jan 2015 00:00:00 +0000")
2022-08-13 16:47:27 +00:00
}
func TestRenderRSSFeedPostDataWithoutDate(t *testing.T) {
user := getTestUser()
2022-10-13 18:33:00 +00:00
post, _ := user.CreateNewPost("testpost", false)
2022-08-13 16:47:27 +00:00
content := "---\n"
content += "title: Test Post\n"
content += "---\n"
content += "This is a test"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
res, err := owl.RenderRSSFeed(user)
assertions.AssertNoError(t, err, "Error rendering RSS feed")
assertions.AssertContains(t, res, "Test Post")
assertions.AssertContains(t, res, post.FullUrl())
2022-08-13 16:47:27 +00:00
}