2022-02-28 13:28:16 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-10-26 13:08:03 +02:00
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
|
|
|
2022-02-28 13:28:16 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
const (
|
|
|
|
testTeamID = "team_id"
|
|
|
|
)
|
|
|
|
|
2022-02-28 13:28:16 +02:00
|
|
|
func TestPrepareOnboardingTour(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("base case", func(t *testing.T) {
|
2022-03-22 16:24:34 +02:00
|
|
|
teamID := testTeamID
|
|
|
|
userID := "user_id_1"
|
|
|
|
welcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Welcome to Boards!",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
2022-02-28 13:28:16 +02:00
|
|
|
}
|
|
|
|
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
|
2022-10-26 13:08:03 +02:00
|
|
|
th.Store.EXPECT().DuplicateBoard(welcomeBoard.ID, userID, teamID, false).Return(&model.BoardsAndBlocks{Boards: []*model.Board{
|
|
|
|
{
|
|
|
|
ID: "board_id_2",
|
|
|
|
Title: "Welcome to Boards!",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
|
|
|
},
|
|
|
|
}},
|
2022-03-22 16:24:34 +02:00
|
|
|
nil, nil)
|
2022-10-26 13:08:03 +02:00
|
|
|
th.Store.EXPECT().GetMembersForBoard(welcomeBoard.ID).Return([]*model.BoardMember{}, nil).Times(2)
|
|
|
|
th.Store.EXPECT().GetMembersForBoard("board_id_2").Return([]*model.BoardMember{}, nil).Times(1)
|
|
|
|
th.Store.EXPECT().GetBoard(welcomeBoard.ID).Return(&welcomeBoard, nil).Times(1)
|
|
|
|
th.Store.EXPECT().GetBoard("board_id_2").Return(&welcomeBoard, nil).Times(1)
|
2022-11-02 22:07:10 +02:00
|
|
|
th.Store.EXPECT().GetUsersByTeam("0", "", false, false).Return([]*model.User{}, nil)
|
2022-03-31 10:28:30 +02:00
|
|
|
|
|
|
|
privateWelcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Welcome to Boards!",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
|
|
|
Type: model.BoardTypePrivate,
|
|
|
|
}
|
|
|
|
newType := model.BoardTypePrivate
|
2022-10-26 13:08:03 +02:00
|
|
|
th.Store.EXPECT().PatchBoard("board_id_2", &model.BoardPatch{Type: &newType}, "user_id_1").Return(&privateWelcomeBoard, nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
|
2022-09-15 13:58:20 +02:00
|
|
|
userPreferencesPatch := model.UserPreferencesPatch{
|
2022-02-28 13:28:16 +02:00
|
|
|
UpdatedFields: map[string]string{
|
|
|
|
KeyOnboardingTourStarted: "1",
|
|
|
|
KeyOnboardingTourStep: ValueOnboardingFirstStep,
|
|
|
|
KeyOnboardingTourCategory: ValueTourCategoryOnboarding,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-09-15 13:58:20 +02:00
|
|
|
th.Store.EXPECT().PatchUserPreferences(userID, userPreferencesPatch).Return(nil, nil)
|
2022-10-26 13:08:03 +02:00
|
|
|
th.Store.EXPECT().GetUserCategoryBoards(userID, "team_id").Return([]model.CategoryBoards{}, nil).Times(1)
|
|
|
|
|
|
|
|
// when this is called the second time, the default category is created so we need to include that in the response list
|
|
|
|
th.Store.EXPECT().GetUserCategoryBoards(userID, "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{ID: "boards_category_id", Name: "Boards"},
|
|
|
|
},
|
|
|
|
}, nil).Times(1)
|
|
|
|
|
|
|
|
th.Store.EXPECT().CreateCategory(utils.Anything).Return(nil).Times(1)
|
|
|
|
th.Store.EXPECT().GetCategory(utils.Anything).Return(&model.Category{
|
|
|
|
ID: "boards_category",
|
|
|
|
Name: "Boards",
|
|
|
|
}, nil)
|
|
|
|
th.Store.EXPECT().GetBoardsForUserAndTeam("user_id_1", teamID, false).Return([]*model.Board{}, nil)
|
|
|
|
th.Store.EXPECT().AddUpdateCategoryBoard("user_id_1", "boards_category_id", "board_id_2").Return(nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
teamID, boardID, err := th.App.PrepareOnboardingTour(userID, teamID)
|
2022-02-28 13:28:16 +02:00
|
|
|
assert.NoError(t, err)
|
2022-03-22 16:24:34 +02:00
|
|
|
assert.Equal(t, testTeamID, teamID)
|
2022-02-28 13:28:16 +02:00
|
|
|
assert.NotEmpty(t, boardID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateWelcomeBoard(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("base case", func(t *testing.T) {
|
2022-03-22 16:24:34 +02:00
|
|
|
teamID := testTeamID
|
|
|
|
userID := "user_id_1"
|
|
|
|
welcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Welcome to Boards!",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
2022-02-28 13:28:16 +02:00
|
|
|
}
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
|
2022-03-22 16:24:34 +02:00
|
|
|
th.Store.EXPECT().DuplicateBoard(welcomeBoard.ID, userID, teamID, false).
|
|
|
|
Return(&model.BoardsAndBlocks{Boards: []*model.Board{&welcomeBoard}}, nil, nil)
|
2022-09-05 00:51:31 +02:00
|
|
|
th.Store.EXPECT().GetMembersForBoard(welcomeBoard.ID).Return([]*model.BoardMember{}, nil).Times(3)
|
2022-04-25 18:37:57 +02:00
|
|
|
th.Store.EXPECT().GetBoard(welcomeBoard.ID).Return(&welcomeBoard, nil).AnyTimes()
|
2022-11-02 22:07:10 +02:00
|
|
|
th.Store.EXPECT().GetUsersByTeam("0", "", false, false).Return([]*model.User{}, nil)
|
2022-04-25 18:37:57 +02:00
|
|
|
|
2022-03-31 11:44:57 +02:00
|
|
|
privateWelcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Welcome to Boards!",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
|
|
|
Type: model.BoardTypePrivate,
|
|
|
|
}
|
|
|
|
newType := model.BoardTypePrivate
|
|
|
|
th.Store.EXPECT().PatchBoard("board_id_1", &model.BoardPatch{Type: &newType}, "user_id_1").Return(&privateWelcomeBoard, nil)
|
2022-10-26 13:08:03 +02:00
|
|
|
th.Store.EXPECT().GetUserCategoryBoards(userID, "team_id").Return([]model.CategoryBoards{
|
|
|
|
{
|
|
|
|
Category: model.Category{ID: "boards_category_id", Name: "Boards"},
|
|
|
|
},
|
|
|
|
}, nil).Times(2)
|
|
|
|
th.Store.EXPECT().AddUpdateCategoryBoard("user_id_1", "boards_category_id", "board_id_1").Return(nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
boardID, err := th.App.createWelcomeBoard(userID, teamID)
|
2022-02-28 13:28:16 +02:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.NotEmpty(t, boardID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("template doesn't contain a board", func(t *testing.T) {
|
2022-03-22 16:24:34 +02:00
|
|
|
teamID := testTeamID
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{}, nil)
|
2022-03-22 16:24:34 +02:00
|
|
|
boardID, err := th.App.createWelcomeBoard("user_id_1", teamID)
|
2022-02-28 13:28:16 +02:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, boardID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("template doesn't contain the welcome board", func(t *testing.T) {
|
2022-03-22 16:24:34 +02:00
|
|
|
teamID := testTeamID
|
|
|
|
welcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Other template",
|
|
|
|
TeamID: teamID,
|
|
|
|
IsTemplate: true,
|
2022-02-28 13:28:16 +02:00
|
|
|
}
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
boardID, err := th.App.createWelcomeBoard("user_id_1", "workspace_id_1")
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, boardID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetOnboardingBoardID(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
|
|
|
t.Run("base case", func(t *testing.T) {
|
2022-03-22 16:24:34 +02:00
|
|
|
welcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Welcome to Boards!",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
2022-02-28 13:28:16 +02:00
|
|
|
}
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
|
|
|
|
onboardingBoardID, err := th.App.getOnboardingBoardID()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "board_id_1", onboardingBoardID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no blocks found", func(t *testing.T) {
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{}, nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
|
|
|
|
onboardingBoardID, err := th.App.getOnboardingBoardID()
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, onboardingBoardID)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("onboarding board doesn't exists", func(t *testing.T) {
|
2022-03-22 16:24:34 +02:00
|
|
|
welcomeBoard := model.Board{
|
|
|
|
ID: "board_id_1",
|
|
|
|
Title: "Other template",
|
|
|
|
TeamID: "0",
|
|
|
|
IsTemplate: true,
|
2022-02-28 13:28:16 +02:00
|
|
|
}
|
2022-03-29 07:46:16 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards("0", "").Return([]*model.Board{&welcomeBoard}, nil)
|
2022-02-28 13:28:16 +02:00
|
|
|
|
|
|
|
onboardingBoardID, err := th.App.getOnboardingBoardID()
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, onboardingBoardID)
|
|
|
|
})
|
|
|
|
}
|