Browse Source

Update API client to support more filters

tags/2.0.24
Frédéric Guillot 1 month ago
parent
commit
acd318b640
3 changed files with 61 additions and 0 deletions
  1. +12
    -0
      client/client.go
  2. +2
    -0
      client/core.go
  3. +47
    -0
      tests/entry_test.go

+ 12
- 0
client/client.go View File

@@ -480,6 +480,18 @@ func buildFilterQueryString(path string, filter *Filter) string {
values.Set("search", filter.Search)
}

if filter.CategoryID > 0 {
values.Set("category_id", strconv.FormatInt(filter.CategoryID, 10))
}

if filter.FeedID > 0 {
values.Set("feed_id", strconv.FormatInt(filter.FeedID, 10))
}

for _, status := range filter.Statuses {
values.Add("status", status)
}

path = fmt.Sprintf("%s?%s", path, values.Encode())
}



+ 2
- 0
client/core.go View File

@@ -171,6 +171,8 @@ type Filter struct {
AfterEntryID int64
Search string
CategoryID int64
FeedID int64
Statuses []string
}

// EntryResultSet represents the response when fetching entries.


+ 47
- 0
tests/entry_test.go View File

@@ -127,6 +127,53 @@ func TestFilterEntriesByCategory(t *testing.T) {
}
}

func TestFilterEntriesByStatuses(t *testing.T) {
client := createClient(t)
category, err := client.CreateCategory("Test Filter by statuses")
if err != nil {
t.Fatal(err)
}

feedID, err := client.CreateFeed(testFeedURL, category.ID)
if err != nil {
t.Fatal(err)
}

if feedID == 0 {
t.Fatalf(`Invalid feed ID, got %q`, feedID)
}

results, err := client.Entries(&miniflux.Filter{FeedID: feedID})
if err != nil {
t.Fatal(err)
}

if err := client.UpdateEntries([]int64{results.Entries[0].ID}, "read"); err != nil {
t.Fatal(err)
}

if err := client.UpdateEntries([]int64{results.Entries[1].ID}, "removed"); err != nil {
t.Fatal(err)
}

results, err = client.Entries(&miniflux.Filter{Statuses: []string{"read", "removed"}})
if err != nil {
t.Fatal(err)
}

if results.Total != 2 {
t.Fatalf(`We should have 2 entries`)
}

if results.Entries[0].Status != "read" {
t.Errorf(`The first entry has the wrong status: %s`, results.Entries[0].Status)
}

if results.Entries[1].Status != "removed" {
t.Errorf(`The 2nd entry has the wrong status: %s`, results.Entries[1].Status)
}
}

func TestSearchEntries(t *testing.T) {
client := createClient(t)
categories, err := client.Categories()


Loading…
Cancel
Save