2020-10-21 11:32:13 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
2021-02-02 21:06:28 +01:00
|
|
|
"github.com/mattermost/focalboard/server/auth"
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/config"
|
2021-03-26 19:01:54 +01:00
|
|
|
st "github.com/mattermost/focalboard/server/services/store"
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/store/mockstore"
|
|
|
|
"github.com/mattermost/focalboard/server/services/webhook"
|
|
|
|
"github.com/mattermost/focalboard/server/ws"
|
2020-10-21 11:32:13 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v5/services/filesstore/mocks"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetParentID(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
2020-10-29 21:32:51 +01:00
|
|
|
cfg := config.Configuration{}
|
2020-10-21 11:32:13 +02:00
|
|
|
store := mockstore.NewMockStore(ctrl)
|
2021-02-02 21:06:28 +01:00
|
|
|
auth := auth.New(&cfg, store)
|
2021-02-10 01:07:41 +01:00
|
|
|
sessionToken := "TESTTOKEN"
|
|
|
|
wsserver := ws.NewServer(auth, sessionToken)
|
2020-10-29 21:42:43 +01:00
|
|
|
webhook := webhook.NewClient(&cfg)
|
2021-02-02 21:11:21 +01:00
|
|
|
app := New(&cfg, store, auth, wsserver, &mocks.FileBackend{}, webhook)
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2021-03-26 19:01:54 +01:00
|
|
|
container := st.Container{
|
2021-03-30 23:04:00 +02:00
|
|
|
WorkspaceID: "0",
|
2021-03-26 19:01:54 +01:00
|
|
|
}
|
2020-10-21 11:32:13 +02:00
|
|
|
t.Run("success query", func(t *testing.T) {
|
2021-03-26 19:01:54 +01:00
|
|
|
store.EXPECT().GetParentID(gomock.Eq(container), gomock.Eq("test-id")).Return("test-parent-id", nil)
|
|
|
|
result, err := app.GetParentID(container, "test-id")
|
2020-10-21 11:32:13 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, "test-parent-id", result)
|
|
|
|
})
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2020-10-21 11:32:13 +02:00
|
|
|
t.Run("fail query", func(t *testing.T) {
|
2021-03-26 19:01:54 +01:00
|
|
|
store.EXPECT().GetParentID(gomock.Eq(container), gomock.Eq("test-id")).Return("", errors.New("block-not-found"))
|
|
|
|
_, err := app.GetParentID(container, "test-id")
|
2020-10-21 11:32:13 +02:00
|
|
|
require.Error(t, err)
|
|
|
|
require.Equal(t, "block-not-found", err.Error())
|
|
|
|
})
|
|
|
|
}
|