2020-11-09 13:19:03 +01:00
|
|
|
package integrationtests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-11-05 11:54:27 +01:00
|
|
|
"time"
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2020-11-09 13:19:03 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetBlocks(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
th := SetupTestHelperWithToken(t).Start()
|
2020-11-09 13:19:03 +01:00
|
|
|
defer th.TearDown()
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
2021-01-06 04:47:18 +01:00
|
|
|
|
2021-11-05 11:54:27 +01:00
|
|
|
initialID1 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
initialID2 := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 13:19:03 +01:00
|
|
|
newBlocks := []model.Block{
|
|
|
|
{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID1,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
},
|
|
|
|
{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID2,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
},
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2021-11-05 11:54:27 +01:00
|
|
|
require.Len(t, newBlocks, 2)
|
|
|
|
blockID1 := newBlocks[0].ID
|
|
|
|
blockID2 := newBlocks[1].ID
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 2)
|
2020-11-09 13:19:03 +01:00
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, blockID1)
|
|
|
|
require.Contains(t, blockIDs, blockID2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostBlock(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
th := SetupTestHelperWithToken(t).Start()
|
2020-11-09 13:19:03 +01:00
|
|
|
defer th.TearDown()
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
2021-01-06 04:47:18 +01:00
|
|
|
|
2021-11-05 11:54:27 +01:00
|
|
|
var blockID1 string
|
|
|
|
var blockID2 string
|
|
|
|
var blockID3 string
|
2020-11-09 13:19:03 +01:00
|
|
|
|
|
|
|
t.Run("Create a single block", func(t *testing.T) {
|
2021-11-05 11:54:27 +01:00
|
|
|
initialID1 := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 13:19:03 +01:00
|
|
|
block := model.Block{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID1,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
Title: "New title",
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block})
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2021-11-05 11:54:27 +01:00
|
|
|
require.Len(t, newBlocks, 1)
|
|
|
|
blockID1 = newBlocks[0].ID
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 1)
|
2021-01-06 04:47:18 +01:00
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, blockID1)
|
2020-11-09 13:19:03 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Create a couple of blocks in the same call", func(t *testing.T) {
|
2021-11-05 11:54:27 +01:00
|
|
|
initialID2 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
initialID3 := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 13:19:03 +01:00
|
|
|
newBlocks := []model.Block{
|
|
|
|
{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID2,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
},
|
|
|
|
{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID3,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2021-11-05 11:54:27 +01:00
|
|
|
require.Len(t, newBlocks, 2)
|
|
|
|
blockID2 = newBlocks[0].ID
|
|
|
|
blockID3 = newBlocks[1].ID
|
|
|
|
require.NotEqual(t, initialID2, blockID2)
|
|
|
|
require.NotEqual(t, initialID3, blockID3)
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 3)
|
2020-11-09 13:19:03 +01:00
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, blockID1)
|
|
|
|
require.Contains(t, blockIDs, blockID2)
|
|
|
|
require.Contains(t, blockIDs, blockID3)
|
|
|
|
})
|
|
|
|
|
2021-11-05 11:54:27 +01:00
|
|
|
t.Run("Update a block should not be possible through the insert endpoint", func(t *testing.T) {
|
2020-11-09 13:19:03 +01:00
|
|
|
block := model.Block{
|
|
|
|
ID: blockID1,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 20,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
Title: "Updated title",
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block})
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2021-11-05 11:54:27 +01:00
|
|
|
require.Len(t, newBlocks, 1)
|
|
|
|
blockID4 := newBlocks[0].ID
|
|
|
|
require.NotEqual(t, blockID1, blockID4)
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 4)
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2021-11-05 11:54:27 +01:00
|
|
|
var block4 model.Block
|
2020-11-09 13:19:03 +01:00
|
|
|
for _, b := range blocks {
|
2021-11-05 11:54:27 +01:00
|
|
|
if b.ID == blockID4 {
|
|
|
|
block4 = b
|
2020-11-09 13:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-05 11:54:27 +01:00
|
|
|
require.NotNil(t, block4)
|
|
|
|
require.Equal(t, "Updated title", block4.Title)
|
2020-11-09 13:19:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-06 14:10:24 +02:00
|
|
|
func TestPatchBlock(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
th := SetupTestHelperWithToken(t).Start()
|
2021-08-06 14:10:24 +02:00
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-11-05 11:54:27 +01:00
|
|
|
initialID := utils.NewID(utils.IDTypeBlock)
|
2021-08-06 14:10:24 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
2021-08-06 14:10:24 +02:00
|
|
|
block := model.Block{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2021-08-06 14:10:24 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2021-08-06 14:10:24 +02:00
|
|
|
Title: "New title",
|
|
|
|
Fields: map[string]interface{}{"test": "test value", "test2": "test value 2"},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block})
|
|
|
|
th.CheckOK(resp)
|
2021-11-05 11:54:27 +01:00
|
|
|
require.Len(t, newBlocks, 1)
|
|
|
|
blockID := newBlocks[0].ID
|
2021-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
t.Run("Patch a block basic field", func(t *testing.T) {
|
|
|
|
newTitle := "Updated title"
|
|
|
|
blockPatch := &model.BlockPatch{
|
|
|
|
Title: &newTitle,
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
_, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 1)
|
2021-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
var updatedBlock model.Block
|
|
|
|
for _, b := range blocks {
|
|
|
|
if b.ID == blockID {
|
|
|
|
updatedBlock = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotNil(t, updatedBlock)
|
|
|
|
require.Equal(t, "Updated title", updatedBlock.Title)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Patch a block custom fields", func(t *testing.T) {
|
|
|
|
blockPatch := &model.BlockPatch{
|
|
|
|
UpdatedFields: map[string]interface{}{
|
|
|
|
"test": "new test value",
|
|
|
|
"test3": "new field",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
_, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 1)
|
2021-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
var updatedBlock model.Block
|
|
|
|
for _, b := range blocks {
|
|
|
|
if b.ID == blockID {
|
|
|
|
updatedBlock = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotNil(t, updatedBlock)
|
|
|
|
require.Equal(t, "new test value", updatedBlock.Fields["test"])
|
|
|
|
require.Equal(t, "new field", updatedBlock.Fields["test3"])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Patch a block to remove custom fields", func(t *testing.T) {
|
|
|
|
blockPatch := &model.BlockPatch{
|
|
|
|
DeletedFields: []string{"test", "test3", "test100"},
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
_, resp := th.Client.PatchBlock(board.ID, blockID, blockPatch)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2021-08-06 14:10:24 +02:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 1)
|
2021-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
var updatedBlock model.Block
|
|
|
|
for _, b := range blocks {
|
|
|
|
if b.ID == blockID {
|
|
|
|
updatedBlock = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotNil(t, updatedBlock)
|
|
|
|
require.Equal(t, nil, updatedBlock.Fields["test"])
|
|
|
|
require.Equal(t, "test value 2", updatedBlock.Fields["test2"])
|
|
|
|
require.Equal(t, nil, updatedBlock.Fields["test3"])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-09 13:19:03 +01:00
|
|
|
func TestDeleteBlock(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
th := SetupTestHelperWithToken(t).Start()
|
2020-11-09 13:19:03 +01:00
|
|
|
defer th.TearDown()
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
2021-01-06 04:47:18 +01:00
|
|
|
|
2021-11-05 11:54:27 +01:00
|
|
|
var blockID string
|
2020-11-09 13:19:03 +01:00
|
|
|
t.Run("Create a block", func(t *testing.T) {
|
2021-11-05 11:54:27 +01:00
|
|
|
initialID := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 13:19:03 +01:00
|
|
|
block := model.Block{
|
2021-11-05 11:54:27 +01:00
|
|
|
ID: initialID,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2020-11-09 13:19:03 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
2022-03-22 15:24:34 +01:00
|
|
|
Type: model.TypeCard,
|
2020-11-09 13:19:03 +01:00
|
|
|
Title: "New title",
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block})
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2021-11-05 11:54:27 +01:00
|
|
|
require.Len(t, newBlocks, 1)
|
|
|
|
require.NotZero(t, newBlocks[0].ID)
|
|
|
|
require.NotEqual(t, initialID, newBlocks[0].ID)
|
|
|
|
blockID = newBlocks[0].ID
|
2020-11-09 13:19:03 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Len(t, blocks, 1)
|
2021-01-06 04:47:18 +01:00
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, blockID)
|
2020-11-09 13:19:03 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete a block", func(t *testing.T) {
|
2021-11-05 11:54:27 +01:00
|
|
|
// this avoids triggering uniqueness constraint of
|
|
|
|
// id,insert_at on block history
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
_, resp := th.Client.DeleteBlock(board.ID, blockID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2020-11-09 13:19:03 +01:00
|
|
|
require.NoError(t, resp.Error)
|
2022-03-22 15:24:34 +01:00
|
|
|
require.Empty(t, blocks)
|
2020-11-09 13:19:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-22 18:42:49 +01:00
|
|
|
func TestUndeleteBlock(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
th := SetupTestHelper(t).InitBasic()
|
2022-02-22 18:42:49 +01:00
|
|
|
defer th.TearDown()
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
|
|
|
var blockID string
|
|
|
|
t.Run("Create a block", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
initialID := utils.NewID(utils.IDTypeBoard)
|
2022-02-22 18:42:49 +01:00
|
|
|
block := model.Block{
|
|
|
|
ID: initialID,
|
2022-03-22 15:24:34 +01:00
|
|
|
BoardID: board.ID,
|
2022-02-22 18:42:49 +01:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: model.TypeBoard,
|
|
|
|
Title: "New title",
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
newBlocks, resp := th.Client.InsertBlocks(board.ID, []model.Block{block})
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, newBlocks, 1)
|
|
|
|
require.NotZero(t, newBlocks[0].ID)
|
|
|
|
require.NotEqual(t, initialID, newBlocks[0].ID)
|
|
|
|
blockID = newBlocks[0].ID
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount+1)
|
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, blockID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete a block", func(t *testing.T) {
|
|
|
|
// this avoids triggering uniqueness constraint of
|
|
|
|
// id,insert_at on block history
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
_, resp := th.Client.DeleteBlock(board.ID, blockID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Undelete a block", func(t *testing.T) {
|
|
|
|
// this avoids triggering uniqueness constraint of
|
|
|
|
// id,insert_at on block history
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
_, resp := th.Client.UndeleteBlock(board.ID, blockID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount+1)
|
|
|
|
})
|
2022-04-08 19:31:28 +02:00
|
|
|
|
|
|
|
t.Run("Try to undelete a block without permissions", func(t *testing.T) {
|
|
|
|
// this avoids triggering uniqueness constraint of
|
|
|
|
// id,insert_at on block history
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
|
|
|
|
_, resp := th.Client.DeleteBlock(board.ID, blockID)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
_, resp = th.Client2.UndeleteBlock(board.ID, blockID)
|
|
|
|
th.CheckForbidden(resp)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
})
|
2022-02-22 18:42:49 +01:00
|
|
|
}
|