2020-10-21 11:32:13 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/mattermost/mattermost-octo-tasks/server/services/config"
|
|
|
|
"github.com/mattermost/mattermost-octo-tasks/server/services/store/mockstore"
|
2020-10-30 20:33:25 +02:00
|
|
|
"github.com/mattermost/mattermost-octo-tasks/server/services/webhook"
|
2020-10-21 11:32:13 +02:00
|
|
|
"github.com/mattermost/mattermost-octo-tasks/server/ws"
|
|
|
|
"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 22:32:51 +02:00
|
|
|
cfg := config.Configuration{}
|
2020-10-21 11:32:13 +02:00
|
|
|
store := mockstore.NewMockStore(ctrl)
|
2020-10-22 13:34:42 +02:00
|
|
|
wsserver := ws.NewServer()
|
2020-10-29 22:42:43 +02:00
|
|
|
webhook := webhook.NewClient(&cfg)
|
2020-10-29 22:32:51 +02:00
|
|
|
app := New(&cfg, store, wsserver, &mocks.FileBackend{}, webhook)
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2020-10-21 11:32:13 +02:00
|
|
|
t.Run("success query", func(t *testing.T) {
|
|
|
|
store.EXPECT().GetParentID(gomock.Eq("test-id")).Return("test-parent-id", nil)
|
|
|
|
result, err := app.GetParentID("test-id")
|
|
|
|
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) {
|
|
|
|
store.EXPECT().GetParentID(gomock.Eq("test-id")).Return("", errors.New("block-not-found"))
|
|
|
|
_, err := app.GetParentID("test-id")
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Equal(t, "block-not-found", err.Error())
|
|
|
|
})
|
|
|
|
}
|