diff --git a/pkg/db/fixtures/saved_filters.yml b/pkg/db/fixtures/saved_filters.yml index caa1ea566..844ceb1a4 100644 --- a/pkg/db/fixtures/saved_filters.yml +++ b/pkg/db/fixtures/saved_filters.yml @@ -1,5 +1,5 @@ - id: 1 - filters: '' + filters: '{"sort_by":null,"order_by":null,"filter_by":["start_date","end_date","due_date"],"filter_value":["2018-12-11T03:46:40+00:00","2018-12-13T11:20:01+00:00","2018-11-29T14:00:00+00:00"],"filter_comparator":["greater","less","greater"],"filter_concat":"","filter_include_nulls":false}' title: testfilter1 owner_id: 1 updated: 2020-09-08 15:13:12 diff --git a/pkg/integrations/task_collection_test.go b/pkg/integrations/task_collection_test.go index 6c203901e..8a8234332 100644 --- a/pkg/integrations/task_collection_test.go +++ b/pkg/integrations/task_collection_test.go @@ -258,6 +258,29 @@ func TestTaskCollection(t *testing.T) { assertHandlerErrorCode(t, err, models.ErrCodeInvalidTaskFilterValue) }) }) + t.Run("saved filter", func(t *testing.T) { + t.Run("date range", func(t *testing.T) { + rec, err := testHandler.testReadAllWithUser( + nil, + map[string]string{"list": "-2"}, // Actually a saved filter - contains the same filter arguments as the start and end date filter from above + ) + assert.NoError(t, err) + assert.NotContains(t, rec.Body.String(), `task #1`) + assert.NotContains(t, rec.Body.String(), `task #2`) + assert.NotContains(t, rec.Body.String(), `task #3`) + assert.NotContains(t, rec.Body.String(), `task #4`) + assert.Contains(t, rec.Body.String(), `task #5`) + assert.Contains(t, rec.Body.String(), `task #6`) + assert.Contains(t, rec.Body.String(), `task #7`) + assert.Contains(t, rec.Body.String(), `task #8`) + assert.Contains(t, rec.Body.String(), `task #9`) + assert.NotContains(t, rec.Body.String(), `task #10`) + assert.NotContains(t, rec.Body.String(), `task #11`) + assert.NotContains(t, rec.Body.String(), `task #12`) + assert.NotContains(t, rec.Body.String(), `task #13`) + assert.NotContains(t, rec.Body.String(), `task #14`) + }) + }) }) t.Run("ReadAll for all tasks", func(t *testing.T) { diff --git a/pkg/models/saved_filters.go b/pkg/models/saved_filters.go index 163277b8a..1d9ba59e8 100644 --- a/pkg/models/saved_filters.go +++ b/pkg/models/saved_filters.go @@ -106,7 +106,10 @@ func (s *SavedFilter) Create(auth web.Auth) error { } func getSavedFilterSimpleByID(id int64) (s *SavedFilter, err error) { - exists, err := x.Where("id = ?", id).Get(s) + s = &SavedFilter{} + exists, err := x. + Where("id = ?", id). + Get(s) if err != nil { return nil, err } diff --git a/pkg/models/saved_filters_test.go b/pkg/models/saved_filters_test.go index 0fc979a7a..e746b6b91 100644 --- a/pkg/models/saved_filters_test.go +++ b/pkg/models/saved_filters_test.go @@ -46,7 +46,7 @@ func TestSavedFilter_Create(t *testing.T) { sf := &SavedFilter{ Title: "test", Description: "Lorem Ipsum dolor sit amet", - Filters: &TaskCollection{}, + Filters: &TaskCollection{}, // Empty filter } u := &user.User{ID: 1}