Adding changes to separate unit tests and integration tests (#13670)

* Introducing unit (not integration) tests for the app layer

* Initial support for unit tests at the API

* Adding unit tests support to the store layer

* Add unit tests support in commands

* Adding last tests needed for run unit tests properly

* Fixing govet

* Removing some duplication

* Fixing tests

* Fixing tests

* Not compiling test helpers with the main module for api

* Revert "Not compiling test helpers with the main module for api"

This reverts commit 36a199bbe0f7503f665f5d6c7b41c53aabc2e54f.

* Fixing tests

* Fixing unit tests

* More consistency between api4/apiteslib.go and app/helper_test.go

* Renaming things to make more obvious the new Setup functions purpose

* Reverting change in go.sum

* Start with empty mock for app layer

* Start with empty mock for api layer

* Start with empty mock for web layer

* Renaming SetupWithStoreMockConfig to SetupConfigWithStoreMock

* Fixing tests on web package

* Removing unnecesary function
Этот коммит содержится в:
Jesús Espino
2020-03-02 17:13:39 +01:00
коммит произвёл GitHub
родитель cd36c9f041
Коммит 7035e09fe9
27 изменённых файлов: 720 добавлений и 187 удалений

Просмотреть файл

@@ -9,8 +9,10 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
)
/* Temporarily comment out until MM-11108
@@ -26,10 +28,21 @@ func TestAppRace(t *testing.T) {
}
*/
func TestUpdateConfig(t *testing.T) {
th := Setup(t)
func TestUnitUpdateConfig(t *testing.T) {
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*mocks.Store)
mockUserStore := mocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := mocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := mocks.SystemStore{}
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
prev := *th.App.Config().ServiceSettings.SiteURL
th.App.AddConfigListener(func(old, current *model.Config) {

Просмотреть файл

@@ -9,9 +9,11 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/sqlstore"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/utils"
)
@@ -51,22 +53,33 @@ func TestConfigListener(t *testing.T) {
}
func TestAsymmetricSigningKey(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
assert.NotNil(t, th.App.AsymmetricSigningKey())
assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
}
func TestPostActionCookieSecret(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
}
func TestClientConfigWithComputed(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*mocks.Store)
mockUserStore := mocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := mocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := mocks.SystemStore{}
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
config := th.App.ClientConfigWithComputed()
_, ok := config["NoAccounts"]
assert.True(t, ok, "expected NoAccounts in returned config")

Просмотреть файл

@@ -14,7 +14,7 @@ import (
)
func TestHandleNewNotifications(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
id1 := model.NewId()
@@ -265,7 +265,7 @@ func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
* Ensures that post contents are not included in notification email when email notification content type is set to generic
*/
func TestRenderBatchedPostGeneric(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
var post = &model.Post{}
@@ -290,7 +290,7 @@ func TestRenderBatchedPostGeneric(t *testing.T) {
* Ensures that post contents included in notification email when email notification content type is set to full
*/
func TestRenderBatchedPostFull(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
var post = &model.Post{}

Просмотреть файл

@@ -9,7 +9,9 @@ import (
"github.com/mattermost/mattermost-server/v5/einterfaces"
"github.com/mattermost/mattermost-server/v5/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v5/model"
storemocks "github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestSAMLSettings(t *testing.T) {
@@ -93,9 +95,20 @@ func TestSAMLSettings(t *testing.T) {
RegisterNewSamlInterface(nil)
}
th := SetupEnterprise(t)
th := SetupEnterpriseWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*storemocks.Store)
mockUserStore := storemocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := storemocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := storemocks.SystemStore{}
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
if tc.useNewSAMLLibrary {
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ExperimentalSettings.UseNewSAMLLibrary = tc.useNewSAMLLibrary

Просмотреть файл

@@ -44,7 +44,7 @@ func TestReactionsOfPost(t *testing.T) {
}
func TestExportUserNotifyProps(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
userNotifyProps := model.StringMap{
@@ -112,7 +112,7 @@ func TestExportUserChannels(t *testing.T) {
}
func TestDirCreationForEmoji(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
pathToDir := th.App.createDirForEmoji("test.json", "exported_emoji_test")
@@ -122,7 +122,7 @@ func TestDirCreationForEmoji(t *testing.T) {
}
func TestCopyEmojiImages(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
emoji := &model.Emoji{

Просмотреть файл

@@ -15,6 +15,9 @@ import (
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/testlib"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/stretchr/testify/require"
)
@@ -33,10 +36,7 @@ type TestHelper struct {
tempWorkspace string
}
func setupTestHelper(enterprise bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
store := mainHelper.GetStore()
store.DropAllTables()
func setupTestHelper(dbStore store.Store, enterprise bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
tempWorkspace, err := ioutil.TempDir("", "apptest")
if err != nil {
panic(err)
@@ -57,7 +57,7 @@ func setupTestHelper(enterprise bool, tb testing.TB, configSet func(*model.Confi
var options []Option
options = append(options, ConfigStore(memoryStore))
options = append(options, StoreOverride(mainHelper.Store))
options = append(options, StoreOverride(dbStore))
options = append(options, SetLogger(mlog.NewTestingLogger(tb)))
s, err := NewServer(options...)
@@ -80,9 +80,6 @@ func setupTestHelper(enterprise bool, tb testing.TB, configSet func(*model.Confi
}
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
th.App.Srv().Store.MarkSystemRanUnitTests()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
// Disable strict password requirements for test
@@ -108,15 +105,54 @@ func setupTestHelper(enterprise bool, tb testing.TB, configSet func(*model.Confi
}
func SetupEnterprise(tb testing.TB) *TestHelper {
return setupTestHelper(true, tb, nil)
if testing.Short() {
tb.SkipNow()
}
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
return setupTestHelper(dbStore, true, tb, nil)
}
func Setup(tb testing.TB) *TestHelper {
return setupTestHelper(false, tb, nil)
if testing.Short() {
tb.SkipNow()
}
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
return setupTestHelper(dbStore, false, tb, nil)
}
func SetupWithStoreMock(tb testing.TB) *TestHelper {
mockStore := testlib.GetMockStoreForSetupFunctions()
th := setupTestHelper(mockStore, false, tb, nil)
emptyMockStore := mocks.Store{}
emptyMockStore.On("Close").Return(nil)
th.App.Srv().Store = &emptyMockStore
return th
}
func SetupEnterpriseWithStoreMock(tb testing.TB) *TestHelper {
mockStore := testlib.GetMockStoreForSetupFunctions()
th := setupTestHelper(mockStore, true, tb, nil)
emptyMockStore := mocks.Store{}
emptyMockStore.On("Close").Return(nil)
th.App.Srv().Store = &emptyMockStore
return th
}
func SetupWithCustomConfig(tb testing.TB, configSet func(*model.Config)) *TestHelper {
return setupTestHelper(false, tb, configSet)
if testing.Short() {
tb.SkipNow()
}
dbStore := mainHelper.GetStore()
dbStore.DropAllTables()
dbStore.MarkSystemRanUnitTests()
return setupTestHelper(dbStore, false, tb, configSet)
}
func (me *TestHelper) InitBasic() *TestHelper {

Просмотреть файл

@@ -15,13 +15,11 @@ import (
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/services/timezones"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/utils"
)
func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] New Direct Message from @sender on"
user := &model.User{}
post := &model.Post{
@@ -33,9 +31,6 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
}
func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) {
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] New Group Message in sender on"
user := &model.User{}
post := &model.Post{
@@ -48,9 +43,6 @@ func TestGetGroupMessageNotificationEmailSubjectFull(t *testing.T) {
}
func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) {
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] New Group Message on"
user := &model.User{}
post := &model.Post{
@@ -63,9 +55,6 @@ func TestGetGroupMessageNotificationEmailSubjectGeneric(t *testing.T) {
}
func TestGetNotificationEmailSubject(t *testing.T) {
th := Setup(t)
defer th.TearDown()
expectedPrefix := "[http://localhost:8065] Notification in team on"
user := &model.User{}
post := &model.Post{
@@ -77,7 +66,7 @@ func TestGetNotificationEmailSubject(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -90,11 +79,16 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new notification.", fmt.Sprintf("Expected email text 'You have a new notification. Got %s", body))
require.Contains(t, body, "Channel: "+channel.DisplayName, "Expected email text 'Channel: %s'. Got %s", channel.DisplayName, body)
@@ -104,7 +98,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -117,11 +111,16 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new Group Message.", fmt.Sprintf("Expected email text 'You have a new Group Message. Got "+body))
require.Contains(t, body, "Channel: ChannelName", fmt.Sprintf("Expected email text 'Channel: ChannelName'. Got %s", body))
@@ -131,7 +130,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -144,11 +143,16 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new notification.", fmt.Sprintf("Expected email text 'You have a new notification. Got "+body))
require.Contains(t, body, "Channel: "+channel.DisplayName, fmt.Sprintf("Expected email text 'Channel: "+channel.DisplayName+"'. Got "+body))
@@ -158,7 +162,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -171,11 +175,16 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new Direct Message.", fmt.Sprintf("Expected email text 'You have a new Direct Message. Got "+body))
require.Contains(t, body, senderName+" - ", fmt.Sprintf("Expected email text '%s - '. Got %s", senderName, body))
@@ -184,7 +193,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{
@@ -201,11 +210,16 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testi
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, false, translateFunc)
r, _ := regexp.Compile("E([S|D]+)T")
zone := r.FindString(body)
@@ -213,7 +227,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeWithTimezone(t *testi
}
func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{
@@ -229,11 +243,16 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
tm := time.Unix(post.CreateAt/1000, 0)
zone, _ := tm.Zone()
@@ -253,7 +272,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTimeNoTimezone(t *testing
}
func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{
@@ -270,18 +289,23 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime12Hour(t *testing.T)
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, false, translateFunc)
require.Contains(t, body, "sender - 2:30 PM", fmt.Sprintf("Expected email text 'sender - 2:30 PM'. Got %s", body))
require.Contains(t, body, "April 25", fmt.Sprintf("Expected email text 'April 25'. Got %s", body))
}
func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{
@@ -298,11 +322,16 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T)
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "sender - 14:30", fmt.Sprintf("Expected email text 'sender - 14:30'. Got %s", body))
require.Contains(t, body, "April 25", fmt.Sprintf("Expected email text 'April 25'. Got %s", body))
@@ -310,7 +339,7 @@ func TestGetNotificationEmailBodyFullNotificationLocaleTime24Hour(t *testing.T)
// from here
func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -323,11 +352,16 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new notification from "+senderName, fmt.Sprintf("Expected email text 'You have a new notification from %s'. Got %s", senderName, body))
require.False(t, strings.Contains(body, "Channel: "+channel.DisplayName), fmt.Sprintf("Did not expect email text 'CHANNEL: %s'. Got %s", channel.DisplayName, body))
@@ -336,7 +370,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
}
func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -349,11 +383,16 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new Group Message from "+senderName, fmt.Sprintf("Expected email text 'You have a new Group Message from %s'. Got %s", senderName, body))
require.False(t, strings.Contains(body, "CHANNEL: "+channel.DisplayName), fmt.Sprintf("Did not expect email text 'CHANNEL: %s'. Got %s", channel.DisplayName, body))
@@ -362,7 +401,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
}
func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -375,11 +414,16 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new notification from "+senderName, fmt.Sprintf("Expected email text 'You have a new notification from %s'. Got %s", senderName, body))
require.False(t, strings.Contains(body, "CHANNEL: "+channel.DisplayName), fmt.Sprintf("Did not expect email text 'CHANNEL: %s'. Got %s", channel.DisplayName, body))
@@ -388,7 +432,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
}
func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -401,11 +445,16 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T)
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, "You have a new Direct Message from "+senderName, fmt.Sprintf("Expected email text 'You have a new Direct Message from "+senderName+"'. Got "+body))
require.False(t, strings.Contains(body, "CHANNEL: "+channel.DisplayName), fmt.Sprintf("Did not expect email text 'CHANNEL: %s'. Got %s", channel.DisplayName, body))
@@ -414,7 +463,7 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T)
}
func TestGetNotificationEmailEscapingChars(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := &model.Channel{
@@ -429,35 +478,59 @@ func TestGetNotificationEmailEscapingChars(t *testing.T) {
}
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, ch,
channelName, senderName, teamName, teamURL,
emailNotificationContentsType, true, translateFunc)
fmt.Println(body)
assert.NotContains(t, body, message)
}
func TestGetNotificationEmailBodyPublicChannelMention(t *testing.T) {
th := Setup(t).InitBasic()
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := th.BasicChannel
recipient := th.BasicUser2
ch := &model.Channel{
Name: "channelname",
DisplayName: "ChannelName",
Type: model.CHANNEL_OPEN,
}
id := model.NewId()
recipient := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
post := &model.Post{
Message: "This is the message ~" + ch.Name,
}
senderName := th.BasicUser.Username
teamName := th.BasicTeam.Name
teamURL := "http://localhost:8065/" + teamName
senderName := "user1"
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Id: "test", Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
channelStoreMock := mocks.ChannelStore{}
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
storeMock.On("Channel").Return(&channelStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, ch,
ch.Name, senderName, teamName, teamURL,
emailNotificationContentsType, true, translateFunc)
@@ -467,31 +540,62 @@ func TestGetNotificationEmailBodyPublicChannelMention(t *testing.T) {
}
func TestGetNotificationEmailBodyMultiPublicChannelMention(t *testing.T) {
th := Setup(t).InitBasic()
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := th.BasicChannel
ch := &model.Channel{
Id: model.NewId(),
Name: "channelnameone",
DisplayName: "ChannelName",
Type: model.CHANNEL_OPEN,
}
mention := "~" + ch.Name
ch2 := th.CreateChannel(th.BasicTeam)
ch2 := &model.Channel{
Id: model.NewId(),
Name: "channelnametwo",
DisplayName: "ChannelName2",
Type: model.CHANNEL_OPEN,
}
mention2 := "~" + ch2.Name
ch3 := th.CreateChannel(th.BasicTeam)
ch3 := &model.Channel{
Id: model.NewId(),
Name: "channelnamethree",
DisplayName: "ChannelName3",
Type: model.CHANNEL_OPEN,
}
mention3 := "~" + ch3.Name
message := fmt.Sprintf("This is the message Channel1: %s; Channel2: %s;"+
" Channel3: %s", mention, mention2, mention3)
recipient := th.BasicUser2
id := model.NewId()
recipient := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
post := &model.Post{
Message: message,
}
senderName := th.BasicUser.Username
teamName := th.BasicTeam.Name
teamURL := "http://localhost:8065/" + teamName
senderName := "user1"
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Id: "test", Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
channelStoreMock := mocks.ChannelStore{}
channelStoreMock.On("GetByNames", "test", []string{ch.Name, ch2.Name, ch3.Name}, true).Return([]*model.Channel{ch, ch2, ch3}, nil)
storeMock.On("Channel").Return(&channelStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, ch,
ch.Name, senderName, teamName, teamURL,
emailNotificationContentsType, true, translateFunc)
@@ -505,21 +609,41 @@ func TestGetNotificationEmailBodyMultiPublicChannelMention(t *testing.T) {
}
func TestGetNotificationEmailBodyPrivateChannelMention(t *testing.T) {
th := Setup(t).InitBasic()
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := th.CreatePrivateChannel(th.BasicTeam)
recipient := th.BasicUser2
ch := &model.Channel{
Name: "channelname",
DisplayName: "ChannelName",
Type: model.CHANNEL_PRIVATE,
}
id := model.NewId()
recipient := &model.User{
Email: "success+" + id + "@simulator.amazonses.com",
Username: "un_" + id,
Nickname: "nn_" + id,
Password: "Password1",
EmailVerified: true,
}
post := &model.Post{
Message: "This is the message ~" + ch.Name,
}
senderName := th.BasicUser.Username
teamName := ch.Name
teamURL := "http://localhost:8065/" + teamName
senderName := "user1"
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Id: "test", Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
channelStoreMock := mocks.ChannelStore{}
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
storeMock.On("Channel").Return(&channelStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, ch,
ch.Name, senderName, teamName, teamURL,
emailNotificationContentsType, true, translateFunc)
@@ -529,15 +653,28 @@ func TestGetNotificationEmailBodyPrivateChannelMention(t *testing.T) {
}
func TestGenerateHyperlinkForChannelsPublic(t *testing.T) {
th := Setup(t).InitBasic()
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := th.BasicChannel
ch := &model.Channel{
Name: "channelname",
DisplayName: "ChannelName",
Type: model.CHANNEL_OPEN,
}
message := "This is the message "
mention := "~" + ch.Name
teamName := th.BasicTeam.Name
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Id: "test", Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
channelStoreMock := mocks.ChannelStore{}
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
storeMock.On("Channel").Return(&channelStoreMock)
outMessage := th.App.generateHyperlinkForChannels(message+mention, teamName, teamURL)
channelURL := teamURL + "/channels/" + ch.Name
@@ -545,23 +682,48 @@ func TestGenerateHyperlinkForChannelsPublic(t *testing.T) {
}
func TestGenerateHyperlinkForChannelsMultiPublic(t *testing.T) {
th := Setup(t).InitBasic()
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := th.BasicChannel
// TODO: Fix the case where the first channel name contains the other channel names (for example here channelnameone)"
ch := &model.Channel{
Id: model.NewId(),
Name: "channelnameone",
DisplayName: "ChannelName",
Type: model.CHANNEL_OPEN,
}
mention := "~" + ch.Name
ch2 := th.CreateChannel(th.BasicTeam)
ch2 := &model.Channel{
Id: model.NewId(),
Name: "channelnametwo",
DisplayName: "ChannelName2",
Type: model.CHANNEL_OPEN,
}
mention2 := "~" + ch2.Name
ch3 := th.CreateChannel(th.BasicTeam)
ch3 := &model.Channel{
Id: model.NewId(),
Name: "channelnamethree",
DisplayName: "ChannelName3",
Type: model.CHANNEL_OPEN,
}
mention3 := "~" + ch3.Name
message := fmt.Sprintf("This is the message Channel1: %s; Channel2: %s;"+
" Channel3: %s", mention, mention2, mention3)
teamName := th.BasicTeam.Name
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Id: "test", Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
channelStoreMock := mocks.ChannelStore{}
channelStoreMock.On("GetByNames", "test", []string{ch.Name, ch2.Name, ch3.Name}, true).Return([]*model.Channel{ch, ch2, ch3}, nil)
storeMock.On("Channel").Return(&channelStoreMock)
outMessage := th.App.generateHyperlinkForChannels(message, teamName, teamURL)
channelURL := teamURL + "/channels/" + ch.Name
@@ -574,21 +736,34 @@ func TestGenerateHyperlinkForChannelsMultiPublic(t *testing.T) {
}
func TestGenerateHyperlinkForChannelsPrivate(t *testing.T) {
th := Setup(t).InitBasic()
th := SetupWithStoreMock(t)
defer th.TearDown()
ch := th.CreatePrivateChannel(th.BasicTeam)
ch := &model.Channel{
Name: "channelname",
DisplayName: "ChannelName",
Type: model.CHANNEL_PRIVATE,
}
message := "This is the message ~" + ch.Name
teamName := th.BasicTeam.Name
teamURL := "http://localhost:8065/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/testteam"
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Id: "test", Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
channelStoreMock := mocks.ChannelStore{}
channelStoreMock.On("GetByNames", "test", []string{ch.Name}, true).Return([]*model.Channel{ch}, nil)
storeMock.On("Channel").Return(&channelStoreMock)
outMessage := th.App.generateHyperlinkForChannels(message, teamName, teamURL)
assert.Equal(t, message, outMessage)
}
func TestLandingLink(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -601,17 +776,22 @@ func TestLandingLink(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "select_team"
teamURL := "http://localhost:8065/landing#/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/landing#/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, teamURL, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
}
func TestLandingLinkPermalink(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
recipient := &model.User{}
@@ -625,11 +805,16 @@ func TestLandingLinkPermalink(t *testing.T) {
}
channelName := "ChannelName"
senderName := "sender"
teamName := "team"
teamURL := "http://localhost:8065/landing#/" + teamName
teamName := "testteam"
teamURL := "http://localhost:8065/landing#/testteam"
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
translateFunc := utils.GetUserTranslations("en")
storeMock := th.App.Srv().Store.(*mocks.Store)
teamStoreMock := mocks.TeamStore{}
teamStoreMock.On("GetByName", "testteam").Return(&model.Team{Name: "testteam"}, nil)
storeMock.On("Team").Return(&teamStoreMock)
body := th.App.getNotificationEmailBody(recipient, post, channel, channelName, senderName, teamName, teamURL, emailNotificationContentsType, true, translateFunc)
require.Contains(t, body, teamURL+"/pl/"+post.Id, fmt.Sprintf("Expected email text '%s'. Got %s", teamURL, body))
}

Просмотреть файл

@@ -8,8 +8,10 @@ import (
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
@@ -539,9 +541,20 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
}
func TestGetPushNotificationMessage(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*mocks.Store)
mockUserStore := mocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := mocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := mocks.SystemStore{}
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
for name, tc := range map[string]struct {
Message string
explicitMention bool

Просмотреть файл

@@ -15,17 +15,6 @@ type permissionTransformation struct {
type permissionsMap []permissionTransformation
const (
MIGRATION_KEY_EMOJI_PERMISSIONS_SPLIT = "emoji_permissions_split"
MIGRATION_KEY_WEBHOOK_PERMISSIONS_SPLIT = "webhook_permissions_split"
MIGRATION_KEY_LIST_JOIN_PUBLIC_PRIVATE_TEAMS = "list_join_public_private_teams"
MIGRATION_KEY_REMOVE_PERMANENT_DELETE_USER = "remove_permanent_delete_user"
MIGRATION_KEY_ADD_BOT_PERMISSIONS = "add_bot_permissions"
MIGRATION_KEY_APPLY_CHANNEL_MANAGE_DELETE_TO_CHANNEL_USER = "apply_channel_manage_delete_to_channel_user"
MIGRATION_KEY_REMOVE_CHANNEL_MANAGE_DELETE_FROM_TEAM_USER = "remove_channel_manage_delete_from_team_user"
MIGRATION_KEY_VIEW_MEMBERS_NEW_PERMISSION = "view_members_new_permission"
MIGRATION_KEY_ADD_MANAGE_GUESTS_PERMISSIONS = "add_manage_guests_permissions"
MIGRATION_KEY_ADD_USE_CHANNEL_MENTIONS_PERMISSION = "add_use_channel_mentions_permission"
PERMISSION_MANAGE_SYSTEM = "manage_system"
PERMISSION_MANAGE_EMOJIS = "manage_emojis"
PERMISSION_MANAGE_OTHERS_EMOJIS = "manage_others_emojis"
@@ -306,16 +295,16 @@ func (a *App) DoPermissionsMigrations() *model.AppError {
Key string
Migration func() permissionsMap
}{
{Key: MIGRATION_KEY_EMOJI_PERMISSIONS_SPLIT, Migration: getEmojisPermissionsSplitMigration},
{Key: MIGRATION_KEY_WEBHOOK_PERMISSIONS_SPLIT, Migration: getWebhooksPermissionsSplitMigration},
{Key: MIGRATION_KEY_LIST_JOIN_PUBLIC_PRIVATE_TEAMS, Migration: getListJoinPublicPrivateTeamsPermissionsMigration},
{Key: MIGRATION_KEY_REMOVE_PERMANENT_DELETE_USER, Migration: removePermanentDeleteUserMigration},
{Key: MIGRATION_KEY_ADD_BOT_PERMISSIONS, Migration: getAddBotPermissionsMigration},
{Key: MIGRATION_KEY_APPLY_CHANNEL_MANAGE_DELETE_TO_CHANNEL_USER, Migration: applyChannelManageDeleteToChannelUser},
{Key: MIGRATION_KEY_REMOVE_CHANNEL_MANAGE_DELETE_FROM_TEAM_USER, Migration: removeChannelManageDeleteFromTeamUser},
{Key: MIGRATION_KEY_VIEW_MEMBERS_NEW_PERMISSION, Migration: getViewMembersPermissionMigration},
{Key: MIGRATION_KEY_ADD_MANAGE_GUESTS_PERMISSIONS, Migration: getAddManageGuestsPermissionsMigration},
{Key: MIGRATION_KEY_ADD_USE_CHANNEL_MENTIONS_PERMISSION, Migration: getAddUseMentionChannelsPermissionMigration},
{Key: model.MIGRATION_KEY_EMOJI_PERMISSIONS_SPLIT, Migration: getEmojisPermissionsSplitMigration},
{Key: model.MIGRATION_KEY_WEBHOOK_PERMISSIONS_SPLIT, Migration: getWebhooksPermissionsSplitMigration},
{Key: model.MIGRATION_KEY_LIST_JOIN_PUBLIC_PRIVATE_TEAMS, Migration: getListJoinPublicPrivateTeamsPermissionsMigration},
{Key: model.MIGRATION_KEY_REMOVE_PERMANENT_DELETE_USER, Migration: removePermanentDeleteUserMigration},
{Key: model.MIGRATION_KEY_ADD_BOT_PERMISSIONS, Migration: getAddBotPermissionsMigration},
{Key: model.MIGRATION_KEY_APPLY_CHANNEL_MANAGE_DELETE_TO_CHANNEL_USER, Migration: applyChannelManageDeleteToChannelUser},
{Key: model.MIGRATION_KEY_REMOVE_CHANNEL_MANAGE_DELETE_FROM_TEAM_USER, Migration: removeChannelManageDeleteFromTeamUser},
{Key: model.MIGRATION_KEY_VIEW_MEMBERS_NEW_PERMISSION, Migration: getViewMembersPermissionMigration},
{Key: model.MIGRATION_KEY_ADD_MANAGE_GUESTS_PERMISSIONS, Migration: getAddManageGuestsPermissionsMigration},
{Key: model.MIGRATION_KEY_ADD_USE_CHANNEL_MENTIONS_PERMISSION, Migration: getAddUseMentionChannelsPermissionMigration},
}
for _, migration := range PermissionsMigrations {

Просмотреть файл

@@ -9,14 +9,28 @@ import (
"path/filepath"
"testing"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
"github.com/mattermost/mattermost-server/v5/utils/fileutils"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestPluginPublicKeys(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*mocks.Store)
mockUserStore := mocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := mocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := mocks.SystemStore{}
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
path, _ := fileutils.FindDir("tests")
publicKeyFilename := "test-public-key.plugin.gpg"
publicKey, err := ioutil.ReadFile(filepath.Join(path, publicKeyFilename))

Просмотреть файл

@@ -17,6 +17,7 @@ import (
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin/plugintest/mock"
"github.com/mattermost/mattermost-server/v5/store/storetest"
storemocks "github.com/mattermost/mattermost-server/v5/store/storetest/mocks"
)
func TestCreatePostDeduplicate(t *testing.T) {
@@ -445,9 +446,20 @@ func TestPostChannelMentions(t *testing.T) {
}
func TestImageProxy(t *testing.T) {
th := Setup(t)
th := SetupWithStoreMock(t)
defer th.TearDown()
mockStore := th.App.Srv().Store.(*storemocks.Store)
mockUserStore := storemocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := storemocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := storemocks.SystemStore{}
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.SiteURL = "http://mymattermost.com"
})