2018-06-24 01:16:54 +02:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package api // import "miniflux.app/api"
|
2018-06-24 01:16:54 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/model"
|
2018-06-24 01:16:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUpdateFeedURL(t *testing.T) {
|
|
|
|
feedURL := "http://example.com/"
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{FeedURL: &feedURL}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{FeedURL: "http://example.org/"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.FeedURL != feedURL {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Errorf(`Unexpected value, got %q instead of %q`, feed.FeedURL, feedURL)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedURLWithEmptyString(t *testing.T) {
|
|
|
|
feedURL := ""
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{FeedURL: &feedURL}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{FeedURL: "http://example.org/"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.FeedURL == feedURL {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The FeedURL should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedURLWhenNotSet(t *testing.T) {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{FeedURL: "http://example.org/"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.FeedURL != "http://example.org/" {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The FeedURL should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedSiteURL(t *testing.T) {
|
|
|
|
siteURL := "http://example.com/"
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{SiteURL: &siteURL}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{SiteURL: "http://example.org/"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.SiteURL != siteURL {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Errorf(`Unexpected value, got %q instead of %q`, feed.SiteURL, siteURL)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedSiteURLWithEmptyString(t *testing.T) {
|
|
|
|
siteURL := ""
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{FeedURL: &siteURL}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{SiteURL: "http://example.org/"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.SiteURL == siteURL {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The FeedURL should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedSiteURLWhenNotSet(t *testing.T) {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{SiteURL: "http://example.org/"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.SiteURL != "http://example.org/" {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The SiteURL should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedTitle(t *testing.T) {
|
|
|
|
title := "Example 2"
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{Title: &title}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Title: "Example"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Title != title {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Errorf(`Unexpected value, got %q instead of %q`, feed.Title, title)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedTitleWithEmptyString(t *testing.T) {
|
|
|
|
title := ""
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{Title: &title}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Title: "Example"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Title == title {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The Title should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedTitleWhenNotSet(t *testing.T) {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Title: "Example"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Title != "Example" {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The Title should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedUsername(t *testing.T) {
|
|
|
|
username := "Alice"
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{Username: &username}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Username: "Bob"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Username != username {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Errorf(`Unexpected value, got %q instead of %q`, feed.Username, username)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedUsernameWithEmptyString(t *testing.T) {
|
|
|
|
username := ""
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{Username: &username}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Username: "Bob"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Username != "" {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The Username should be empty now`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedUsernameWhenNotSet(t *testing.T) {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Username: "Alice"}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Username != "Alice" {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The Username should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-27 06:13:06 +02:00
|
|
|
func TestUpdateFeedDisabled(t *testing.T) {
|
|
|
|
valueTrue := true
|
|
|
|
valueFalse := false
|
|
|
|
scenarios := []struct {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes *feedModificationRequest
|
2019-07-27 06:13:06 +02:00
|
|
|
feed *model.Feed
|
|
|
|
expected bool
|
|
|
|
}{
|
2020-12-14 05:31:19 +01:00
|
|
|
{&feedModificationRequest{}, &model.Feed{Disabled: true}, true},
|
|
|
|
{&feedModificationRequest{Disabled: &valueTrue}, &model.Feed{Disabled: true}, true},
|
|
|
|
{&feedModificationRequest{Disabled: &valueFalse}, &model.Feed{Disabled: true}, false},
|
|
|
|
{&feedModificationRequest{}, &model.Feed{Disabled: false}, false},
|
|
|
|
{&feedModificationRequest{Disabled: &valueTrue}, &model.Feed{Disabled: false}, true},
|
|
|
|
{&feedModificationRequest{Disabled: &valueFalse}, &model.Feed{Disabled: false}, false},
|
2019-07-27 06:13:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, scenario := range scenarios {
|
|
|
|
scenario.changes.Update(scenario.feed)
|
|
|
|
if scenario.feed.Disabled != scenario.expected {
|
|
|
|
t.Errorf(`Unexpected result, got %v, want: %v`,
|
|
|
|
scenario.feed.Disabled,
|
|
|
|
scenario.expected,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 01:16:54 +02:00
|
|
|
func TestUpdateFeedCategory(t *testing.T) {
|
|
|
|
categoryID := int64(1)
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{CategoryID: &categoryID}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Category: &model.Category{ID: 42}}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Category.ID != categoryID {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Errorf(`Unexpected value, got %q instead of %q`, feed.Username, categoryID)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedCategoryWithZero(t *testing.T) {
|
|
|
|
categoryID := int64(0)
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{CategoryID: &categoryID}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Category: &model.Category{ID: 42}}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Category.ID != 42 {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The CategoryID should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedCategoryWhenNotSet(t *testing.T) {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &feedModificationRequest{}
|
2018-06-24 01:16:54 +02:00
|
|
|
feed := &model.Feed{Category: &model.Category{ID: 42}}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.Category.ID != 42 {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The CategoryID should not be modified`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedToIgnoreCache(t *testing.T) {
|
|
|
|
value := true
|
|
|
|
changes := &feedModificationRequest{IgnoreHTTPCache: &value}
|
|
|
|
feed := &model.Feed{IgnoreHTTPCache: false}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.IgnoreHTTPCache != value {
|
|
|
|
t.Errorf(`The field IgnoreHTTPCache should be %v`, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateFeedToFetchViaProxy(t *testing.T) {
|
|
|
|
value := true
|
|
|
|
changes := &feedModificationRequest{FetchViaProxy: &value}
|
|
|
|
feed := &model.Feed{FetchViaProxy: false}
|
|
|
|
changes.Update(feed)
|
|
|
|
|
|
|
|
if feed.FetchViaProxy != value {
|
|
|
|
t.Errorf(`The field FetchViaProxy should be %v`, value)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateUserTheme(t *testing.T) {
|
|
|
|
theme := "Example 2"
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &userModificationRequest{Theme: &theme}
|
2018-06-24 01:16:54 +02:00
|
|
|
user := &model.User{Theme: "Example"}
|
|
|
|
changes.Update(user)
|
|
|
|
|
|
|
|
if user.Theme != theme {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Errorf(`Unexpected value, got %q instead of %q`, user.Theme, theme)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserThemeWhenNotSet(t *testing.T) {
|
2020-12-14 05:31:19 +01:00
|
|
|
changes := &userModificationRequest{}
|
2018-06-24 01:16:54 +02:00
|
|
|
user := &model.User{Theme: "Example"}
|
|
|
|
changes.Update(user)
|
|
|
|
|
|
|
|
if user.Theme != "Example" {
|
2020-12-14 05:31:19 +01:00
|
|
|
t.Error(`The user Theme should not be modified`)
|
2018-06-24 01:16:54 +02:00
|
|
|
}
|
|
|
|
}
|