2022-08-03 14:55:48 +00:00
|
|
|
package owl_test
|
2022-07-21 17:44:07 +00:00
|
|
|
|
2022-08-01 17:50:29 +00:00
|
|
|
import (
|
2022-08-20 20:35:51 +00:00
|
|
|
"os"
|
2022-08-01 17:50:29 +00:00
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
)
|
2022-07-21 17:44:07 +00:00
|
|
|
|
|
|
|
func TestCanGetPostTitle(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
result := post.Title()
|
|
|
|
if result != "testpost" {
|
|
|
|
t.Error("Wrong Title. Got: " + result)
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 17:50:29 +00:00
|
|
|
|
|
|
|
func TestMediaDir(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
result := post.MediaDir()
|
|
|
|
if result != path.Join(post.Dir(), "media") {
|
|
|
|
t.Error("Wrong MediaDir. Got: " + result)
|
|
|
|
}
|
|
|
|
}
|
2022-08-03 17:41:13 +00:00
|
|
|
|
|
|
|
func TestPostUrlPath(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/"
|
|
|
|
if !(post.UrlPath() == expected) {
|
|
|
|
t.Error("Wrong url path")
|
|
|
|
t.Error("Expected: " + expected)
|
|
|
|
t.Error(" Got: " + post.UrlPath())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-13 16:47:27 +00:00
|
|
|
func TestPostFullUrl(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
expected := "http://localhost:8080/user/" + user.Name() + "/posts/" + post.Id() + "/"
|
|
|
|
if !(post.FullUrl() == expected) {
|
|
|
|
t.Error("Wrong url path")
|
|
|
|
t.Error("Expected: " + expected)
|
|
|
|
t.Error(" Got: " + post.FullUrl())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 17:41:13 +00:00
|
|
|
func TestPostUrlMediaPath(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/media/data.png"
|
|
|
|
if !(post.UrlMediaPath("data.png") == expected) {
|
|
|
|
t.Error("Wrong url path")
|
|
|
|
t.Error("Expected: " + expected)
|
|
|
|
t.Error(" Got: " + post.UrlPath())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostUrlMediaPathWithSubDir(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
expected := "/user/" + user.Name() + "/posts/" + post.Id() + "/media/foo/data.png"
|
|
|
|
if !(post.UrlMediaPath("foo/data.png") == expected) {
|
|
|
|
t.Error("Wrong url path")
|
|
|
|
t.Error("Expected: " + expected)
|
|
|
|
t.Error(" Got: " + post.UrlPath())
|
|
|
|
}
|
|
|
|
}
|
2022-08-20 20:35:51 +00:00
|
|
|
|
|
|
|
func TestDraftInMetaData(t *testing.T) {
|
|
|
|
user := getTestUser()
|
|
|
|
post, _ := user.CreateNewPost("testpost")
|
|
|
|
content := "---\n"
|
|
|
|
content += "title: test\n"
|
|
|
|
content += "draft: true\n"
|
|
|
|
content += "---\n"
|
|
|
|
content += "\n"
|
|
|
|
content += "Write your post here.\n"
|
|
|
|
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
|
|
|
_, meta := post.MarkdownData()
|
|
|
|
if !meta.Draft {
|
|
|
|
t.Error("Draft should be true")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|