fix user view in find for deleted comments #972

This commit is contained in:
Umputun
2021-05-05 01:15:03 -05:00
parent d3bd966df8
commit d361564815
2 changed files with 20 additions and 4 deletions
+7 -3
View File
@@ -386,16 +386,20 @@ func (s *public) robotsCtrl(w http.ResponseWriter, r *http.Request) {
func (s *public) applyView(comments []store.Comment, view string) []store.Comment {
if strings.EqualFold(view, "user") {
projection := make([]store.Comment, len(comments))
for i, c := range comments {
projection := make([]store.Comment, 0, len(comments))
for _, c := range comments {
if c.Deleted {
continue
}
p := store.Comment{
ID: c.ID,
User: c.User,
}
projection[i] = p
projection = append(projection, p)
}
return projection
}
return comments
}
+13 -1
View File
@@ -232,7 +232,7 @@ func TestRest_FindReadOnly(t *testing.T) {
}
func TestRest_FindUserView(t *testing.T) {
ts, _, teardown := startupT(t)
ts, srv, teardown := startupT(t)
defer teardown()
res, code := get(t, ts.URL+"/api/v1/find?site=remark42&url=https://radio-t.com/blah1&view=user")
@@ -265,6 +265,18 @@ func TestRest_FindUserView(t *testing.T) {
assert.Equal(t, "dev", comments.Comments[1].User.ID)
assert.Equal(t, "", comments.Comments[0].Text)
assert.Equal(t, "", comments.Comments[1].Text)
err = srv.DataService.Delete(store.Locator{SiteID: "remark42", URL: "https://radio-t.com/blah1"}, id1, store.SoftDelete)
assert.NoError(t, err)
srv.Cache.Flush(cache.FlusherRequest{})
res, code = get(t, ts.URL+"/api/v1/find?site=remark42&url=https://radio-t.com/blah1&sort=+time&view=user")
assert.Equal(t, 200, code)
comments = commentsWithInfo{}
err = json.Unmarshal([]byte(res), &comments)
assert.NoError(t, err)
require.Equal(t, 1, len(comments.Comments), "1 comment left")
assert.Equal(t, id2, comments.Comments[0].ID)
}
func TestRest_Last(t *testing.T) {