diff --git a/server/integrationtests/blocks_test.go b/server/integrationtests/blocks_test.go index 83471cb3d..9103def0e 100644 --- a/server/integrationtests/blocks_test.go +++ b/server/integrationtests/blocks_test.go @@ -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) - }) -} diff --git a/server/integrationtests/board_test.go b/server/integrationtests/board_test.go index b8e2dd448..831eded9a 100644 --- a/server/integrationtests/board_test.go +++ b/server/integrationtests/board_test.go @@ -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()