Merge pull request #2756 from wiggin77/add_remove_unit_tests

Add unit test for GetAllBlocksForBoard; remove integration test GetSubtree
This commit is contained in:
Scott Bishel 2022-04-09 08:43:31 -06:00 committed by GitHub
commit a19840a76a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 54 deletions

View file

@ -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)
})
}

View file

@ -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()