add delete test
This commit is contained in:
+2
-2
@@ -211,7 +211,7 @@ func (s *Server) deleteCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
locator := store.Locator{SiteID: r.URL.Query().Get("site"), URL: r.URL.Query().Get("url")}
|
||||
err := s.DataService.Delete(locator, id)
|
||||
if err != nil {
|
||||
common.SendErrorJSON(w, r, http.StatusInternalServerError, err, "can't delete comment")
|
||||
common.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't delete comment")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func (s *Server) commentByIDCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
comment, err := s.DataService.Get(store.Locator{SiteID: siteID, URL: url}, id)
|
||||
if err != nil {
|
||||
common.SendErrorJSON(w, r, http.StatusInternalServerError, err, "can't get comment by id")
|
||||
common.SendErrorJSON(w, r, http.StatusBadRequest, err, "can't get comment by id")
|
||||
return
|
||||
}
|
||||
render.Status(r, http.StatusOK)
|
||||
|
||||
@@ -215,6 +215,31 @@ func TestServer_FindUserComments(t *testing.T) {
|
||||
assert.Equal(t, 3, len(comments), "should have 3 comments")
|
||||
}
|
||||
|
||||
func TestServer_Delete(t *testing.T) {
|
||||
srv, port := prep(t)
|
||||
assert.NotNil(t, srv)
|
||||
defer cleanup(srv)
|
||||
|
||||
c1 := store.Comment{Text: "test test #1",
|
||||
Locator: store.Locator{SiteID: "radio-t", URL: "https://radio-t.com/blah"}}
|
||||
c2 := store.Comment{Text: "test test #2", ParentID: "p1",
|
||||
Locator: store.Locator{SiteID: "radio-t", URL: "https://radio-t.com/blah"}}
|
||||
|
||||
id1 := addComment(t, c1, port)
|
||||
addComment(t, c2, port)
|
||||
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest(http.MethodDelete,
|
||||
fmt.Sprintf("http://127.0.0.1:%d/api/v1/comment/%s?site=radio-t&url=https://radio-t.com/blah1", port, id1),
|
||||
nil)
|
||||
assert.Nil(t, err)
|
||||
_, err = client.Do(req)
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, code := get(t, fmt.Sprintf("http://127.0.0.1:%d/api/v1/id/%s?site=radio-t&url=https://radio-t.com/blah1", port, id1))
|
||||
assert.Equal(t, 400, code)
|
||||
}
|
||||
|
||||
func prep(t *testing.T) (srv *Server, port int) {
|
||||
dataStore, err := store.NewBoltDB(store.BoltSite{FileName: testDb, SiteID: "radio-t"})
|
||||
assert.Nil(t, err)
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ func (b *BoltDB) SetBlock(siteID string, userID string, status bool) error {
|
||||
|
||||
switch status {
|
||||
case true:
|
||||
if e := bucket.Put([]byte(userID), []byte(time.Now().Format(time.RFC3339))); e != nil {
|
||||
if e := bucket.Put([]byte(userID), []byte(time.Now().Format(time.RFC3339Nano))); e != nil {
|
||||
return errors.Wrapf(e, "failed to put %s to %s", userID, blocksBucketName)
|
||||
}
|
||||
case false:
|
||||
|
||||
Reference in New Issue
Block a user