diff options
author | Frédéric Guillot <fred@miniflux.net> | 2019-07-26 21:13:06 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2019-07-26 21:24:15 -0700 |
commit | 3d19313a7f655bc2626990650c4de8141485eea3 (patch) | |
tree | c7fb0ade2b0f2eac2ae42067342df2e584ad230d /api | |
parent | 17aae725830cdd27131d40e20f3901d7da25e281 (diff) |
Add option to disable feeds
Diffstat (limited to 'api')
-rw-r--r-- | api/payload.go | 5 | ||||
-rw-r--r-- | api/payload_test.go | 27 |
2 files changed, 32 insertions, 0 deletions
diff --git a/api/payload.go b/api/payload.go index 5acf0bb..011a516 100644 --- a/api/payload.go +++ b/api/payload.go @@ -50,6 +50,7 @@ type feedModification struct { Username *string `json:"username"` Password *string `json:"password"` CategoryID *int64 `json:"category_id"` + Disabled *bool `json:"disabled"` } func (f *feedModification) Update(feed *model.Feed) { @@ -92,6 +93,10 @@ func (f *feedModification) Update(feed *model.Feed) { if f.CategoryID != nil && *f.CategoryID > 0 { feed.Category.ID = *f.CategoryID } + + if f.Disabled != nil { + feed.Disabled = *f.Disabled + } } type userModification struct { diff --git a/api/payload_test.go b/api/payload_test.go index f890fe6..fe52ed1 100644 --- a/api/payload_test.go +++ b/api/payload_test.go @@ -138,6 +138,33 @@ func TestUpdateFeedUsernameWhenNotSet(t *testing.T) { } } +func TestUpdateFeedDisabled(t *testing.T) { + valueTrue := true + valueFalse := false + scenarios := []struct { + changes *feedModification + feed *model.Feed + expected bool + }{ + {&feedModification{}, &model.Feed{Disabled: true}, true}, + {&feedModification{Disabled: &valueTrue}, &model.Feed{Disabled: true}, true}, + {&feedModification{Disabled: &valueFalse}, &model.Feed{Disabled: true}, false}, + {&feedModification{}, &model.Feed{Disabled: false}, false}, + {&feedModification{Disabled: &valueTrue}, &model.Feed{Disabled: false}, true}, + {&feedModification{Disabled: &valueFalse}, &model.Feed{Disabled: false}, false}, + } + + 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, + ) + } + } +} + func TestUpdateFeedCategory(t *testing.T) { categoryID := int64(1) changes := &feedModification{CategoryID: &categoryID} |