Merge pull request #2756 from wiggin77/add_remove_unit_tests
Add unit test for GetAllBlocksForBoard; remove integration test GetSubtree
This commit is contained in:
commit
a19840a76a
2 changed files with 63 additions and 54 deletions
|
@ -392,57 +392,3 @@ func TestUndeleteBlock(t *testing.T) {
|
|||
require.Len(t, blocks, initialCount)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetSubtree(t *testing.T) {
|
||||
t.Skip("TODO: fix flaky test")
|
||||
|
||||
th := SetupTestHelperWithToken(t).Start()
|
||||
defer th.TearDown()
|
||||
|
||||
board := th.CreateBoard("team-id", model.BoardTypeOpen)
|
||||
|
||||
parentBlockID := utils.NewID(utils.IDTypeBlock)
|
||||
childBlockID1 := utils.NewID(utils.IDTypeBlock)
|
||||
childBlockID2 := utils.NewID(utils.IDTypeBlock)
|
||||
|
||||
t.Run("Create the block structure", func(t *testing.T) {
|
||||
newBlocks := []model.Block{
|
||||
{
|
||||
ID: parentBlockID,
|
||||
BoardID: board.ID,
|
||||
CreateAt: 1,
|
||||
UpdateAt: 1,
|
||||
Type: model.TypeCard,
|
||||
},
|
||||
{
|
||||
ID: childBlockID1,
|
||||
BoardID: board.ID,
|
||||
ParentID: parentBlockID,
|
||||
CreateAt: 2,
|
||||
UpdateAt: 2,
|
||||
Type: model.TypeCard,
|
||||
},
|
||||
{
|
||||
ID: childBlockID2,
|
||||
BoardID: board.ID,
|
||||
ParentID: parentBlockID,
|
||||
CreateAt: 2,
|
||||
UpdateAt: 2,
|
||||
Type: model.TypeCard,
|
||||
},
|
||||
}
|
||||
|
||||
_, resp := th.Client.InsertBlocks(board.ID, newBlocks)
|
||||
require.NoError(t, resp.Error)
|
||||
|
||||
blocks, resp := th.Client.GetBlocksForBoard(board.ID)
|
||||
require.NoError(t, resp.Error)
|
||||
require.Len(t, blocks, 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)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package integrationtests
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -255,6 +256,68 @@ func TestCreateBoard(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestGetAllBlocksForBoard(t *testing.T) {
|
||||
th := SetupTestHelperWithToken(t).Start()
|
||||
defer th.TearDown()
|
||||
|
||||
board := th.CreateBoard("board-id", model.BoardTypeOpen)
|
||||
|
||||
parentBlockID := utils.NewID(utils.IDTypeBlock)
|
||||
childBlockID1 := utils.NewID(utils.IDTypeBlock)
|
||||
childBlockID2 := utils.NewID(utils.IDTypeBlock)
|
||||
|
||||
t.Run("Create the block structure", func(t *testing.T) {
|
||||
newBlocks := []model.Block{
|
||||
{
|
||||
ID: parentBlockID,
|
||||
BoardID: board.ID,
|
||||
CreateAt: 1,
|
||||
UpdateAt: 1,
|
||||
Type: model.TypeCard,
|
||||
},
|
||||
{
|
||||
ID: childBlockID1,
|
||||
BoardID: board.ID,
|
||||
ParentID: parentBlockID,
|
||||
CreateAt: 2,
|
||||
UpdateAt: 2,
|
||||
Type: model.TypeCard,
|
||||
},
|
||||
{
|
||||
ID: childBlockID2,
|
||||
BoardID: board.ID,
|
||||
ParentID: parentBlockID,
|
||||
CreateAt: 2,
|
||||
UpdateAt: 2,
|
||||
Type: model.TypeCard,
|
||||
},
|
||||
}
|
||||
|
||||
insertedBlocks, resp := th.Client.InsertBlocks(board.ID, newBlocks)
|
||||
require.NoError(t, resp.Error)
|
||||
require.Len(t, insertedBlocks, len(newBlocks))
|
||||
|
||||
insertedBlockIDs := make([]string, len(insertedBlocks))
|
||||
for i, b := range insertedBlocks {
|
||||
insertedBlockIDs[i] = b.ID
|
||||
}
|
||||
|
||||
fetchedBlocks, resp := th.Client.GetAllBlocksForBoard(board.ID)
|
||||
require.NoError(t, resp.Error)
|
||||
require.Len(t, fetchedBlocks, len(newBlocks))
|
||||
|
||||
fetchedblockIDs := make([]string, len(fetchedBlocks))
|
||||
for i, b := range fetchedBlocks {
|
||||
fetchedblockIDs[i] = b.ID
|
||||
}
|
||||
|
||||
sort.Strings(insertedBlockIDs)
|
||||
sort.Strings(fetchedblockIDs)
|
||||
|
||||
require.Equal(t, insertedBlockIDs, fetchedblockIDs)
|
||||
})
|
||||
}
|
||||
|
||||
func TestSearchBoards(t *testing.T) {
|
||||
t.Run("a non authenticated user should be rejected", func(t *testing.T) {
|
||||
th := SetupTestHelper(t).InitBasic()
|
||||
|
|
Loading…
Reference in a new issue