From 1f015d5dfeb3eba7c0c2d1eb2f697dd18c128ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 25 Nov 2017 17:32:43 -0800 Subject: [PATCH] Add integration tests for feeds --- integration_test.go | 196 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/integration_test.go b/integration_test.go index 848a6951..c9974322 100644 --- a/integration_test.go +++ b/integration_test.go @@ -575,6 +575,202 @@ func TestCreateFeedWithInexistingCategory(t *testing.T) { } } +func TestUpdateFeed(t *testing.T) { + username := getRandomUsername() + client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword) + _, err := client.CreateUser(username, testStandardPassword, false) + if err != nil { + t.Fatal(err) + } + + client = miniflux.NewClient(testBaseURL, username, testStandardPassword) + categories, err := client.Categories() + if err != nil { + t.Fatal(err) + } + + feedID, err := client.CreateFeed("https://miniflux.net/feed", categories[0].ID) + if err != nil { + t.Fatal(err) + } + + if feedID == 0 { + t.Fatalf(`Invalid feed ID, got "%v"`, feedID) + } + + feed, err := client.Feed(feedID) + if err != nil { + t.Fatal(err) + } + + newTitle := "My new feed" + feed.Title = newTitle + feed, err = client.UpdateFeed(feed) + if err != nil { + t.Fatal(err) + } + + if feed.Title != newTitle { + t.Errorf(`Wrong title, got "%v" instead of "%v"`, feed.Title, newTitle) + } +} + +func TestDeleteFeed(t *testing.T) { + username := getRandomUsername() + client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword) + _, err := client.CreateUser(username, testStandardPassword, false) + if err != nil { + t.Fatal(err) + } + + client = miniflux.NewClient(testBaseURL, username, testStandardPassword) + categories, err := client.Categories() + if err != nil { + t.Fatal(err) + } + + feedID, err := client.CreateFeed("https://miniflux.net/feed", categories[0].ID) + if err != nil { + t.Fatal(err) + } + + err = client.DeleteFeed(feedID) + if err != nil { + t.Fatal(err) + } +} + +func TestRefreshFeed(t *testing.T) { + username := getRandomUsername() + client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword) + _, err := client.CreateUser(username, testStandardPassword, false) + if err != nil { + t.Fatal(err) + } + + client = miniflux.NewClient(testBaseURL, username, testStandardPassword) + categories, err := client.Categories() + if err != nil { + t.Fatal(err) + } + + feedID, err := client.CreateFeed("https://miniflux.net/feed", categories[0].ID) + if err != nil { + t.Fatal(err) + } + + err = client.RefreshFeed(feedID) + if err != nil { + t.Fatal(err) + } +} + +func TestGetFeed(t *testing.T) { + username := getRandomUsername() + client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword) + _, err := client.CreateUser(username, testStandardPassword, false) + if err != nil { + t.Fatal(err) + } + + client = miniflux.NewClient(testBaseURL, username, testStandardPassword) + categories, err := client.Categories() + if err != nil { + t.Fatal(err) + } + + feedID, err := client.CreateFeed("https://miniflux.net/feed", categories[0].ID) + if err != nil { + t.Fatal(err) + } + + feed, err := client.Feed(feedID) + if err != nil { + t.Fatal(err) + } + + if feed.Title != "Miniflux" { + t.Fatalf(`Invalid feed title, got "%v" instead of "%v"`, feed.Title, "Miniflux") + } + + if feed.SiteURL != "https://miniflux.net/" { + t.Fatalf(`Invalid site URL, got "%v" instead of "%v"`, feed.SiteURL, "https://miniflux.net/") + } + + if feed.FeedURL != "https://miniflux.net/feed" { + t.Fatalf(`Invalid feed URL, got "%v" instead of "%v"`, feed.FeedURL, "https://miniflux.net/feed") + } + + if feed.Category.ID != categories[0].ID { + t.Fatalf(`Invalid feed category ID, got "%v" instead of "%v"`, feed.Category.ID, categories[0].ID) + } + + if feed.Category.UserID != categories[0].UserID { + t.Fatalf(`Invalid feed category user ID, got "%v" instead of "%v"`, feed.Category.UserID, categories[0].UserID) + } + + if feed.Category.Title != categories[0].Title { + t.Fatalf(`Invalid feed category title, got "%v" instead of "%v"`, feed.Category.Title, categories[0].Title) + } +} + +func TestGetFeeds(t *testing.T) { + username := getRandomUsername() + client := miniflux.NewClient(testBaseURL, testAdminUsername, testAdminPassword) + _, err := client.CreateUser(username, testStandardPassword, false) + if err != nil { + t.Fatal(err) + } + + client = miniflux.NewClient(testBaseURL, username, testStandardPassword) + categories, err := client.Categories() + if err != nil { + t.Fatal(err) + } + + feedID, err := client.CreateFeed("https://miniflux.net/feed", categories[0].ID) + if err != nil { + t.Fatal(err) + } + + feeds, err := client.Feeds() + if err != nil { + t.Fatal(err) + } + + if len(feeds) != 1 { + t.Fatalf(`Invalid number of feeds`) + } + + if feeds[0].ID != feedID { + t.Fatalf(`Invalid feed ID, got "%v" instead of "%v"`, feeds[0].ID, feedID) + } + + if feeds[0].Title != "Miniflux" { + t.Fatalf(`Invalid feed title, got "%v" instead of "%v"`, feeds[0].Title, "Miniflux") + } + + if feeds[0].SiteURL != "https://miniflux.net/" { + t.Fatalf(`Invalid site URL, got "%v" instead of "%v"`, feeds[0].SiteURL, "https://miniflux.net/") + } + + if feeds[0].FeedURL != "https://miniflux.net/feed" { + t.Fatalf(`Invalid feed URL, got "%v" instead of "%v"`, feeds[0].FeedURL, "https://miniflux.net/feed") + } + + if feeds[0].Category.ID != categories[0].ID { + t.Fatalf(`Invalid feed category ID, got "%v" instead of "%v"`, feeds[0].Category.ID, categories[0].ID) + } + + if feeds[0].Category.UserID != categories[0].UserID { + t.Fatalf(`Invalid feed category user ID, got "%v" instead of "%v"`, feeds[0].Category.UserID, categories[0].UserID) + } + + if feeds[0].Category.Title != categories[0].Title { + t.Fatalf(`Invalid feed category title, got "%v" instead of "%v"`, feeds[0].Category.Title, categories[0].Title) + } +} + func getRandomUsername() string { rand.Seed(time.Now().UnixNano()) var suffix []string