08c0b7a2fd
* Refactor error usage from the store level up and add API helpers * Complete API tests * Fix merge errorResponse calls * Remove ensure helpers to allow for custom messages on permission errors * Fix bad import and call * Remove bad user check on auth that was added as part of the main merge * Fix empty list test * Replace deprecated proxy calls to ioutil.ReadAll with io.ReadAll * Add information to the NotFound errors * Add context to all remaining errors and address review comments * Fix linter * Adapt the new card API endpoints to the error refactor * Remove almost all customErrorResponse calls * Add request entity too large to errorResponse and remove customErrorResponse * Fix linter
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
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())) {
|
|
t.Run("UpsertSharingAndGetSharing", func(t *testing.T) {
|
|
store, tearDown := setup(t)
|
|
defer tearDown()
|
|
testUpsertSharingAndGetSharing(t, store)
|
|
})
|
|
}
|
|
|
|
func testUpsertSharingAndGetSharing(t *testing.T, store store.Store) {
|
|
t.Run("Insert first sharing and get it", func(t *testing.T) {
|
|
sharing := model.Sharing{
|
|
ID: "sharing-id",
|
|
Enabled: true,
|
|
Token: "token",
|
|
ModifiedBy: testUserID,
|
|
}
|
|
|
|
err := store.UpsertSharing(sharing)
|
|
require.NoError(t, err)
|
|
newSharing, err := store.GetSharing("sharing-id")
|
|
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",
|
|
}
|
|
|
|
newSharing, err := store.GetSharing("sharing-id")
|
|
require.NoError(t, err)
|
|
newSharing.UpdateAt = 0
|
|
require.NotEqual(t, sharing, *newSharing)
|
|
|
|
err = store.UpsertSharing(sharing)
|
|
require.NoError(t, err)
|
|
newSharing, err = store.GetSharing("sharing-id")
|
|
require.NoError(t, err)
|
|
newSharing.UpdateAt = 0
|
|
require.Equal(t, sharing, *newSharing)
|
|
})
|
|
t.Run("Get not existing sharing", func(t *testing.T) {
|
|
_, err := store.GetSharing("not-existing")
|
|
require.Error(t, err)
|
|
require.True(t, model.IsErrNotFound(err))
|
|
})
|
|
}
|