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-11-02 21:02:49 +00:00
|
|
|
"h4kor/owl-blogs/priv/assertions"
|
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)
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertNoError(t, err, "Error creating request")
|
2022-08-20 20:46:52 +00:00
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
router := main.Router(&repo)
|
|
|
|
router.ServeHTTP(rr, req)
|
|
|
|
|
2022-11-02 21:02:49 +00:00
|
|
|
assertions.AssertStatus(t, rr, http.StatusNotFound)
|
2022-08-20 20:46:52 +00:00
|
|
|
}
|