2021-01-29 21:27:43 +02: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 20:01:54 +02:00
|
|
|
container := store.Container{
|
2021-03-30 23:04:00 +02:00
|
|
|
WorkspaceID: "0",
|
2021-03-26 20:01:54 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 21:27:43 +02:00
|
|
|
t.Run("UpsertSharingAndGetSharing", func(t *testing.T) {
|
|
|
|
store, tearDown := setup(t)
|
|
|
|
defer tearDown()
|
2021-03-26 20:01:54 +02:00
|
|
|
testUpsertSharingAndGetSharing(t, store, container)
|
2021-01-29 21:27:43 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-26 20:01:54 +02:00
|
|
|
func testUpsertSharingAndGetSharing(t *testing.T, store store.Store, container store.Container) {
|
2021-01-29 21:27:43 +02:00
|
|
|
t.Run("Insert first sharing and get it", func(t *testing.T) {
|
|
|
|
sharing := model.Sharing{
|
|
|
|
ID: "sharing-id",
|
|
|
|
Enabled: true,
|
|
|
|
Token: "token",
|
2021-07-09 03:09:02 +02:00
|
|
|
ModifiedBy: testUserID,
|
2021-01-29 21:27:43 +02:00
|
|
|
}
|
|
|
|
|
2021-03-26 20:01:54 +02:00
|
|
|
err := store.UpsertSharing(container, sharing)
|
2021-01-29 21:27:43 +02:00
|
|
|
require.NoError(t, err)
|
2021-03-26 20:01:54 +02:00
|
|
|
newSharing, err := store.GetSharing(container, "sharing-id")
|
2021-01-29 21:27:43 +02: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 20:01:54 +02:00
|
|
|
newSharing, err := store.GetSharing(container, "sharing-id")
|
2021-01-29 21:27:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
newSharing.UpdateAt = 0
|
|
|
|
require.NotEqual(t, sharing, *newSharing)
|
|
|
|
|
2021-03-26 20:01:54 +02:00
|
|
|
err = store.UpsertSharing(container, sharing)
|
2021-01-29 21:27:43 +02:00
|
|
|
require.NoError(t, err)
|
2021-03-26 20:01:54 +02:00
|
|
|
newSharing, err = store.GetSharing(container, "sharing-id")
|
2021-01-29 21:27:43 +02: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 20:01:54 +02:00
|
|
|
_, err := store.GetSharing(container, "not-existing")
|
2021-01-29 21:27:43 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|