1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00
focalboard/server/integrationtests/sharing_test.go
Scott Bishel 21667aa8d0
GH-2808: fix some logging issues with share board. (#2827)
* fix some logging issues

* fix unit test

* more test fixes

* unit test
2022-04-18 08:57:42 -06:00

99 lines
2.4 KiB
Go

package integrationtests
import (
"testing"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/utils"
"github.com/stretchr/testify/require"
)
func TestSharing(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
var boardID string
token := utils.NewID(utils.IDTypeToken)
t.Run("an unauthenticated client should not be able to get a sharing", func(t *testing.T) {
th.Logout(th.Client)
sharing, resp := th.Client.GetSharing("board-id")
th.CheckUnauthorized(resp)
require.Nil(t, sharing)
})
t.Run("Check no initial sharing", func(t *testing.T) {
th.Login1()
teamID := "0"
newBoard := &model.Board{
TeamID: teamID,
Type: model.BoardTypeOpen,
}
board, err := th.Server.App().CreateBoard(newBoard, th.GetUser1().ID, true)
require.NoError(t, err)
require.NotNil(t, board)
boardID = board.ID
s, err := th.Server.App().GetSharing(boardID)
require.NoError(t, err)
require.Nil(t, s)
sharing, resp := th.Client.GetSharing(boardID)
require.NoError(t, resp.Error)
require.NotNil(t, sharing)
require.False(t, sharing.Enabled)
require.Empty(t, sharing.ID)
})
t.Run("POST sharing, config = false", func(t *testing.T) {
sharing := model.Sharing{
ID: boardID,
Token: token,
Enabled: true,
UpdateAt: 1,
}
// it will fail with default config
success, resp := th.Client.PostSharing(&sharing)
require.False(t, success)
require.Error(t, resp.Error)
t.Run("GET sharing", func(t *testing.T) {
sharing, resp := th.Client.GetSharing(boardID)
// Expect empty sharing object
require.NoError(t, resp.Error)
require.NotNil(t, sharing)
require.False(t, sharing.Enabled)
require.Empty(t, sharing.ID)
require.Empty(t, sharing.Token)
})
})
t.Run("POST sharing, config = true", func(t *testing.T) {
th.Server.Config().EnablePublicSharedBoards = true
sharing := model.Sharing{
ID: boardID,
Token: token,
Enabled: true,
UpdateAt: 1,
}
// it will succeed with updated config
success, resp := th.Client.PostSharing(&sharing)
require.True(t, success)
require.NoError(t, resp.Error)
t.Run("GET sharing", func(t *testing.T) {
sharing, resp := th.Client.GetSharing(boardID)
require.NoError(t, resp.Error)
require.NotNil(t, sharing)
require.Equal(t, sharing.ID, boardID)
require.True(t, sharing.Enabled)
require.Equal(t, sharing.Token, token)
})
})
}