mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-21 13:38:56 +02:00
a4ef8ec6bc
* Initial permissions review infrastructure
* Adding more tests cases
* Modifying a bit the tests approach and adding more tests
* Adding more tests
* Adding more tests for permissions
* Adding more tests
* Adding more permissions tests
* Adding more tests
* Adding more permission checks
* Adding more permissions tests
* Adding more permission tests
* Adding more tests
* Adding subscriptions tests
* Adding more permissions tests
* Adding tests for read tokens in the files
* Update APIs and fix unit tests
* Fix linter errors
* Auto-assign category id from the database (as expected because is serial/auto_increment integer field)
* Revert "Auto-assign category id from the database (as expected because is serial/auto_increment integer field)"
This reverts commit 5c98fd76a3
.
* Fixing Category scheme in postgres and MySQL
* Removing restriction about the channel_id and add it to all the databases
* Moving everything to a new migration
* Fix bad merge (?)
* Update 000021_fix_categories.up.sql
Fix Postgres ALTER COLUMN syntax
* Update 000021_fix_categories.down.sql
Fix Postgres ALTER COLUMN syntax
* Update 000021_fix_categories.up.sql
Remove unnecessary, and unsupported MODIFY COLUMNs for SQLite.
* Update 000021_fix_categories.up.sql
Remove not null from categories.channel_id
* Update 000021_fix_categories.down.sql
Migrate down removing not null from categories.channel_id
* Update 000021_fix_categories.up.sql
Fix drop not null on categories.channel_id
* Update 000021_fix_categories.down.sql
Fix down migration of drop not null from categories.channel_id.
* Restore default notification level to debug
Co-authored-by: Chen-I Lim <chenilim@gmail.com>
Co-authored-by: Chen-I Lim <46905241+chenilim@users.noreply.github.com>
136 lines
4.4 KiB
Go
136 lines
4.4 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type blockError struct {
|
|
msg string
|
|
}
|
|
|
|
func (be blockError) Error() string {
|
|
return be.msg
|
|
}
|
|
|
|
func TestInsertBlock(t *testing.T) {
|
|
th, tearDown := SetupTestHelper(t)
|
|
defer tearDown()
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
|
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")
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("error scenerio", func(t *testing.T) {
|
|
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")
|
|
require.Error(t, err, "error")
|
|
})
|
|
}
|
|
|
|
func TestPatchBlocks(t *testing.T) {
|
|
th, tearDown := SetupTestHelper(t)
|
|
defer tearDown()
|
|
|
|
t.Run("patchBlocks success scenerio", func(t *testing.T) {
|
|
blockPatches := model.BlockPatchBatch{}
|
|
th.Store.EXPECT().PatchBlocks(gomock.Eq(&blockPatches), gomock.Eq("user-id-1")).Return(nil)
|
|
err := th.App.PatchBlocks("team-id", &blockPatches, "user-id-1")
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("patchBlocks error scenerio", func(t *testing.T) {
|
|
blockPatches := model.BlockPatchBatch{}
|
|
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")
|
|
require.Error(t, err, "error")
|
|
})
|
|
}
|
|
|
|
func TestDeleteBlock(t *testing.T) {
|
|
th, tearDown := SetupTestHelper(t)
|
|
defer tearDown()
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
|
boardID := testBoardID
|
|
board := &model.Board{ID: boardID}
|
|
block := model.Block{
|
|
ID: "block-id",
|
|
BoardID: board.ID,
|
|
}
|
|
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")
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("error scenerio", func(t *testing.T) {
|
|
boardID := testBoardID
|
|
board := &model.Board{ID: boardID}
|
|
block := model.Block{
|
|
ID: "block-id",
|
|
BoardID: board.ID,
|
|
}
|
|
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")
|
|
require.Error(t, err, "error")
|
|
})
|
|
}
|
|
|
|
func TestUndeleteBlock(t *testing.T) {
|
|
th, tearDown := SetupTestHelper(t)
|
|
defer tearDown()
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
|
boardID := testBoardID
|
|
board := &model.Board{ID: boardID}
|
|
block := model.Block{
|
|
ID: "block-id",
|
|
BoardID: board.ID,
|
|
}
|
|
th.Store.EXPECT().GetBlockHistory(
|
|
gomock.Eq("block-id"),
|
|
gomock.Eq(model.QueryBlockHistoryOptions{Limit: 1, Descending: true}),
|
|
).Return([]model.Block{block}, nil)
|
|
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)
|
|
_, err := th.App.UndeleteBlock("block-id", "user-id-1")
|
|
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)
|
|
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)
|
|
_, err := th.App.UndeleteBlock("block-id", "user-id-1")
|
|
require.Error(t, err, "error")
|
|
})
|
|
}
|