1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

Refactor feed creation to allow setting most fields via API

Allow API clients to create disabled feeds or define field like "ignore_http_cache".
This commit is contained in:
Frédéric Guillot 2021-01-02 16:33:41 -08:00 committed by fguillot
parent ab82c4b300
commit f0610bdd9c
26 changed files with 370 additions and 264 deletions

View file

@ -100,7 +100,10 @@ func TestFilterEntriesByCategory(t *testing.T) {
t.Fatal(err)
}
feedID, err := client.CreateFeed(testFeedURL, category.ID)
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: category.ID,
})
if err != nil {
t.Fatal(err)
}
@ -134,7 +137,10 @@ func TestFilterEntriesByStatuses(t *testing.T) {
t.Fatal(err)
}
feedID, err := client.CreateFeed(testFeedURL, category.ID)
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: category.ID,
})
if err != nil {
t.Fatal(err)
}
@ -181,7 +187,10 @@ func TestSearchEntries(t *testing.T) {
t.Fatal(err)
}
feedID, err := client.CreateFeed(testFeedURL, categories[0].ID)
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: categories[0].ID,
})
if err != nil {
t.Fatal(err)
}

View file

@ -26,7 +26,10 @@ func TestCannotCreateDuplicatedFeed(t *testing.T) {
client := createClient(t)
feed, category := createFeed(t, client)
_, err := client.CreateFeed(feed.FeedURL, category.ID)
_, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: feed.FeedURL,
CategoryID: category.ID,
})
if err == nil {
t.Fatal(`Duplicated feeds should not be allowed`)
}
@ -34,19 +37,145 @@ func TestCannotCreateDuplicatedFeed(t *testing.T) {
func TestCreateFeedWithInexistingCategory(t *testing.T) {
client := createClient(t)
_, err := client.CreateFeed(testFeedURL, -1)
_, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: -1,
})
if err == nil {
t.Fatal(`Feeds should not be created with inexisting category`)
}
}
func TestCreateDisabledFeed(t *testing.T) {
client := createClient(t)
categories, err := client.Categories()
if err != nil {
t.Fatal(err)
}
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: categories[0].ID,
Disabled: true,
})
if err != nil {
t.Fatal(err)
}
if feedID == 0 {
t.Fatalf(`Invalid feed ID, got %q`, feedID)
}
feed, err := client.Feed(feedID)
if err != nil {
t.Fatal(err)
}
if !feed.Disabled {
t.Error(`The feed should be disabled`)
}
}
func TestCreateFeedWithDisabledCache(t *testing.T) {
client := createClient(t)
categories, err := client.Categories()
if err != nil {
t.Fatal(err)
}
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: categories[0].ID,
IgnoreHTTPCache: true,
})
if err != nil {
t.Fatal(err)
}
if feedID == 0 {
t.Fatalf(`Invalid feed ID, got %q`, feedID)
}
feed, err := client.Feed(feedID)
if err != nil {
t.Fatal(err)
}
if !feed.IgnoreHTTPCache {
t.Error(`The feed should be ignoring HTTP cache`)
}
}
func TestCreateFeedWithCrawlerEnabled(t *testing.T) {
client := createClient(t)
categories, err := client.Categories()
if err != nil {
t.Fatal(err)
}
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: categories[0].ID,
Crawler: true,
})
if err != nil {
t.Fatal(err)
}
if feedID == 0 {
t.Fatalf(`Invalid feed ID, got %q`, feedID)
}
feed, err := client.Feed(feedID)
if err != nil {
t.Fatal(err)
}
if !feed.Crawler {
t.Error(`The feed should have the scraper enabled`)
}
}
func TestCreateFeedWithScraperRule(t *testing.T) {
client := createClient(t)
categories, err := client.Categories()
if err != nil {
t.Fatal(err)
}
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: categories[0].ID,
ScraperRules: "article",
})
if err != nil {
t.Fatal(err)
}
if feedID == 0 {
t.Fatalf(`Invalid feed ID, got %q`, feedID)
}
feed, err := client.Feed(feedID)
if err != nil {
t.Fatal(err)
}
if feed.ScraperRules != "article" {
t.Error(`The feed should have the custom scraper rule saved`)
}
}
func TestUpdateFeedURL(t *testing.T) {
client := createClient(t)
feed, _ := createFeed(t, client)
url := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{FeedURL: &url})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{FeedURL: &url})
if err != nil {
t.Fatal(err)
}
@ -56,7 +185,7 @@ func TestUpdateFeedURL(t *testing.T) {
}
url = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{FeedURL: &url})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{FeedURL: &url})
if err != nil {
t.Fatal(err)
}
@ -71,7 +200,7 @@ func TestUpdateFeedSiteURL(t *testing.T) {
feed, _ := createFeed(t, client)
url := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{SiteURL: &url})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{SiteURL: &url})
if err != nil {
t.Fatal(err)
}
@ -81,7 +210,7 @@ func TestUpdateFeedSiteURL(t *testing.T) {
}
url = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{SiteURL: &url})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{SiteURL: &url})
if err != nil {
t.Fatal(err)
}
@ -96,7 +225,7 @@ func TestUpdateFeedTitle(t *testing.T) {
feed, _ := createFeed(t, client)
newTitle := "My new feed"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{Title: &newTitle})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Title: &newTitle})
if err != nil {
t.Fatal(err)
}
@ -106,7 +235,7 @@ func TestUpdateFeedTitle(t *testing.T) {
}
newTitle = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{Title: &newTitle})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Title: &newTitle})
if err != nil {
t.Fatal(err)
}
@ -121,7 +250,7 @@ func TestUpdateFeedCrawler(t *testing.T) {
feed, _ := createFeed(t, client)
crawler := true
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{Crawler: &crawler})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Crawler: &crawler})
if err != nil {
t.Fatal(err)
}
@ -135,7 +264,7 @@ func TestUpdateFeedCrawler(t *testing.T) {
}
crawler = false
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{Crawler: &crawler})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Crawler: &crawler})
if err != nil {
t.Fatal(err)
}
@ -150,7 +279,7 @@ func TestUpdateFeedScraperRules(t *testing.T) {
feed, _ := createFeed(t, client)
scraperRules := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{ScraperRules: &scraperRules})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{ScraperRules: &scraperRules})
if err != nil {
t.Fatal(err)
}
@ -160,7 +289,7 @@ func TestUpdateFeedScraperRules(t *testing.T) {
}
scraperRules = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{ScraperRules: &scraperRules})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{ScraperRules: &scraperRules})
if err != nil {
t.Fatal(err)
}
@ -175,7 +304,7 @@ func TestUpdateFeedRewriteRules(t *testing.T) {
feed, _ := createFeed(t, client)
rewriteRules := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{RewriteRules: &rewriteRules})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{RewriteRules: &rewriteRules})
if err != nil {
t.Fatal(err)
}
@ -185,7 +314,7 @@ func TestUpdateFeedRewriteRules(t *testing.T) {
}
rewriteRules = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{RewriteRules: &rewriteRules})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{RewriteRules: &rewriteRules})
if err != nil {
t.Fatal(err)
}
@ -200,7 +329,7 @@ func TestUpdateFeedKeeplistRules(t *testing.T) {
feed, _ := createFeed(t, client)
keeplistRules := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{KeeplistRules: &keeplistRules})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{KeeplistRules: &keeplistRules})
if err != nil {
t.Fatal(err)
}
@ -210,7 +339,7 @@ func TestUpdateFeedKeeplistRules(t *testing.T) {
}
keeplistRules = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{KeeplistRules: &keeplistRules})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{KeeplistRules: &keeplistRules})
if err != nil {
t.Fatal(err)
}
@ -225,7 +354,7 @@ func TestUpdateFeedUserAgent(t *testing.T) {
feed, _ := createFeed(t, client)
userAgent := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{UserAgent: &userAgent})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{UserAgent: &userAgent})
if err != nil {
t.Fatal(err)
}
@ -235,7 +364,7 @@ func TestUpdateFeedUserAgent(t *testing.T) {
}
userAgent = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{UserAgent: &userAgent})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{UserAgent: &userAgent})
if err != nil {
t.Fatal(err)
}
@ -250,7 +379,7 @@ func TestUpdateFeedUsername(t *testing.T) {
feed, _ := createFeed(t, client)
username := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{Username: &username})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Username: &username})
if err != nil {
t.Fatal(err)
}
@ -260,7 +389,7 @@ func TestUpdateFeedUsername(t *testing.T) {
}
username = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{Username: &username})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Username: &username})
if err != nil {
t.Fatal(err)
}
@ -275,7 +404,7 @@ func TestUpdateFeedPassword(t *testing.T) {
feed, _ := createFeed(t, client)
password := "test"
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{Password: &password})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Password: &password})
if err != nil {
t.Fatal(err)
}
@ -285,7 +414,7 @@ func TestUpdateFeedPassword(t *testing.T) {
}
password = ""
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{Password: &password})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{Password: &password})
if err != nil {
t.Fatal(err)
}
@ -304,7 +433,7 @@ func TestUpdateFeedCategory(t *testing.T) {
t.Fatal(err)
}
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModification{CategoryID: &newCategory.ID})
updatedFeed, err := client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{CategoryID: &newCategory.ID})
if err != nil {
t.Fatal(err)
}
@ -314,7 +443,7 @@ func TestUpdateFeedCategory(t *testing.T) {
}
categoryID := int64(0)
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModification{CategoryID: &categoryID})
updatedFeed, err = client.UpdateFeed(feed.ID, &miniflux.FeedModificationRequest{CategoryID: &categoryID})
if err != nil {
t.Fatal(err)
}

View file

@ -51,7 +51,10 @@ func createFeed(t *testing.T, client *miniflux.Client) (*miniflux.Feed, *miniflu
t.Fatal(err)
}
feedID, err := client.CreateFeed(testFeedURL, categories[0].ID)
feedID, err := client.CreateFeed(&miniflux.FeedCreationRequest{
FeedURL: testFeedURL,
CategoryID: categories[0].ID,
})
if err != nil {
t.Fatal(err)
}

View file

@ -261,7 +261,7 @@ func TestUpdateUserTheme(t *testing.T) {
}
theme := "dark_serif"
user, err = client.UpdateUser(user.ID, &miniflux.UserModification{Theme: &theme})
user, err = client.UpdateUser(user.ID, &miniflux.UserModificationRequest{Theme: &theme})
if err != nil {
t.Fatal(err)
}
@ -282,7 +282,7 @@ func TestUpdateUserFields(t *testing.T) {
stylesheet := "body { color: red }"
swipe := false
entriesPerPage := 5
user, err = client.UpdateUser(user.ID, &miniflux.UserModification{
user, err = client.UpdateUser(user.ID, &miniflux.UserModificationRequest{
Stylesheet: &stylesheet,
EntrySwipe: &swipe,
EntriesPerPage: &entriesPerPage,
@ -313,7 +313,7 @@ func TestUpdateUserThemeWithInvalidValue(t *testing.T) {
}
theme := "something that doesn't exists"
_, err = client.UpdateUser(user.ID, &miniflux.UserModification{Theme: &theme})
_, err = client.UpdateUser(user.ID, &miniflux.UserModificationRequest{Theme: &theme})
if err == nil {
t.Fatal(`Updating a user Theme with an invalid value should raise an error`)
}
@ -388,7 +388,7 @@ func TestCannotUpdateUserAsNonAdmin(t *testing.T) {
entriesPerPage := 10
userAClient := miniflux.New(testBaseURL, usernameA, testStandardPassword)
userAAfterUpdate, err := userAClient.UpdateUser(userA.ID, &miniflux.UserModification{EntriesPerPage: &entriesPerPage})
userAAfterUpdate, err := userAClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{EntriesPerPage: &entriesPerPage})
if err != nil {
t.Fatal(`Standard users should be able to update themselves`)
}
@ -398,13 +398,13 @@ func TestCannotUpdateUserAsNonAdmin(t *testing.T) {
}
isAdmin := true
_, err = userAClient.UpdateUser(userA.ID, &miniflux.UserModification{IsAdmin: &isAdmin})
_, err = userAClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{IsAdmin: &isAdmin})
if err == nil {
t.Fatal(`Standard users should not be able to become admin`)
}
userBClient := miniflux.New(testBaseURL, usernameB, testStandardPassword)
_, err = userBClient.UpdateUser(userA.ID, &miniflux.UserModification{})
_, err = userBClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{})
if err == nil {
t.Fatal(`Standard users should not be able to update other users`)
}
@ -414,7 +414,7 @@ func TestCannotUpdateUserAsNonAdmin(t *testing.T) {
}
stylesheet := "test"
userC, err := adminClient.UpdateUser(userA.ID, &miniflux.UserModification{Stylesheet: &stylesheet})
userC, err := adminClient.UpdateUser(userA.ID, &miniflux.UserModificationRequest{Stylesheet: &stylesheet})
if err != nil {
t.Fatal(`Admin users should be able to update any users`)
}