2021-01-13 01:44:50 +01:00
|
|
|
package integrationtests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2021-01-13 01:44:50 +01:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSharing(t *testing.T) {
|
|
|
|
th := SetupTestHelper().InitBasic()
|
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-10-05 15:52:59 +02:00
|
|
|
rootID := utils.NewID(utils.IDTypeBlock)
|
|
|
|
token := utils.NewID(utils.IDTypeToken)
|
2021-01-13 01:44:50 +01:00
|
|
|
|
|
|
|
t.Run("Check no initial sharing", func(t *testing.T) {
|
|
|
|
sharing, resp := th.Client.GetSharing(rootID)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Empty(t, sharing.ID)
|
|
|
|
require.False(t, sharing.Enabled)
|
|
|
|
})
|
|
|
|
|
2022-01-28 18:35:38 +01:00
|
|
|
t.Run("POST sharing, config = false", func(t *testing.T) {
|
2021-01-13 01:44:50 +01:00
|
|
|
sharing := model.Sharing{
|
|
|
|
ID: rootID,
|
|
|
|
Token: token,
|
|
|
|
Enabled: true,
|
|
|
|
UpdateAt: 1,
|
|
|
|
}
|
|
|
|
|
2022-01-28 18:35:38 +01:00
|
|
|
// it will fail with default config
|
2021-01-13 01:44:50 +01:00
|
|
|
success, resp := th.Client.PostSharing(sharing)
|
2022-01-28 18:35:38 +01:00
|
|
|
require.False(t, success)
|
|
|
|
require.Error(t, resp.Error)
|
|
|
|
|
|
|
|
t.Run("GET sharing", func(t *testing.T) {
|
|
|
|
sharing, resp := th.Client.GetSharing(rootID)
|
|
|
|
// Expect no error, but no Id returned
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.NotNil(t, sharing)
|
|
|
|
require.Equal(t, "", sharing.ID)
|
|
|
|
})
|
2021-01-13 01:44:50 +01:00
|
|
|
})
|
|
|
|
|
2022-01-28 18:35:38 +01:00
|
|
|
t.Run("POST sharing, config = true", func(t *testing.T) {
|
|
|
|
th.Server.Config().EnablePublicSharedBoards = true
|
|
|
|
sharing := model.Sharing{
|
|
|
|
ID: rootID,
|
|
|
|
Token: token,
|
|
|
|
Enabled: true,
|
|
|
|
UpdateAt: 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
// it will succeed with updated config
|
|
|
|
success, resp := th.Client.PostSharing(sharing)
|
|
|
|
require.True(t, success)
|
2021-01-13 01:44:50 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-01-28 18:35:38 +01:00
|
|
|
|
|
|
|
t.Run("GET sharing", func(t *testing.T) {
|
|
|
|
sharing, resp := th.Client.GetSharing(rootID)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.NotNil(t, sharing)
|
|
|
|
require.Equal(t, sharing.ID, rootID)
|
|
|
|
require.True(t, sharing.Enabled)
|
|
|
|
require.Equal(t, sharing.Token, token)
|
|
|
|
})
|
2021-01-13 01:44:50 +01:00
|
|
|
})
|
|
|
|
}
|