2020-10-21 11:32:13 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
"github.com/golang/mock/gomock"
|
2021-07-09 03:09:02 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
|
2020-10-21 11:32:13 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-07-09 03:09:02 +02:00
|
|
|
type blockError struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (be blockError) Error() string {
|
|
|
|
return be.msg
|
|
|
|
}
|
|
|
|
|
2021-07-08 16:36:43 +02:00
|
|
|
func TestInsertBlock(t *testing.T) {
|
2021-08-25 22:08:01 +02:00
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
|
|
|
block := model.Block{BoardID: boardID}
|
|
|
|
board := &model.Board{ID: boardID}
|
|
|
|
th.Store.EXPECT().GetBoard(boardID).Return(board, nil)
|
|
|
|
th.Store.EXPECT().InsertBlock(&block, "user-id-1").Return(nil)
|
|
|
|
th.Store.EXPECT().GetMembersForBoard(boardID).Return([]*model.BoardMember{}, nil)
|
|
|
|
err := th.App.InsertBlock(block, "user-id-1")
|
2021-07-08 16:36:43 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("error scenerio", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
|
|
|
block := model.Block{BoardID: boardID}
|
|
|
|
board := &model.Board{ID: boardID}
|
|
|
|
th.Store.EXPECT().GetBoard(boardID).Return(board, nil)
|
|
|
|
th.Store.EXPECT().InsertBlock(&block, "user-id-1").Return(blockError{"error"})
|
|
|
|
err := th.App.InsertBlock(block, "user-id-1")
|
2021-07-09 03:09:02 +02:00
|
|
|
require.Error(t, err, "error")
|
2021-07-08 16:36:43 +02:00
|
|
|
})
|
|
|
|
}
|
2021-12-10 15:17:00 +01:00
|
|
|
|
|
|
|
func TestPatchBlocks(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("patchBlocks success scenerio", func(t *testing.T) {
|
|
|
|
blockPatches := model.BlockPatchBatch{}
|
2022-03-22 15:24:34 +01:00
|
|
|
th.Store.EXPECT().PatchBlocks(gomock.Eq(&blockPatches), gomock.Eq("user-id-1")).Return(nil)
|
|
|
|
err := th.App.PatchBlocks("team-id", &blockPatches, "user-id-1")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("patchBlocks error scenerio", func(t *testing.T) {
|
|
|
|
blockPatches := model.BlockPatchBatch{}
|
2022-03-22 15:24:34 +01:00
|
|
|
th.Store.EXPECT().PatchBlocks(gomock.Eq(&blockPatches), gomock.Eq("user-id-1")).Return(blockError{"error"})
|
|
|
|
err := th.App.PatchBlocks("team-id", &blockPatches, "user-id-1")
|
2021-12-10 15:17:00 +01:00
|
|
|
require.Error(t, err, "error")
|
|
|
|
})
|
|
|
|
}
|
2022-02-22 18:42:49 +01:00
|
|
|
|
|
|
|
func TestDeleteBlock(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
|
|
|
board := &model.Board{ID: boardID}
|
2022-02-22 18:42:49 +01:00
|
|
|
block := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
ID: "block-id",
|
|
|
|
BoardID: board.ID,
|
2022-02-22 18:42:49 +01:00
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
th.Store.EXPECT().GetBlock(gomock.Eq("block-id")).Return(&block, nil)
|
|
|
|
th.Store.EXPECT().DeleteBlock(gomock.Eq("block-id"), gomock.Eq("user-id-1")).Return(nil)
|
|
|
|
th.Store.EXPECT().GetBoard(gomock.Eq(testBoardID)).Return(board, nil)
|
|
|
|
th.Store.EXPECT().GetMembersForBoard(boardID).Return([]*model.BoardMember{}, nil)
|
|
|
|
err := th.App.DeleteBlock("block-id", "user-id-1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("error scenerio", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
|
|
|
board := &model.Board{ID: boardID}
|
2022-02-22 18:42:49 +01:00
|
|
|
block := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
ID: "block-id",
|
|
|
|
BoardID: board.ID,
|
2022-02-22 18:42:49 +01:00
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
th.Store.EXPECT().GetBlock(gomock.Eq("block-id")).Return(&block, nil)
|
|
|
|
th.Store.EXPECT().DeleteBlock(gomock.Eq("block-id"), gomock.Eq("user-id-1")).Return(blockError{"error"})
|
|
|
|
th.Store.EXPECT().GetBoard(gomock.Eq(testBoardID)).Return(board, nil)
|
|
|
|
err := th.App.DeleteBlock("block-id", "user-id-1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.Error(t, err, "error")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUndeleteBlock(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
2022-03-22 15:24:34 +01:00
|
|
|
boardID := testBoardID
|
|
|
|
board := &model.Board{ID: boardID}
|
2022-02-22 18:42:49 +01:00
|
|
|
block := model.Block{
|
2022-03-22 15:24:34 +01:00
|
|
|
ID: "block-id",
|
|
|
|
BoardID: board.ID,
|
2022-02-22 18:42:49 +01:00
|
|
|
}
|
|
|
|
th.Store.EXPECT().GetBlockHistory(
|
|
|
|
gomock.Eq("block-id"),
|
|
|
|
gomock.Eq(model.QueryBlockHistoryOptions{Limit: 1, Descending: true}),
|
|
|
|
).Return([]model.Block{block}, nil)
|
2022-03-22 15:24:34 +01:00
|
|
|
th.Store.EXPECT().UndeleteBlock(gomock.Eq("block-id"), gomock.Eq("user-id-1")).Return(nil)
|
|
|
|
th.Store.EXPECT().GetBlock(gomock.Eq("block-id")).Return(&block, nil)
|
|
|
|
th.Store.EXPECT().GetBoard(boardID).Return(board, nil)
|
|
|
|
th.Store.EXPECT().GetMembersForBoard(boardID).Return([]*model.BoardMember{}, nil)
|
2022-04-05 17:00:04 +02:00
|
|
|
_, err := th.App.UndeleteBlock("block-id", "user-id-1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("error scenerio", func(t *testing.T) {
|
|
|
|
block := model.Block{
|
|
|
|
ID: "block-id",
|
|
|
|
}
|
|
|
|
th.Store.EXPECT().GetBlockHistory(
|
|
|
|
gomock.Eq("block-id"),
|
|
|
|
gomock.Eq(model.QueryBlockHistoryOptions{Limit: 1, Descending: true}),
|
|
|
|
).Return([]model.Block{block}, nil)
|
2022-03-22 15:24:34 +01:00
|
|
|
th.Store.EXPECT().UndeleteBlock(gomock.Eq("block-id"), gomock.Eq("user-id-1")).Return(blockError{"error"})
|
|
|
|
th.Store.EXPECT().GetBlock(gomock.Eq("block-id")).Return(&block, nil)
|
2022-04-05 17:00:04 +02:00
|
|
|
_, err := th.App.UndeleteBlock("block-id", "user-id-1")
|
2022-02-22 18:42:49 +01:00
|
|
|
require.Error(t, err, "error")
|
|
|
|
})
|
|
|
|
}
|