saving notice without content, title should not work
This commit is contained in:
parent
362e40e473
commit
83920aa646
|
@ -143,6 +143,11 @@ func (h noticeHandler) save(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
n.Title = req.FormValue("title")
|
||||
if n.Title == "" {
|
||||
err = weberrors.ErrBadRequest{Where: "title", Details: fmt.Errorf("title can't be empty")}
|
||||
h.r.Error(rw, req, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: validate languages properly
|
||||
n.Language = req.FormValue("language")
|
||||
|
@ -153,6 +158,11 @@ func (h noticeHandler) save(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
n.Content = req.FormValue("content")
|
||||
if n.Content == "" {
|
||||
err = weberrors.ErrBadRequest{Where: "content", Details: fmt.Errorf("content can't be empty")}
|
||||
h.r.Error(rw, req, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
// https://github.com/russross/blackfriday/issues/575
|
||||
n.Content = strings.Replace(n.Content, "\r\n", "\n", -1)
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ func TestNoticeSaveRefusesIncomplete(t *testing.T) {
|
|||
urlTo := web.NewURLTo(ts.Router)
|
||||
|
||||
// notice values we are selectively omitting in the tests below
|
||||
// ID: 1,
|
||||
// Title: "News",
|
||||
// Content: "Breaking News: This Room Has News",
|
||||
// Language: "en-GB",
|
||||
id := []string{"1"}
|
||||
title := []string{"SSB Breaking News: This Test Is Great"}
|
||||
content := []string{"Absolutely Thrilling Content"}
|
||||
language := []string{"pt"}
|
||||
|
||||
/* save without id */
|
||||
u := urlTo(router.AdminNoticeSave)
|
||||
|
@ -32,8 +32,18 @@ func TestNoticeSaveRefusesIncomplete(t *testing.T) {
|
|||
resp := ts.Client.PostForm(u.String(), emptyParams)
|
||||
a.Equal(http.StatusInternalServerError, resp.Code, "saving without id should not work")
|
||||
|
||||
/* save without title */
|
||||
formValues := url.Values{"id": id, "content": content, "language": language}
|
||||
resp = ts.Client.PostForm(u.String(), formValues)
|
||||
a.Equal(http.StatusInternalServerError, resp.Code, "saving without title should not work")
|
||||
|
||||
/* save without content */
|
||||
formValues = url.Values{"id": id, "title": title, "language": language}
|
||||
resp = ts.Client.PostForm(u.String(), formValues)
|
||||
a.Equal(http.StatusInternalServerError, resp.Code, "saving without content should not work")
|
||||
|
||||
/* save without language */
|
||||
formValues := url.Values{"id": []string{"1"}, "title": []string{"Fake Title"}, "content": []string{"Thrilling Content"}}
|
||||
formValues = url.Values{"id": id, "title": title, "content": content}
|
||||
resp = ts.Client.PostForm(u.String(), formValues)
|
||||
a.Equal(http.StatusInternalServerError, resp.Code, "saving without language should not work")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue