1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00
focalboard/server/services/store/mattermostauthlayer/mattermostauthlayer_test.go
Scott Bishel cb4e5d9c39
Gh 3942 - fix bug with Boards bot, update link text (#4027)
* fix error when ensuring bot

* update link/unlink board text

* lint fixes
2022-10-19 09:22:55 -06:00

40 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)
}