2022-03-31 00:10:11 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestApp_initializeTemplates(t *testing.T) {
|
|
|
|
board := &model.Board{
|
|
|
|
ID: utils.NewID(utils.IDTypeBoard),
|
2022-04-01 21:42:30 +02:00
|
|
|
TeamID: model.GlobalTeamID,
|
2022-03-31 00:10:11 +02:00
|
|
|
Type: model.BoardTypeOpen,
|
|
|
|
Title: "test board",
|
|
|
|
IsTemplate: true,
|
|
|
|
TemplateVersion: defaultTemplateVersion,
|
|
|
|
}
|
|
|
|
|
|
|
|
block := model.Block{
|
|
|
|
ID: utils.NewID(utils.IDTypeBlock),
|
|
|
|
ParentID: board.ID,
|
|
|
|
BoardID: board.ID,
|
|
|
|
Type: model.TypeText,
|
|
|
|
Title: "test text",
|
|
|
|
}
|
|
|
|
|
|
|
|
boardsAndBlocks := &model.BoardsAndBlocks{
|
|
|
|
Boards: []*model.Board{board},
|
|
|
|
Blocks: []model.Block{block},
|
|
|
|
}
|
|
|
|
|
2022-03-31 21:11:44 +02:00
|
|
|
boardMember := &model.BoardMember{
|
|
|
|
BoardID: board.ID,
|
|
|
|
UserID: "test-user",
|
|
|
|
}
|
|
|
|
|
2022-03-31 00:10:11 +02:00
|
|
|
t.Run("Needs template init", func(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
2022-04-01 21:42:30 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards(model.GlobalTeamID, "").Return([]*model.Board{}, nil)
|
2022-03-31 00:10:11 +02:00
|
|
|
th.Store.EXPECT().RemoveDefaultTemplates([]*model.Board{}).Return(nil)
|
|
|
|
th.Store.EXPECT().CreateBoardsAndBlocks(gomock.Any(), gomock.Any()).AnyTimes().Return(boardsAndBlocks, nil)
|
|
|
|
th.Store.EXPECT().GetMembersForBoard(board.ID).AnyTimes().Return([]*model.BoardMember{}, nil)
|
2022-03-31 21:11:44 +02:00
|
|
|
th.Store.EXPECT().GetBoard(board.ID).AnyTimes().Return(board, nil)
|
|
|
|
th.Store.EXPECT().GetMemberForBoard(gomock.Any(), gomock.Any()).AnyTimes().Return(boardMember, nil)
|
2022-03-31 00:10:11 +02:00
|
|
|
|
|
|
|
th.FilesBackend.On("WriteFile", mock.Anything, mock.Anything).Return(int64(1), nil)
|
|
|
|
|
|
|
|
done, err := th.App.initializeTemplates()
|
|
|
|
require.NoError(t, err, "initializeTemplates should not error")
|
|
|
|
require.True(t, done, "initialization was needed")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Skip template init", func(t *testing.T) {
|
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
|
|
|
|
2022-04-01 21:42:30 +02:00
|
|
|
th.Store.EXPECT().GetTemplateBoards(model.GlobalTeamID, "").Return([]*model.Board{board}, nil)
|
2022-03-31 00:10:11 +02:00
|
|
|
|
|
|
|
done, err := th.App.initializeTemplates()
|
|
|
|
require.NoError(t, err, "initializeTemplates should not error")
|
|
|
|
require.False(t, done, "initialization was not needed")
|
|
|
|
})
|
|
|
|
}
|