2022-10-26 13:08:03 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetUserCategoryBoards(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("user had no default category and had boards", func(t *testing.T) {
|
2023-01-24 12:11:54 +02:00
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{}, nil).Times(1)
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Type: model.CategoryTypeSystem,
|
|
|
|
Name: "Boards",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil).Times(1)
|
2022-10-26 13:08:03 +02:00
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
|
|
|
|
2022-12-14 10:51:53 +02:00
|
|
|
board1 := &model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
}
|
|
|
|
|
|
|
|
board2 := &model.Board{
|
|
|
|
ID: "board_id_2",
|
|
|
|
}
|
|
|
|
|
|
|
|
board3 := &model.Board{
|
|
|
|
ID: "board_id_3",
|
|
|
|
}
|
|
|
|
|
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{board1, board2, board3}, nil)
|
|
|
|
|
2022-11-24 11:30:06 +02:00
|
|
|
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
|
|
|
{
|
|
|
|
BoardID: "board_id_1",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_2",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_3",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
}, nil)
|
2023-02-14 18:17:33 +02:00
|
|
|
th.Store.EXPECT().GetBoard(utils.Anything).Return(nil, nil).Times(3)
|
2023-01-24 12:11:54 +02:00
|
|
|
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", []string{"board_id_1", "board_id_2", "board_id_3"}).Return(nil)
|
2022-10-26 13:08:03 +02:00
|
|
|
|
|
|
|
categoryBoards, err := th.App.GetUserCategoryBoards("user_id", "team_id")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(categoryBoards))
|
|
|
|
assert.Equal(t, "Boards", categoryBoards[0].Name)
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 3, len(categoryBoards[0].BoardMetadata))
|
|
|
|
assert.Contains(t, categoryBoards[0].BoardMetadata, model.CategoryBoardMetadata{BoardID: "board_id_1", Hidden: false})
|
|
|
|
assert.Contains(t, categoryBoards[0].BoardMetadata, model.CategoryBoardMetadata{BoardID: "board_id_2", Hidden: false})
|
|
|
|
assert.Contains(t, categoryBoards[0].BoardMetadata, model.CategoryBoardMetadata{BoardID: "board_id_3", Hidden: false})
|
2022-10-26 13:08:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("user had no default category BUT had no boards", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{}, nil)
|
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
|
|
|
|
2022-11-24 11:30:06 +02:00
|
|
|
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil)
|
2022-12-14 10:51:53 +02:00
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil)
|
2022-10-26 13:08:03 +02:00
|
|
|
|
|
|
|
categoryBoards, err := th.App.GetUserCategoryBoards("user_id", "team_id")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(categoryBoards))
|
|
|
|
assert.Equal(t, "Boards", categoryBoards[0].Name)
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 0, len(categoryBoards[0].BoardMetadata))
|
2022-10-26 13:08:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("user already had a default Boards category with boards in it", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{Name: "Boards"},
|
2023-01-24 12:11:54 +02:00
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{
|
|
|
|
{BoardID: "board_id_1", Hidden: false},
|
|
|
|
{BoardID: "board_id_2", Hidden: false},
|
|
|
|
},
|
2022-10-26 13:08:03 +02:00
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
categoryBoards, err := th.App.GetUserCategoryBoards("user_id", "team_id")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(categoryBoards))
|
|
|
|
assert.Equal(t, "Boards", categoryBoards[0].Name)
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 2, len(categoryBoards[0].BoardMetadata))
|
2022-10-26 13:08:03 +02:00
|
|
|
})
|
|
|
|
}
|
2022-11-24 10:21:17 +02:00
|
|
|
|
|
|
|
func TestCreateBoardsCategory(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("user doesn't have any boards - implicit or explicit", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Type: "system",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
2022-12-14 10:51:53 +02:00
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil)
|
2022-11-24 10:21:17 +02:00
|
|
|
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{}, nil)
|
|
|
|
|
|
|
|
existingCategoryBoards := []model.CategoryBoards{}
|
|
|
|
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, boardsCategory)
|
|
|
|
assert.Equal(t, "Boards", boardsCategory.Name)
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 0, len(boardsCategory.BoardMetadata))
|
2022-11-24 10:21:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("user has implicit access to some board", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Type: "system",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
2022-12-14 10:51:53 +02:00
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{}, nil)
|
2022-11-24 10:21:17 +02:00
|
|
|
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
|
|
|
{
|
|
|
|
BoardID: "board_id_1",
|
|
|
|
Synthetic: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_2",
|
|
|
|
Synthetic: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_3",
|
|
|
|
Synthetic: true,
|
|
|
|
},
|
|
|
|
}, nil)
|
2023-02-14 18:17:33 +02:00
|
|
|
th.Store.EXPECT().GetBoard(utils.Anything).Return(nil, nil).Times(3)
|
2022-11-24 10:21:17 +02:00
|
|
|
|
|
|
|
existingCategoryBoards := []model.CategoryBoards{}
|
|
|
|
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, boardsCategory)
|
|
|
|
assert.Equal(t, "Boards", boardsCategory.Name)
|
|
|
|
|
|
|
|
// there should still be no boards in the default category as
|
|
|
|
// the user had only implicit access to boards
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 0, len(boardsCategory.BoardMetadata))
|
2022-11-24 10:21:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("user has explicit access to some board", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Type: "system",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
2022-12-14 10:51:53 +02:00
|
|
|
|
|
|
|
board1 := &model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
}
|
|
|
|
board2 := &model.Board{
|
|
|
|
ID: "board_id_2",
|
|
|
|
}
|
|
|
|
board3 := &model.Board{
|
|
|
|
ID: "board_id_3",
|
|
|
|
}
|
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{board1, board2, board3}, nil)
|
2022-11-24 10:21:17 +02:00
|
|
|
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
|
|
|
{
|
|
|
|
BoardID: "board_id_1",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_2",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_3",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
}, nil)
|
2023-02-14 18:17:33 +02:00
|
|
|
th.Store.EXPECT().GetBoard(utils.Anything).Return(nil, nil).Times(3)
|
2023-01-24 12:11:54 +02:00
|
|
|
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", []string{"board_id_1", "board_id_2", "board_id_3"}).Return(nil)
|
|
|
|
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{
|
|
|
|
Type: model.CategoryTypeSystem,
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Name: "Boards",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil)
|
2022-11-24 10:21:17 +02:00
|
|
|
|
|
|
|
existingCategoryBoards := []model.CategoryBoards{}
|
|
|
|
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, boardsCategory)
|
|
|
|
assert.Equal(t, "Boards", boardsCategory.Name)
|
|
|
|
|
|
|
|
// since user has explicit access to three boards,
|
|
|
|
// they should all end up in the default category
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 3, len(boardsCategory.BoardMetadata))
|
2022-11-24 10:21:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("user has both implicit and explicit access to some board", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Type: "system",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
2022-12-14 10:51:53 +02:00
|
|
|
|
|
|
|
board1 := &model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
}
|
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id", "team_id", false).Return([]*model.Board{board1}, nil)
|
2022-11-24 10:21:17 +02:00
|
|
|
th.Store.EXPECT().GetMembersForUser("user_id").Return([]*model.BoardMember{
|
|
|
|
{
|
|
|
|
BoardID: "board_id_1",
|
|
|
|
Synthetic: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_2",
|
|
|
|
Synthetic: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BoardID: "board_id_3",
|
|
|
|
Synthetic: true,
|
|
|
|
},
|
|
|
|
}, nil)
|
2023-02-14 18:17:33 +02:00
|
|
|
th.Store.EXPECT().GetBoard(utils.Anything).Return(nil, nil).Times(3)
|
2023-01-24 12:11:54 +02:00
|
|
|
th.Store.EXPECT().AddUpdateCategoryBoard("user_id", "boards_category_id", []string{"board_id_1"}).Return(nil)
|
|
|
|
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{
|
|
|
|
Type: model.CategoryTypeSystem,
|
|
|
|
ID: "boards_category_id",
|
|
|
|
Name: "Boards",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil)
|
2022-11-24 10:21:17 +02:00
|
|
|
|
|
|
|
existingCategoryBoards := []model.CategoryBoards{}
|
|
|
|
boardsCategory, err := th.App.createBoardsCategory("user_id", "team_id", existingCategoryBoards)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, boardsCategory)
|
|
|
|
assert.Equal(t, "Boards", boardsCategory.Name)
|
|
|
|
|
|
|
|
// there was only one explicit board access,
|
|
|
|
// and so only that one should end up in the
|
|
|
|
// default category
|
2023-01-24 12:11:54 +02:00
|
|
|
assert.Equal(t, 1, len(boardsCategory.BoardMetadata))
|
2022-11-24 10:21:17 +02:00
|
|
|
})
|
|
|
|
}
|
2022-12-14 10:51:53 +02:00
|
|
|
|
|
|
|
func TestReorderCategoryBoards(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("base case", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{ID: "category_id_1", Name: "Category 1"},
|
2023-01-24 12:11:54 +02:00
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{
|
|
|
|
{BoardID: "board_id_1", Hidden: false},
|
|
|
|
{BoardID: "board_id_2", Hidden: false},
|
|
|
|
},
|
2022-12-14 10:51:53 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Category: model.Category{ID: "category_id_2", Name: "Boards", Type: "system"},
|
2023-01-24 12:11:54 +02:00
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{
|
|
|
|
{BoardID: "board_id_3", Hidden: false},
|
|
|
|
},
|
2022-12-14 10:51:53 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-24 12:11:54 +02:00
|
|
|
Category: model.Category{ID: "category_id_3", Name: "Category 3"},
|
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{},
|
2022-12-14 10:51:53 +02:00
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
th.Store.EXPECT().ReorderCategoryBoards("category_id_1", []string{"board_id_2", "board_id_1"}).Return([]string{"board_id_2", "board_id_1"}, nil)
|
|
|
|
|
|
|
|
newOrder, err := th.App.ReorderCategoryBoards("user_id", "team_id", "category_id_1", []string{"board_id_2", "board_id_1"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, len(newOrder))
|
|
|
|
assert.Equal(t, "board_id_2", newOrder[0])
|
|
|
|
assert.Equal(t, "board_id_1", newOrder[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not specifying all boards", func(t *testing.T) {
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards("user_id", "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{ID: "category_id_1", Name: "Category 1"},
|
2023-01-24 12:11:54 +02:00
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{
|
|
|
|
{BoardID: "board_id_1", Hidden: false},
|
|
|
|
{BoardID: "board_id_2", Hidden: false},
|
|
|
|
{BoardID: "board_id_3", Hidden: false},
|
|
|
|
},
|
2022-12-14 10:51:53 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Category: model.Category{ID: "category_id_2", Name: "Boards", Type: "system"},
|
2023-01-24 12:11:54 +02:00
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{
|
|
|
|
{BoardID: "board_id_3", Hidden: false},
|
|
|
|
},
|
2022-12-14 10:51:53 +02:00
|
|
|
},
|
|
|
|
{
|
2023-01-24 12:11:54 +02:00
|
|
|
Category: model.Category{ID: "category_id_3", Name: "Category 3"},
|
|
|
|
BoardMetadata: []model.CategoryBoardMetadata{},
|
2022-12-14 10:51:53 +02:00
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
newOrder, err := th.App.ReorderCategoryBoards("user_id", "team_id", "category_id_1", []string{"board_id_2", "board_id_1"})
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, newOrder)
|
|
|
|
})
|
|
|
|
}
|