diff options
Diffstat (limited to 'miniflux/client_test.go')
| -rw-r--r-- | miniflux/client_test.go | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/miniflux/client_test.go b/miniflux/client_test.go index 8f8c6ad..e3774a3 100644 --- a/miniflux/client_test.go +++ b/miniflux/client_test.go @@ -80,7 +80,7 @@ const entriesFixture = `{ }` // fakeServer records the last request's auth header and query, then replies -// with the fixture (or an error status). +// with the fixture (or an error status). Accepts /v1/entries and /v1/feeds. type fakeServer struct { t *testing.T status int @@ -98,7 +98,7 @@ func (f *fakeServer) handler() http.HandlerFunc { for k, v := range r.URL.Query() { f.gotQuery[k] = v[0] } - if r.URL.Path != "/v1/entries" { + if r.URL.Path != "/v1/entries" && r.URL.Path != "/v1/feeds" { f.t.Errorf("unexpected path: %s", r.URL.Path) } w.Header().Set("Content-Type", "application/json") @@ -165,6 +165,7 @@ func TestEntriesSendsFilters(t *testing.T) { _, err := client.Entries(Filters{ Starred: &starred, Status: "read", + FeedID: 77, ChangedAfter: 1700000000, PublishedAfter: 1700000000, AfterEntryID: 40999, @@ -178,6 +179,7 @@ func TestEntriesSendsFilters(t *testing.T) { want := map[string]string{ "starred": "true", "status": "read", + "feed_id": "77", "changed_after": "1700000000", "published_after": "1700000000", "after_entry_id": "40999", @@ -225,6 +227,59 @@ func TestEntriesBadJSON(t *testing.T) { } } +const feedsFixture = `[ + { + "id": 77, + "user_id": 3, + "feed_url": "https://example.com/feed.xml", + "site_url": "https://example.com", + "title": "Example Blog", + "disabled": false, + "category": {"id": 1, "title": "Tech", "user_id": 3} + }, + { + "id": 102, + "user_id": 3, + "feed_url": "https://daily.example/rss", + "site_url": "https://daily.example", + "title": "Some Daily", + "disabled": true, + "category": {"id": 2, "title": "News", "user_id": 3} + } +]` + +func TestFeedsDecodesFixture(t *testing.T) { + f := &fakeServer{t: t, status: http.StatusOK, body: feedsFixture} + client := newFakeClient(t, f) + + feeds, err := client.Feeds() + if err != nil { + t.Fatalf("Feeds: %v", err) + } + if !f.sawRequest { + t.Fatal("fake server saw no request") + } + if f.gotHeader != "test-token-123" { + t.Errorf("X-Auth-Token = %q, want test-token-123", f.gotHeader) + } + if len(feeds) != 2 { + t.Fatalf("len(feeds) = %d, want 2", len(feeds)) + } + if feeds[0].ID != 77 || feeds[0].Title != "Example Blog" || feeds[0].SiteURL != "https://example.com" { + t.Errorf("feeds[0] = %+v", feeds[0]) + } + if feeds[0].Disabled { + t.Error("feeds[0].Disabled = true, want false") + } + if !feeds[1].Disabled { + t.Error("feeds[1].Disabled = false, want true") + } + if feeds[0].Category.Title != "Tech" || feeds[1].Category.Title != "News" { + t.Errorf("categories = %q / %q, want Tech / News", + feeds[0].Category.Title, feeds[1].Category.Title) + } +} + func TestConfigFromEnv(t *testing.T) { t.Run("primary vars", func(t *testing.T) { t.Setenv("MINIFLUX_URL", "https://flux.example") |
