mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Add API endpoints to get feeds and entries of a category
This commit is contained in:
parent
02a4c9db53
commit
4ff52bd730
6 changed files with 275 additions and 38 deletions
|
@ -48,7 +48,47 @@ func TestGetAllFeedEntries(t *testing.T) {
|
|||
}
|
||||
|
||||
if filteredResultsByEntryID.Entries[0].ID == allResults.Entries[0].ID {
|
||||
t.Fatal(`The first entry should filtered out`)
|
||||
t.Fatal(`The first entry should be filtered out`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllCategoryEntries(t *testing.T) {
|
||||
client := createClient(t)
|
||||
_, category := createFeed(t, client)
|
||||
|
||||
allResults, err := client.CategoryEntries(category.ID, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if allResults.Total == 0 {
|
||||
t.Fatal(`Invalid number of entries`)
|
||||
}
|
||||
|
||||
if allResults.Entries[0].Title == "" {
|
||||
t.Fatal(`Invalid entry title`)
|
||||
}
|
||||
|
||||
filteredResults, err := client.CategoryEntries(category.ID, &miniflux.Filter{Limit: 1, Offset: 5})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if allResults.Total != filteredResults.Total {
|
||||
t.Fatal(`Total should always contains the total number of items regardless of filters`)
|
||||
}
|
||||
|
||||
if allResults.Entries[0].ID == filteredResults.Entries[0].ID {
|
||||
t.Fatal(`Filtered entries should be different than previous results`)
|
||||
}
|
||||
|
||||
filteredResultsByEntryID, err := client.CategoryEntries(category.ID, &miniflux.Filter{BeforeEntryID: allResults.Entries[0].ID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if filteredResultsByEntryID.Entries[0].ID == allResults.Entries[0].ID {
|
||||
t.Fatal(`The first entry should be filtered out`)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,6 +170,43 @@ func TestFilterEntriesByCategory(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFilterEntriesByFeed(t *testing.T) {
|
||||
client := createClient(t)
|
||||
category, err := client.CreateCategory("Test Filter by Feed")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
|
||||
FeedURL: testFeedURL,
|
||||
CategoryID: 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 results.Total == 0 {
|
||||
t.Fatalf(`We should have more than one entry`)
|
||||
}
|
||||
|
||||
if results.Entries[0].Feed.Category == nil {
|
||||
t.Fatalf(`The entry feed category should not be nil`)
|
||||
}
|
||||
|
||||
if results.Entries[0].Feed.Category.ID != category.ID {
|
||||
t.Errorf(`Entries should be filtered by category_id=%d`, category.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterEntriesByStatuses(t *testing.T) {
|
||||
client := createClient(t)
|
||||
category, err := client.CreateCategory("Test Filter by statuses")
|
||||
|
@ -229,6 +306,44 @@ func TestInvalidFilters(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetFeedEntry(t *testing.T) {
|
||||
client := createClient(t)
|
||||
createFeed(t, client)
|
||||
|
||||
result, err := client.Entries(&miniflux.Filter{Limit: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test get entry by entry id and feed id
|
||||
entry, err := client.FeedEntry(result.Entries[0].FeedID, result.Entries[0].ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if entry.ID != result.Entries[0].ID {
|
||||
t.Fatal("Wrong entry returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCategoryEntry(t *testing.T) {
|
||||
client := createClient(t)
|
||||
_, category := createFeed(t, client)
|
||||
|
||||
result, err := client.Entries(&miniflux.Filter{Limit: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Test get entry by entry id and category id
|
||||
entry, err := client.CategoryEntry(category.ID, result.Entries[0].ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if entry.ID != result.Entries[0].ID {
|
||||
t.Fatal("Wrong entry returned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEntry(t *testing.T) {
|
||||
client := createClient(t)
|
||||
createFeed(t, client)
|
||||
|
@ -238,20 +353,11 @@ func TestGetEntry(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
entry, err := client.FeedEntry(result.Entries[0].FeedID, result.Entries[0].ID)
|
||||
// Test get entry by entry id only
|
||||
entry, err := client.Entry(result.Entries[0].ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if entry.ID != result.Entries[0].ID {
|
||||
t.Fatal("Wrong entry returned")
|
||||
}
|
||||
|
||||
entry, err = client.Entry(result.Entries[0].ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if entry.ID != result.Entries[0].ID {
|
||||
t.Fatal("Wrong entry returned")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue