Skip to content

Commit

Permalink
make sure last returns [] list #262
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Jan 26, 2019
1 parent f7de26e commit 440beb3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/app/rest/api/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ func encodeJSONWithHTML(v interface{}) ([]byte, error) {
return buf.Bytes(), nil
}

func filterComments(comments []store.Comment, fn func(c store.Comment) bool) (filtered []store.Comment) {
func filterComments(comments []store.Comment, fn func(c store.Comment) bool) []store.Comment {
filtered := []store.Comment{}
for _, c := range comments {
if fn(c) {
filtered = append(filtered, c)
Expand Down
6 changes: 5 additions & 1 deletion backend/app/rest/api/rest_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func TestRest_Last(t *testing.T) {
ts, srv, teardown := startupT(t)
defer teardown()

res, code := get(t, ts.URL+"/api/v1/last/2?site=radio-t")
assert.Equal(t, 200, code)
assert.Equal(t, "[]\n", res, "empty last should return empty list")

c1 := store.Comment{Text: "test test #1", ParentID: "p1",
Locator: store.Locator{SiteID: "radio-t", URL: "https://radio-t.com/blah1"}}
c2 := store.Comment{Text: "test test #2", ParentID: "p1",
Expand All @@ -209,7 +213,7 @@ func TestRest_Last(t *testing.T) {
id1 := addComment(t, c1, ts)
id2 := addComment(t, c2, ts)

res, code := get(t, ts.URL+"/api/v1/last/2?site=radio-t")
res, code = get(t, ts.URL+"/api/v1/last/2?site=radio-t")
assert.Equal(t, 200, code)
comments := []store.Comment{}
err := json.Unmarshal([]byte(res), &comments)
Expand Down

0 comments on commit 440beb3

Please sign in to comment.