mirror of
https://github.com/aykhans/slash-e.git
synced 2026-09-24 23:06:48 +00:00
chore: update store tests
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package teststore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
|
||||
func TestCollectionStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ts := NewTestingStore(ctx, t)
|
||||
user, err := createTestingAdminUser(ctx, ts)
|
||||
require.NoError(t, err)
|
||||
collection, err := ts.CreateCollection(ctx, &storepb.Collection{
|
||||
CreatorId: user.ID,
|
||||
Name: "test",
|
||||
Title: "My collection",
|
||||
Description: "A test collection",
|
||||
ShortcutIds: []int32{101, 102},
|
||||
Visibility: storepb.Visibility_WORKSPACE,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
collections, err := ts.ListCollections(ctx, &store.FindCollection{
|
||||
CreatorID: &user.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(collections))
|
||||
require.Equal(t, collection, collections[0])
|
||||
newTitle := "My new collection"
|
||||
newShortcutIDs := []int32{101, 103}
|
||||
updatedCollection, err := ts.UpdateCollection(ctx, &store.UpdateCollection{
|
||||
ID: collection.Id,
|
||||
Title: &newTitle,
|
||||
ShortcutIDs: newShortcutIDs,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newTitle, updatedCollection.Title)
|
||||
require.Equal(t, newShortcutIDs, updatedCollection.ShortcutIds)
|
||||
err = ts.DeleteCollection(ctx, &store.DeleteCollection{
|
||||
ID: collection.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
collections, err = ts.ListCollections(ctx, &store.FindCollection{
|
||||
CreatorID: &user.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(collections))
|
||||
}
|
||||
Reference in New Issue
Block a user