focalboard/server/services/store/storetests/sharing.go

64 lines
1.7 KiB
Go
Raw Normal View History

2021-01-29 20:27:43 +01:00
package storetests
import (
"testing"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
"github.com/stretchr/testify/require"
)
func StoreTestSharingStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
2021-03-26 19:01:54 +01:00
container := store.Container{
2021-03-30 23:04:00 +02:00
WorkspaceID: "0",
2021-03-26 19:01:54 +01:00
}
2021-01-29 20:27:43 +01:00
t.Run("UpsertSharingAndGetSharing", func(t *testing.T) {
store, tearDown := setup(t)
defer tearDown()
2021-03-26 19:01:54 +01:00
testUpsertSharingAndGetSharing(t, store, container)
2021-01-29 20:27:43 +01:00
})
}
2021-03-26 19:01:54 +01:00
func testUpsertSharingAndGetSharing(t *testing.T, store store.Store, container store.Container) {
2021-01-29 20:27:43 +01:00
t.Run("Insert first sharing and get it", func(t *testing.T) {
sharing := model.Sharing{
ID: "sharing-id",
Enabled: true,
Token: "token",
ModifiedBy: testUserID,
2021-01-29 20:27:43 +01:00
}
2021-03-26 19:01:54 +01:00
err := store.UpsertSharing(container, sharing)
2021-01-29 20:27:43 +01:00
require.NoError(t, err)
2021-03-26 19:01:54 +01:00
newSharing, err := store.GetSharing(container, "sharing-id")
2021-01-29 20:27:43 +01:00
require.NoError(t, err)
newSharing.UpdateAt = 0
require.Equal(t, sharing, *newSharing)
})
t.Run("Upsert the inserted sharing and get it", func(t *testing.T) {
sharing := model.Sharing{
ID: "sharing-id",
Enabled: true,
Token: "token2",
ModifiedBy: "user-id2",
}
2021-03-26 19:01:54 +01:00
newSharing, err := store.GetSharing(container, "sharing-id")
2021-01-29 20:27:43 +01:00
require.NoError(t, err)
newSharing.UpdateAt = 0
require.NotEqual(t, sharing, *newSharing)
2021-03-26 19:01:54 +01:00
err = store.UpsertSharing(container, sharing)
2021-01-29 20:27:43 +01:00
require.NoError(t, err)
2021-03-26 19:01:54 +01:00
newSharing, err = store.GetSharing(container, "sharing-id")
2021-01-29 20:27:43 +01:00
require.NoError(t, err)
newSharing.UpdateAt = 0
require.Equal(t, sharing, *newSharing)
})
t.Run("Get not existing sharing", func(t *testing.T) {
2021-03-26 19:01:54 +01:00
_, err := store.GetSharing(container, "not-existing")
2021-01-29 20:27:43 +01:00
require.Error(t, err)
})
}