mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-24 13:43:12 +02:00
110d9d4cfd
(cherry picked from commit 3625c53527
)
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package mattermostauthlayer
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
mockservicesapi "github.com/mattermost/focalboard/server/model/mocks"
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var errTest = errors.New("failed to patch bot")
|
|
|
|
func TestGetBoardsBotID(t *testing.T) {
|
|
ctrl := gomock.NewController(t)
|
|
servicesAPI := mockservicesapi.NewMockServicesAPI(ctrl)
|
|
mmAuthLayer, _ := New("test", nil, nil, mlog.CreateConsoleTestLogger(true, mlog.LvlError), servicesAPI, "")
|
|
|
|
servicesAPI.EXPECT().EnsureBot(model.FocalboardBot).Return("", errTest)
|
|
_, err := mmAuthLayer.getBoardsBotID()
|
|
require.NotEmpty(t, err)
|
|
|
|
servicesAPI.EXPECT().EnsureBot(model.FocalboardBot).Return("TestBotID", nil).Times(1)
|
|
botID, err := mmAuthLayer.getBoardsBotID()
|
|
require.Empty(t, err)
|
|
require.NotEmpty(t, botID)
|
|
require.Equal(t, "TestBotID", botID)
|
|
|
|
// Call again, should not call "EnsureBot"
|
|
botID, err = mmAuthLayer.getBoardsBotID()
|
|
require.Empty(t, err)
|
|
require.NotEmpty(t, botID)
|
|
require.Equal(t, "TestBotID", botID)
|
|
}
|