Create Note
This commit is contained in:
parent
18a593d2b1
commit
03f37c6d9e
|
@ -151,3 +151,34 @@ func TestEditorPostWithSession(t *testing.T) {
|
|||
assertions.AssertStatus(t, rr, http.StatusFound)
|
||||
assertions.AssertEqual(t, rr.Header().Get("Location"), post.FullUrl())
|
||||
}
|
||||
|
||||
func TestEditorPostWithSessionNote(t *testing.T) {
|
||||
repo, user := getSingleUserTestRepo()
|
||||
user.ResetPassword("testpassword")
|
||||
sessionId := user.CreateNewSession()
|
||||
|
||||
csrfToken := "test_csrf_token"
|
||||
|
||||
// Create Request and Response
|
||||
form := url.Values{}
|
||||
form.Add("type", "note")
|
||||
form.Add("content", "testcontent")
|
||||
form.Add("csrf_token", csrfToken)
|
||||
|
||||
req, err := http.NewRequest("POST", user.EditorUrl(), strings.NewReader(form.Encode()))
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Add("Content-Length", strconv.Itoa(len(form.Encode())))
|
||||
req.AddCookie(&http.Cookie{Name: "csrf_token", Value: csrfToken})
|
||||
req.AddCookie(&http.Cookie{Name: "session", Value: sessionId})
|
||||
assertions.AssertNoError(t, err, "Error creating request")
|
||||
rr := httptest.NewRecorder()
|
||||
router := main.SingleUserRouter(&repo)
|
||||
router.ServeHTTP(rr, req)
|
||||
|
||||
posts, _ := user.AllPosts()
|
||||
assertions.AssertEqual(t, len(posts), 1)
|
||||
post := posts[0]
|
||||
|
||||
assertions.AssertStatus(t, rr, http.StatusFound)
|
||||
assertions.AssertEqual(t, rr.Header().Get("Location"), post.FullUrl())
|
||||
}
|
||||
|
|
|
@ -13,11 +13,19 @@
|
|||
<input type="checkbox" name="draft" />
|
||||
<label for="draft">Draft</label>
|
||||
<br><br>
|
||||
<input type="submit" value="Create" />
|
||||
<input type="submit" value="Create Article" />
|
||||
</form>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Write Note</summary>
|
||||
TODO
|
||||
<form action="" method="post">
|
||||
<h2>Create New Note</h2>
|
||||
<input type="hidden" name="csrf_token" value="{{.CsrfToken}}">
|
||||
<input type="hidden" name="type" value="note">
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" placeholder="Content" rows="24"></textarea>
|
||||
<br><br>
|
||||
<input type="submit" value="Create Note" />
|
||||
</form>
|
||||
</details>
|
Loading…
Reference in New Issue