Add test fixture for saved filters and fix existing tests
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2020-09-07 21:49:34 +02:00
parent 0691083646
commit c224289c93
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -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]

View File

@ -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)
})
}

View File

@ -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
}

View File

@ -58,6 +58,7 @@ func SetupTests() {
"users_list",
"users_namespace",
"buckets",
"saved_filters",
)
if err != nil {
log.Fatal(err)