2022-09-05 18:34:24 +00:00
|
|
|
package web_test
|
2022-08-20 20:46:52 +00:00
|
|
|
|
|
|
|
import (
|
2022-09-05 18:50:46 +00:00
|
|
|
"h4kor/owl-blogs"
|
2022-09-05 18:34:24 +00:00
|
|
|
main "h4kor/owl-blogs/cmd/owl/web"
|
2022-08-20 20:46:52 +00:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPostHandlerReturns404OnDrafts(t *testing.T) {
|
2022-09-05 18:50:46 +00:00
|
|
|
repo := getTestRepo(owl.RepoConfig{})
|
2022-08-20 20:46:52 +00:00
|
|
|
user, _ := repo.CreateUser("test-1")
|
2022-10-13 18:33:00 +00:00
|
|
|
post, _ := user.CreateNewPost("post-1", false)
|
2022-08-20 20:46:52 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
// Create Request and Response
|
|
|
|
req, err := http.NewRequest("GET", post.UrlPath(), nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
router := main.Router(&repo)
|
|
|
|
router.ServeHTTP(rr, req)
|
|
|
|
|
|
|
|
// Check the status code is what we expect.
|
|
|
|
if status := rr.Code; status != http.StatusNotFound {
|
|
|
|
t.Errorf("handler returned wrong status code: got %v want %v",
|
|
|
|
status, http.StatusNotFound)
|
|
|
|
}
|
|
|
|
}
|