diff --git a/pkg/db/fixtures/saved_filters.yml b/pkg/db/fixtures/saved_filters.yml new file mode 100644 index 000000000..caa1ea566 --- /dev/null +++ b/pkg/db/fixtures/saved_filters.yml @@ -0,0 +1,6 @@ +- id: 1 + filters: '' + title: testfilter1 + owner_id: 1 + updated: 2020-09-08 15:13:12 + created: 2020-09-08 14:13:12 diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 20e816872..c753d5ca3 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -395,7 +395,7 @@ func (n *Namespace) ReadAll(a web.Auth, search string, page int, perPage int) (r } ////////////////////// - // Put it all together + // Put it all together (and sort it) all := make([]*NamespaceWithLists, 0, len(namespaces)) for _, n := range namespaces { n.Owner = userMap[n.OwnerID] diff --git a/pkg/models/namespace_test.go b/pkg/models/namespace_test.go index de434a8bb..5e7667f25 100644 --- a/pkg/models/namespace_test.go +++ b/pkg/models/namespace_test.go @@ -145,9 +145,10 @@ func TestNamespace_ReadAll(t *testing.T) { assert.NoError(t, err) namespaces := nn.([]*NamespaceWithLists) assert.NotNil(t, namespaces) - assert.Len(t, namespaces, 10) // Total of 10 including shared & favorites - assert.Equal(t, int64(-2), namespaces[0].ID) // The first one should be the one with favorites - assert.Equal(t, int64(-1), namespaces[1].ID) // The second one should be the one with the shared namespaces + assert.Len(t, namespaces, 11) // Total of 10 including shared, favorites and saved filters + assert.Equal(t, int64(-3), namespaces[0].ID) // The first one should be the one with shared filters + assert.Equal(t, int64(-2), namespaces[1].ID) // The second one should be the one with favorites + assert.Equal(t, int64(-1), namespaces[2].ID) // The third one should be the one with the shared namespaces // Ensure every list and namespace are not archived for _, namespace := range namespaces { assert.False(t, namespace.IsArchived) @@ -164,9 +165,10 @@ func TestNamespace_ReadAll(t *testing.T) { namespaces := nn.([]*NamespaceWithLists) assert.NoError(t, err) assert.NotNil(t, namespaces) - assert.Len(t, namespaces, 11) // Total of 11 including shared & favorites, one is archived - assert.Equal(t, int64(-2), namespaces[0].ID) // The first one should be the one with favorites - assert.Equal(t, int64(-1), namespaces[1].ID) // The second one should be the one with the shared namespaces + assert.Len(t, namespaces, 12) // Total of 12 including shared & favorites, one is archived + assert.Equal(t, int64(-3), namespaces[0].ID) // The first one should be the one with shared filters + assert.Equal(t, int64(-2), namespaces[1].ID) // The second one should be the one with favorites + assert.Equal(t, int64(-1), namespaces[2].ID) // The third one should be the one with the shared namespaces }) t.Run("no favorites", func(t *testing.T) { n := &Namespace{} @@ -185,4 +187,12 @@ func TestNamespace_ReadAll(t *testing.T) { assert.Equal(t, FavoritesPseudoNamespace.ID, namespaces[0].ID) assert.NotEqual(t, 0, namespaces[0].Lists) }) + t.Run("no saved filters", func(t *testing.T) { + n := &Namespace{} + nn, _, _, err := n.ReadAll(user11, "", 1, -1) + namespaces := nn.([]*NamespaceWithLists) + assert.NoError(t, err) + // Assert the first namespace is not the favorites namespace + assert.NotEqual(t, SavedFiltersPseudoNamespace.ID, namespaces[0].ID) + }) } diff --git a/pkg/models/saved_filters.go b/pkg/models/saved_filters.go index f65a81403..9e7d1eef1 100644 --- a/pkg/models/saved_filters.go +++ b/pkg/models/saved_filters.go @@ -80,7 +80,7 @@ func getSavedFiltersForUser(auth web.Auth) (filters []*SavedFilter, err error) { return nil, ErrSavedFilterNotAvailableForLinkShare{LinkShareID: auth.GetID()} } - err = x.Where("owner_id = ?", auth.GetID()).Find(filters) + err = x.Where("owner_id = ?", auth.GetID()).Find(&filters) return } diff --git a/pkg/models/unit_tests.go b/pkg/models/unit_tests.go index 4fc373205..df3e83687 100644 --- a/pkg/models/unit_tests.go +++ b/pkg/models/unit_tests.go @@ -58,6 +58,7 @@ func SetupTests() { "users_list", "users_namespace", "buckets", + "saved_filters", ) if err != nil { log.Fatal(err)