Update API client to support more filters
This commit is contained in:
parent
55fad7ea27
commit
acd318b640
3 changed files with 61 additions and 0 deletions
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -171,6 +171,8 @@ type Filter struct {
|
|||
AfterEntryID int64
|
||||
Search string
|
||||
CategoryID int64
|
||||
FeedID int64
|
||||
Statuses []string
|
||||
}
|
||||
|
||||
// EntryResultSet represents the response when fetching entries.
|
||||
|
|
|
@ -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…
Reference in a new issue