tests for drafts
This commit is contained in:
parent
4e28d403b5
commit
709f850a73
|
@ -96,3 +96,38 @@ func TestSingleUserPostMediaHandler(t *testing.T) {
|
|||
t.Error(rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHasNoDraftsInList(t *testing.T) {
|
||||
repo, user := getSingleUserTestRepo()
|
||||
post, _ := user.CreateNewPost("post-1")
|
||||
content := ""
|
||||
content += "---\n"
|
||||
content += "title: Articles September 2019\n"
|
||||
content += "author: h4kor\n"
|
||||
content += "type: post\n"
|
||||
content += "date: -001-11-30T00:00:00+00:00\n"
|
||||
content += "draft: true\n"
|
||||
content += "url: /?p=426\n"
|
||||
content += "categories:\n"
|
||||
content += " - Uncategorised\n"
|
||||
content += "\n"
|
||||
content += "---\n"
|
||||
content += "<https://nesslabs.com/time-anxiety>\n"
|
||||
|
||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
||||
|
||||
// Create Request and Response
|
||||
req, err := http.NewRequest("GET", "/", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rr := httptest.NewRecorder()
|
||||
router := main.SingleUserRouter(&repo)
|
||||
router.ServeHTTP(rr, req)
|
||||
|
||||
// Check if title is in the response body
|
||||
if strings.Contains(rr.Body.String(), "Articles September 2019") {
|
||||
t.Error("Articles September 2019 listed on index page. Got: ")
|
||||
t.Error(rr.Body.String())
|
||||
}
|
||||
}
|
||||
|
|
28
user_test.go
28
user_test.go
|
@ -168,6 +168,34 @@ func TestListUserPostsDoesNotIncludeDrafts(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestListUsersDraftsExcludedRealWorld(t *testing.T) {
|
||||
// Create a new user
|
||||
repo, _ := owl.CreateRepository(testRepoName())
|
||||
user, _ := repo.CreateUser(randomUserName())
|
||||
// Create a new post
|
||||
post, _ := user.CreateNewPost("testpost")
|
||||
content := ""
|
||||
content += "---\n"
|
||||
content += "title: Articles September 2019\n"
|
||||
content += "author: h4kor\n"
|
||||
content += "type: post\n"
|
||||
content += "date: -001-11-30T00:00:00+00:00\n"
|
||||
content += "draft: true\n"
|
||||
content += "url: /?p=426\n"
|
||||
content += "categories:\n"
|
||||
content += " - Uncategorised\n"
|
||||
content += "\n"
|
||||
content += "---\n"
|
||||
content += "<https://nesslabs.com/time-anxiety>\n"
|
||||
|
||||
os.WriteFile(post.ContentFile(), []byte(content), 0644)
|
||||
|
||||
posts, _ := user.Posts()
|
||||
if len(posts) != 0 {
|
||||
t.Error("Found draft post")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanLoadPost(t *testing.T) {
|
||||
user := getTestUser()
|
||||
// Create a new post
|
||||
|
|
Loading…
Reference in New Issue