This commit is contained in:
Umputun
2018-01-15 01:56:52 -06:00
parent f72a0c5ef7
commit 7ca6dd84bd
2 changed files with 14 additions and 10 deletions
+5 -7
View File
@@ -288,10 +288,10 @@ func (s *Server) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) {
userID := r.URL.Query().Get("user")
siteID := r.URL.Query().Get("site")
type resp struct {
resp := struct {
Comments []store.Comment
Count int
}
}{}
log.Printf("[DEBUG] get comments for userID %s, %s", userID, siteID)
@@ -300,11 +300,9 @@ func (s *Server) findUserCommentsCtrl(w http.ResponseWriter, r *http.Request) {
if e != nil {
return nil, e
}
rc := resp{
Comments: comments,
Count: count,
}
return encodeJSONWithHTML(rc)
resp.Comments, resp.Count = comments, count
return encodeJSONWithHTML(resp)
})
if err != nil {
+9 -3
View File
@@ -211,10 +211,16 @@ func TestServer_FindUserComments(t *testing.T) {
res, code := get(t, fmt.Sprintf("http://127.0.0.1:%d/api/v1/comments?site=radio-t&user=dev", port))
assert.Equal(t, 200, code)
comments := []store.Comment{}
err := json.Unmarshal([]byte(res), &comments)
resp := struct {
Comments []store.Comment
Count int
}{}
err := json.Unmarshal([]byte(res), &resp)
assert.Nil(t, err)
assert.Equal(t, 3, len(comments), "should have 3 comments")
assert.Equal(t, 3, len(resp.Comments), "should have 3 comments")
assert.Equal(t, 3, resp.Count, "should have 3 count")
}
func TestServer_UserInfo(t *testing.T) {