2020-10-21 11:32:13 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-09 03:09:02 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
|
2020-10-21 11:32:13 +02:00
|
|
|
"github.com/golang/mock/gomock"
|
2021-03-26 19:01:54 +01:00
|
|
|
st "github.com/mattermost/focalboard/server/services/store"
|
2020-10-21 11:32:13 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-07-09 03:09:02 +02:00
|
|
|
type blockError struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (be blockError) Error() string {
|
|
|
|
return be.msg
|
|
|
|
}
|
|
|
|
|
2020-10-21 11:32:13 +02:00
|
|
|
func TestGetParentID(t *testing.T) {
|
2021-08-25 22:08:01 +02:00
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
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-05-26 12:38:43 +02:00
|
|
|
th.Store.EXPECT().GetParentID(gomock.Eq(container), gomock.Eq("test-id")).Return("test-parent-id", nil)
|
|
|
|
result, err := th.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-07-09 03:09:02 +02:00
|
|
|
th.Store.EXPECT().GetParentID(gomock.Eq(container), gomock.Eq("test-id")).Return("", blockError{"block-not-found"})
|
2021-05-26 12:38:43 +02:00
|
|
|
_, err := th.App.GetParentID(container, "test-id")
|
2020-10-21 11:32:13 +02:00
|
|
|
require.Error(t, err)
|
2021-07-09 03:09:02 +02:00
|
|
|
require.ErrorIs(t, err, blockError{"block-not-found"})
|
2020-10-21 11:32:13 +02:00
|
|
|
})
|
|
|
|
}
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
func TestInsertBlock(t *testing.T) {
|
2021-08-25 22:08:01 +02:00
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
container := st.Container{
|
|
|
|
WorkspaceID: "0",
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("success scenerio", func(t *testing.T) {
|
|
|
|
block := model.Block{}
|
|
|
|
th.Store.EXPECT().InsertBlock(gomock.Eq(container), gomock.Eq(&block), gomock.Eq("user-id-1")).Return(nil)
|
|
|
|
err := th.App.InsertBlock(container, block, "user-id-1")
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("error scenerio", func(t *testing.T) {
|
|
|
|
block := model.Block{}
|
2021-07-09 03:09:02 +02:00
|
|
|
th.Store.EXPECT().InsertBlock(gomock.Eq(container), gomock.Eq(&block), gomock.Eq("user-id-1")).Return(blockError{"error"})
|
2021-07-08 16:36:43 +02:00
|
|
|
err := th.App.InsertBlock(container, block, "user-id-1")
|
2021-07-09 03:09:02 +02:00
|
|
|
require.Error(t, err, "error")
|
2021-07-08 16:36:43 +02:00
|
|
|
})
|
|
|
|
}
|