2020-11-09 14:19:03 +02:00
|
|
|
package integrationtests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-01-27 00:13:46 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2020-11-09 14:19:03 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetBlocks(t *testing.T) {
|
|
|
|
th := SetupTestHelper().InitBasic()
|
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-01-06 05:47:18 +02:00
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
2021-10-05 15:52:59 +02:00
|
|
|
blockID1 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
blockID2 := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 14:19:03 +02:00
|
|
|
newBlocks := []model.Block{
|
|
|
|
{
|
|
|
|
ID: blockID1,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID1,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: blockID2,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID2,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
},
|
|
|
|
}
|
2021-01-06 05:47:18 +02:00
|
|
|
_, resp = th.Client.InsertBlocks(newBlocks)
|
2020-11-09 14:19:03 +02:00
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
2021-01-06 05:47:18 +02:00
|
|
|
blocks, resp = th.Client.GetBlocks()
|
2020-11-09 14:19:03 +02:00
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
require.Len(t, blocks, initialCount+2)
|
2020-11-09 14:19:03 +02: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) {
|
|
|
|
th := SetupTestHelper().InitBasic()
|
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-01-06 05:47:18 +02:00
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
2021-10-05 15:52:59 +02:00
|
|
|
blockID1 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
blockID2 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
blockID3 := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 14:19:03 +02:00
|
|
|
|
|
|
|
t.Run("Create a single block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: blockID1,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID1,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
Title: "New title",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.InsertBlocks([]model.Block{block})
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
require.Len(t, blocks, initialCount+1)
|
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, blockID1)
|
2020-11-09 14:19:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Create a couple of blocks in the same call", func(t *testing.T) {
|
|
|
|
newBlocks := []model.Block{
|
|
|
|
{
|
|
|
|
ID: blockID2,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID2,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: blockID3,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID3,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.InsertBlocks(newBlocks)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
require.Len(t, blocks, initialCount+3)
|
2020-11-09 14:19:03 +02: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)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Update a block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: blockID1,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID1,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 20,
|
|
|
|
Type: "board",
|
|
|
|
Title: "Updated title",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.InsertBlocks([]model.Block{block})
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
require.Len(t, blocks, initialCount+3)
|
2020-11-09 14:19:03 +02:00
|
|
|
|
|
|
|
var updatedBlock model.Block
|
|
|
|
for _, b := range blocks {
|
|
|
|
if b.ID == blockID1 {
|
|
|
|
updatedBlock = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotNil(t, updatedBlock)
|
|
|
|
require.Equal(t, "Updated title", updatedBlock.Title)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-06 14:10:24 +02:00
|
|
|
func TestPatchBlock(t *testing.T) {
|
|
|
|
th := SetupTestHelper().InitBasic()
|
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-10-05 15:52:59 +02:00
|
|
|
blockID := utils.NewID(utils.IDTypeBlock)
|
2021-08-06 14:10:24 +02:00
|
|
|
|
|
|
|
block := model.Block{
|
|
|
|
ID: blockID,
|
|
|
|
RootID: blockID,
|
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
Title: "New title",
|
|
|
|
Fields: map[string]interface{}{"test": "test value", "test2": "test value 2"},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.InsertBlocks([]model.Block{block})
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
|
|
|
t.Run("Patch a block basic field", func(t *testing.T) {
|
|
|
|
newTitle := "Updated title"
|
|
|
|
blockPatch := &model.BlockPatch{
|
|
|
|
Title: &newTitle,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.PatchBlock(blockID, blockPatch)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.PatchBlock(blockID, blockPatch)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
|
|
|
|
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"},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.PatchBlock(blockID, blockPatch)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, initialCount)
|
|
|
|
|
|
|
|
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 14:19:03 +02:00
|
|
|
func TestDeleteBlock(t *testing.T) {
|
|
|
|
th := SetupTestHelper().InitBasic()
|
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-01-06 05:47:18 +02:00
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
2021-10-05 15:52:59 +02:00
|
|
|
blockID := utils.NewID(utils.IDTypeBlock)
|
2020-11-09 14:19:03 +02:00
|
|
|
t.Run("Create a block", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: blockID,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: blockID,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
Title: "New title",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.InsertBlocks([]model.Block{block})
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
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)
|
2020-11-09 14:19:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Delete a block", func(t *testing.T) {
|
|
|
|
_, resp := th.Client.DeleteBlock(blockID)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
require.Len(t, blocks, initialCount)
|
2020-11-09 14:19:03 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetSubtree(t *testing.T) {
|
2021-09-21 19:25:45 +02:00
|
|
|
t.Skip("TODO: fix flaky test")
|
|
|
|
|
2020-11-09 14:19:03 +02:00
|
|
|
th := SetupTestHelper().InitBasic()
|
|
|
|
defer th.TearDown()
|
|
|
|
|
2021-01-06 05:47:18 +02:00
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
initialCount := len(blocks)
|
|
|
|
|
2021-10-05 15:52:59 +02:00
|
|
|
parentBlockID := utils.NewID(utils.IDTypeBlock)
|
|
|
|
childBlockID1 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
childBlockID2 := utils.NewID(utils.IDTypeBlock)
|
|
|
|
|
2020-11-09 14:19:03 +02:00
|
|
|
t.Run("Create the block structure", func(t *testing.T) {
|
|
|
|
newBlocks := []model.Block{
|
|
|
|
{
|
|
|
|
ID: parentBlockID,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: parentBlockID,
|
2020-11-09 14:19:03 +02:00
|
|
|
CreateAt: 1,
|
|
|
|
UpdateAt: 1,
|
|
|
|
Type: "board",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: childBlockID1,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: parentBlockID,
|
2020-11-09 14:19:03 +02:00
|
|
|
ParentID: parentBlockID,
|
|
|
|
CreateAt: 2,
|
|
|
|
UpdateAt: 2,
|
|
|
|
Type: "card",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: childBlockID2,
|
2021-01-06 05:47:18 +02:00
|
|
|
RootID: parentBlockID,
|
2020-11-09 14:19:03 +02:00
|
|
|
ParentID: parentBlockID,
|
|
|
|
CreateAt: 2,
|
|
|
|
UpdateAt: 2,
|
|
|
|
Type: "card",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, resp := th.Client.InsertBlocks(newBlocks)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
|
|
|
|
blocks, resp := th.Client.GetBlocks()
|
|
|
|
require.NoError(t, resp.Error)
|
2021-01-06 05:47:18 +02:00
|
|
|
require.Len(t, blocks, initialCount+1) // GetBlocks returns root blocks (null ParentID)
|
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, parentBlockID)
|
2020-11-09 14:19:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get subtree for parent ID", func(t *testing.T) {
|
|
|
|
blocks, resp := th.Client.GetSubtree(parentBlockID)
|
|
|
|
require.NoError(t, resp.Error)
|
|
|
|
require.Len(t, blocks, 3)
|
|
|
|
|
|
|
|
blockIDs := make([]string, len(blocks))
|
|
|
|
for i, b := range blocks {
|
|
|
|
blockIDs[i] = b.ID
|
|
|
|
}
|
|
|
|
require.Contains(t, blockIDs, parentBlockID)
|
|
|
|
require.Contains(t, blockIDs, childBlockID1)
|
|
|
|
require.Contains(t, blockIDs, childBlockID2)
|
|
|
|
})
|
|
|
|
}
|