Add TestGetTemplates integration test (#2635)

* Add TestGetTemplates integration test

* Use t.Logf instead of fmt

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Chen-I Lim 2022-03-29 15:55:39 -07:00 committed by GitHub
parent c3a4921ac3
commit 9f82537f9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 3 deletions

View file

@ -188,6 +188,10 @@ func (c *Client) GetBlocksRoute(boardID string) string {
return fmt.Sprintf("%s/blocks", c.GetBoardRoute(boardID))
}
func (c *Client) GetAllBlocksRoute(boardID string) string {
return fmt.Sprintf("%s/blocks?all=true", c.GetBoardRoute(boardID))
}
func (c *Client) GetBoardsAndBlocksRoute() string {
return "/boards-and-blocks"
}
@ -212,6 +216,16 @@ func (c *Client) GetBlocksForBoard(boardID string) ([]model.Block, *Response) {
return model.BlocksFromJSON(r.Body), BuildResponse(r)
}
func (c *Client) GetAllBlocksForBoard(boardID string) ([]model.Block, *Response) {
r, err := c.DoAPIGet(c.GetAllBlocksRoute(boardID), "")
if err != nil {
return nil, BuildErrorResponse(r, err)
}
defer closeBody(r)
return model.BlocksFromJSON(r.Body), BuildResponse(r)
}
func (c *Client) PatchBlock(boardID, blockID string, blockPatch *model.BlockPatch) (bool, *Response) {
r, err := c.DoAPIPatch(c.GetBlockRoute(boardID, blockID), toJSON(blockPatch))
if err != nil {
@ -222,18 +236,21 @@ func (c *Client) PatchBlock(boardID, blockID string, blockPatch *model.BlockPatc
return true, BuildResponse(r)
}
func (c *Client) DuplicateBoard(boardID string, asTemplate bool, teamID string) (bool, *Response) {
func (c *Client) DuplicateBoard(boardID string, asTemplate bool, teamID string) (*model.BoardsAndBlocks, *Response) {
queryParams := "?asTemplate=false&"
if asTemplate {
queryParams = "?asTemplate=true"
}
if len(teamID) > 0 {
queryParams = queryParams + "&toTeam=" + teamID
}
r, err := c.DoAPIPost(c.GetBoardRoute(boardID)+"/duplicate"+queryParams, "")
if err != nil {
return false, BuildErrorResponse(r, err)
return nil, BuildErrorResponse(r, err)
}
defer closeBody(r)
return true, BuildResponse(r)
return model.BoardsAndBlocksFromJSON(r.Body), BuildResponse(r)
}
func (c *Client) DuplicateBlock(boardID, blockID string, asTemplate bool) (bool, *Response) {
@ -646,3 +663,13 @@ func (c *Client) GetSubscriptions(subscriberID string) ([]*model.Subscription, *
return subs, BuildResponse(r)
}
func (c *Client) GetTemplatesForTeam(teamID string) ([]*model.Board, *Response) {
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/templates", "")
if err != nil {
return nil, BuildErrorResponse(r, err)
}
defer closeBody(r)
return model.BoardsFromJSON(r.Body), BuildResponse(r)
}

View file

@ -1450,6 +1450,56 @@ func TestDeleteMember(t *testing.T) {
})
}
func TestGetTemplates(t *testing.T) {
t.Run("should be able to retrieve built-in templates", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
teamID := "my-team-id"
rBoards, resp := th.Client.GetTemplatesForTeam("0")
th.CheckOK(resp)
require.NotNil(t, rBoards)
require.GreaterOrEqual(t, len(rBoards), 6)
t.Log("\n\n")
for _, board := range rBoards {
t.Logf("Test get template: %s - %s\n", board.Title, board.ID)
rBoard, resp := th.Client.GetBoard(board.ID, "")
th.CheckOK(resp)
require.NotNil(t, rBoard)
require.Equal(t, board, rBoard)
rBlocks, resp := th.Client.GetAllBlocksForBoard(board.ID)
th.CheckOK(resp)
require.NotNil(t, rBlocks)
require.Greater(t, len(rBlocks), 0)
t.Logf("Got %d block(s)\n", len(rBlocks))
rBoardsAndBlock, resp := th.Client.DuplicateBoard(board.ID, false, teamID)
th.CheckOK(resp)
require.NotNil(t, rBoardsAndBlock)
require.Greater(t, len(rBoardsAndBlock.Boards), 0)
require.Greater(t, len(rBoardsAndBlock.Blocks), 0)
rBoard2 := rBoardsAndBlock.Boards[0]
require.Contains(t, board.Title, rBoard2.Title)
require.False(t, rBoard2.IsTemplate)
t.Logf("Duplicate template: %s - %s, %d block(s)\n", rBoard2.Title, rBoard2.ID, len(rBoardsAndBlock.Blocks))
rBoard3, resp := th.Client.GetBoard(rBoard2.ID, "")
th.CheckOK(resp)
require.NotNil(t, rBoard3)
require.Equal(t, rBoard2, rBoard3)
rBlocks2, resp := th.Client.GetAllBlocksForBoard(rBoard2.ID)
th.CheckOK(resp)
require.NotNil(t, rBlocks2)
require.Equal(t, len(rBoardsAndBlock.Blocks), len(rBlocks2))
}
t.Log("\n\n")
})
}
func TestJoinBoard(t *testing.T) {
t.Run("create and join public board", func(t *testing.T) {
th := SetupTestHelper(t).InitBasic()