Remove global app references (#7433)
* remove global app references * test fix * fix api4 test compilation
Этот коммит содержится в:
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type TestHelper struct {
|
||||
App *App
|
||||
BasicTeam *model.Team
|
||||
BasicUser *model.User
|
||||
BasicUser2 *model.User
|
||||
@@ -20,55 +21,48 @@ type TestHelper struct {
|
||||
BasicPost *model.Post
|
||||
}
|
||||
|
||||
func (a *App) SetupEnterprise() *TestHelper {
|
||||
if a.Srv == nil {
|
||||
func setupTestHelper(enterprise bool) *TestHelper {
|
||||
th := &TestHelper{
|
||||
App: Global(),
|
||||
}
|
||||
|
||||
if th.App.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
utils.License().Features.SetDefaults()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.StartServer()
|
||||
if enterprise {
|
||||
utils.License().Features.SetDefaults()
|
||||
}
|
||||
th.App.NewServer()
|
||||
th.App.InitStores()
|
||||
th.App.StartServer()
|
||||
utils.InitHTML()
|
||||
utils.EnableDebugLogForTest()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
th.App.Srv.Store.MarkSystemRanUnitTests()
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
return &TestHelper{}
|
||||
return th
|
||||
}
|
||||
|
||||
func (a *App) Setup() *TestHelper {
|
||||
if a.Srv == nil {
|
||||
utils.TranslationsPreInit()
|
||||
utils.LoadConfig("config.json")
|
||||
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||
*utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.RateLimitSettings.Enable = false
|
||||
utils.DisableDebugLogForTest()
|
||||
a.NewServer()
|
||||
a.InitStores()
|
||||
a.StartServer()
|
||||
utils.InitHTML()
|
||||
utils.EnableDebugLogForTest()
|
||||
a.Srv.Store.MarkSystemRanUnitTests()
|
||||
func SetupEnterprise() *TestHelper {
|
||||
return setupTestHelper(true)
|
||||
}
|
||||
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
return &TestHelper{}
|
||||
func Setup() *TestHelper {
|
||||
return setupTestHelper(false)
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.BasicTeam = me.CreateTeam()
|
||||
me.BasicUser = me.CreateUser()
|
||||
Global().LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.App.LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.BasicUser2 = me.CreateUser()
|
||||
Global().LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.App.LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.BasicChannel = me.CreateChannel(me.BasicTeam)
|
||||
me.BasicPost = me.CreatePost(me.BasicChannel)
|
||||
|
||||
@@ -94,7 +88,7 @@ func (me *TestHelper) CreateTeam() *model.Team {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if team, err = Global().CreateTeam(team); err != nil {
|
||||
if team, err = me.App.CreateTeam(team); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -117,7 +111,7 @@ func (me *TestHelper) CreateUser() *model.User {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if user, err = Global().CreateUser(user); err != nil {
|
||||
if user, err = me.App.CreateUser(user); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -148,7 +142,7 @@ func (me *TestHelper) createChannel(team *model.Team, channelType string) *model
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if channel, err = Global().CreateChannel(channel, true); err != nil {
|
||||
if channel, err = me.App.CreateChannel(channel, true); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
@@ -169,7 +163,7 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post {
|
||||
|
||||
utils.DisableDebugLogForTest()
|
||||
var err *model.AppError
|
||||
if post, err = Global().CreatePost(post, channel, false); err != nil {
|
||||
if post, err = me.App.CreatePost(post, channel, false); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
l4g.Close()
|
||||
time.Sleep(time.Second)
|
||||
|
||||
@@ -10,8 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCheckIfRolesGrantPermission(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
|
||||
cases := []struct {
|
||||
roles []string
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPermanentDeleteChannel(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
incomingWasEnabled := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
|
||||
outgoingWasEnabled := utils.Cfg.ServiceSettings.EnableOutgoingWebhooks
|
||||
@@ -20,25 +19,25 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
utils.Cfg.ServiceSettings.EnableOutgoingWebhooks = outgoingWasEnabled
|
||||
}()
|
||||
|
||||
channel, err := a.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
channel, err := th.App.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer func() {
|
||||
a.PermanentDeleteChannel(channel)
|
||||
th.App.PermanentDeleteChannel(channel)
|
||||
}()
|
||||
|
||||
incoming, err := a.CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
||||
incoming, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteIncomingWebhook(incoming.Id)
|
||||
defer th.App.DeleteIncomingWebhook(incoming.Id)
|
||||
|
||||
if incoming, err = a.GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
||||
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
||||
t.Fatal("unable to get new incoming webhook")
|
||||
}
|
||||
|
||||
outgoing, err := a.CreateOutgoingWebhook(&model.OutgoingWebhook{
|
||||
outgoing, err := th.App.CreateOutgoingWebhook(&model.OutgoingWebhook{
|
||||
ChannelId: channel.Id,
|
||||
TeamId: channel.TeamId,
|
||||
CreatorId: th.BasicUser.Id,
|
||||
@@ -47,65 +46,64 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteOutgoingWebhook(outgoing.Id)
|
||||
defer th.App.DeleteOutgoingWebhook(outgoing.Id)
|
||||
|
||||
if outgoing, err = a.GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
||||
if outgoing, err = th.App.GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
||||
t.Fatal("unable to get new outgoing webhook")
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteChannel(channel); err != nil {
|
||||
if err := th.App.PermanentDeleteChannel(channel); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if incoming, err = a.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||
t.Error("incoming webhook wasn't deleted")
|
||||
}
|
||||
|
||||
if outgoing, err = a.GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
||||
if outgoing, err = th.App.GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
||||
t.Error("outgoing webhook wasn't deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveChannel(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
sourceTeam := th.CreateTeam()
|
||||
targetTeam := th.CreateTeam()
|
||||
channel1 := th.CreateChannel(sourceTeam)
|
||||
defer func() {
|
||||
a.PermanentDeleteChannel(channel1)
|
||||
a.PermanentDeleteTeam(sourceTeam)
|
||||
a.PermanentDeleteTeam(targetTeam)
|
||||
th.App.PermanentDeleteChannel(channel1)
|
||||
th.App.PermanentDeleteTeam(sourceTeam)
|
||||
th.App.PermanentDeleteTeam(targetTeam)
|
||||
}()
|
||||
|
||||
if _, err := a.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := a.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := a.AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.MoveChannel(targetTeam, channel1); err == nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1); err == nil {
|
||||
t.Fatal("Should have failed due to mismatched members.")
|
||||
}
|
||||
|
||||
if _, err := a.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.MoveChannel(targetTeam, channel1); err != nil {
|
||||
if err := th.App.MoveChannel(targetTeam, channel1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func TestClusterDiscoveryService(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
|
||||
ds := NewClusterDiscoveryService()
|
||||
ds.Type = model.CDS_TYPE_APP
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestRenameProviderDoCommand(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
rp := RenameProvider{}
|
||||
args := &model.CommandArgs{
|
||||
|
||||
@@ -47,8 +47,7 @@ func TestPluginSetting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDiagnostics(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
@@ -92,7 +91,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("SendDailyDiagnostics", func(t *testing.T) {
|
||||
a.SendDailyDiagnostics()
|
||||
th.App.SendDailyDiagnostics()
|
||||
|
||||
info := ""
|
||||
// Collect the info sent.
|
||||
@@ -152,7 +151,7 @@ func TestDiagnostics(t *testing.T) {
|
||||
*utils.Cfg.LogSettings.EnableDiagnostics = oldSetting
|
||||
}()
|
||||
|
||||
a.SendDailyDiagnostics()
|
||||
th.App.SendDailyDiagnostics()
|
||||
|
||||
select {
|
||||
case <-data:
|
||||
|
||||
@@ -13,8 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestHandleNewNotifications(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
|
||||
id1 := model.NewId()
|
||||
id2 := model.NewId()
|
||||
@@ -94,8 +93,7 @@ func TestHandleNewNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckPendingNotifications(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
job := MakeEmailBatchingJob(128)
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
@@ -109,11 +107,11 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
channelMember := store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 9999999
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
store.Must(a.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
@@ -128,9 +126,9 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
// test that notifications are cleared if the user has acted
|
||||
channelMember = store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember = store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 10001000
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
job.checkPendingNotifications(time.Unix(10002, 0), func(string, []*batchedNotification) {})
|
||||
|
||||
@@ -202,14 +200,13 @@ func TestCheckPendingNotifications(t *testing.T) {
|
||||
* Ensures that email batch interval defaults to 15 minutes for users that haven't explicitly set this preference
|
||||
*/
|
||||
func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
job := MakeEmailBatchingJob(128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember := store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
job.pendingNotifications[th.BasicUser.Id] = []*batchedNotification{
|
||||
{
|
||||
@@ -239,17 +236,16 @@ func TestCheckPendingNotificationsDefaultInterval(t *testing.T) {
|
||||
* Ensures that email batch interval defaults to 15 minutes if user preference is invalid
|
||||
*/
|
||||
func TestCheckPendingNotificationsCantParseInterval(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
job := MakeEmailBatchingJob(128)
|
||||
|
||||
// bypasses recent user activity check
|
||||
channelMember := store.Must(a.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember := store.Must(th.App.Srv.Store.Channel().GetMember(th.BasicChannel.Id, th.BasicUser.Id)).(*model.ChannelMember)
|
||||
channelMember.LastViewedAt = 9999000
|
||||
store.Must(a.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
store.Must(th.App.Srv.Store.Channel().UpdateMember(channelMember))
|
||||
|
||||
// preference value is not an integer, so we'll fall back to the default 15min value
|
||||
store.Must(a.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
store.Must(th.App.Srv.Store.Preference().Save(&model.Preferences{{
|
||||
UserId: th.BasicUser.Id,
|
||||
Category: model.PREFERENCE_CATEGORY_NOTIFICATIONS,
|
||||
Name: model.PREFERENCE_NAME_EMAIL_INTERVAL,
|
||||
@@ -284,8 +280,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) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
var post = &model.Post{}
|
||||
post.Message = "This is the message"
|
||||
var notification = &batchedNotification{}
|
||||
@@ -300,7 +295,7 @@ func TestRenderBatchedPostGeneric(t *testing.T) {
|
||||
return translationID
|
||||
}
|
||||
|
||||
var rendered = a.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_GENERIC)
|
||||
var rendered = th.App.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_GENERIC)
|
||||
if strings.Contains(rendered, post.Message) {
|
||||
t.Fatal("Rendered email should not contain post contents when email notification contents type is set to Generic.")
|
||||
}
|
||||
@@ -310,8 +305,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) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
var post = &model.Post{}
|
||||
post.Message = "This is the message"
|
||||
var notification = &batchedNotification{}
|
||||
@@ -326,7 +320,7 @@ func TestRenderBatchedPostFull(t *testing.T) {
|
||||
return translationID
|
||||
}
|
||||
|
||||
var rendered = a.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_FULL)
|
||||
var rendered = th.App.renderBatchedPost(notification, channel, sender, "http://localhost:8065", "", translateFunc, "en", model.EMAIL_NOTIFICATION_CONTENTS_FULL)
|
||||
if !strings.Contains(rendered, post.Message) {
|
||||
t.Fatal("Rendered email should contain post contents when email notification contents type is set to Full.")
|
||||
}
|
||||
|
||||
@@ -1,639 +0,0 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
/*func TestSendChangeUsernameEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var emailTo string = "test@example.com"
|
||||
var oldUsername string = "myoldusername"
|
||||
var newUsername string = "fancyusername"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var expectedPartialMessage string = "Your username for " + utils.Cfg.TeamSettings.SiteName + " has been changed to " + newUsername + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your username has changed"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(emailTo)
|
||||
|
||||
if err := SendChangeUsernameEmail(oldUsername, newUsername, emailTo, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(emailTo)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], emailTo) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEmailChangeVerifyEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var newUserEmail string = "newtest@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://localhost:8065"
|
||||
var expectedPartialMessage string = "You updated your email"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Verify new email address"
|
||||
var token string = "TEST_TOKEN"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(newUserEmail)
|
||||
|
||||
if err := SendEmailChangeVerifyEmail(newUserEmail, locale, siteURL, token); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(newUserEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], newUserEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(newUserEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(newUserEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendEmailChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var oldEmail string = "test@example.com"
|
||||
var newUserEmail string = "newtest@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var expectedPartialMessage string = "Your email address for Mattermost has been changed to " + newUserEmail
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your email address has changed"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(oldEmail)
|
||||
|
||||
if err := SendEmailChangeEmail(oldEmail, newUserEmail, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(oldEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], oldEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(oldEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendVerifyEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var userEmail string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://localhost:8605"
|
||||
var expectedPartialMessage string = "Please verify your email address by clicking below"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Email Verification"
|
||||
var token string = "TEST_TOKEN"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(userEmail)
|
||||
|
||||
if err := SendVerifyEmail(userEmail, locale, siteURL, token); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(userEmail)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], userEmail) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(userEmail, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(userEmail)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong new email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendSignInChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var method string = "AD/LDAP"
|
||||
var expectedPartialMessage string = "You updated your sign-in method on Mattermost to " + method + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your sign-in method has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendSignInChangeEmail(email, method, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendWelcomeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var userId string = "32432nkjnijn432uj32"
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
var verified bool = true
|
||||
var expectedPartialMessage string = "Mattermost lets you share messages and files from your PC or phone, with instant search and archiving"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] You joined test.mattermost.io"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := a.SendWelcomeEmail(userId, email, verified, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
utils.DeleteMailBox(email)
|
||||
verified = false
|
||||
var expectedVerifyEmail string = "Please verify your email address by clicking below."
|
||||
|
||||
if err := a.SendWelcomeEmail(userId, email, verified, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedVerifyEmail) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, utils.UrlEncode(email)) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong email in the message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPasswordChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
var method string = "using a reset password link"
|
||||
var expectedPartialMessage string = "Your password has been updated for " + utils.Cfg.TeamSettings.SiteName + " on " + siteURL + " by " + method
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your password has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendPasswordChangeEmail(email, method, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendMfaChangeEmail(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
a.Setup()
|
||||
|
||||
var email string = "test@example.com"
|
||||
var locale string = "en"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
var activated bool = true
|
||||
var expectedPartialMessage string = "Multi-factor authentication has been added to your account on " + siteURL + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your MFA has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendMfaChangeEmail(email, activated, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
activated = false
|
||||
expectedPartialMessage = "Multi-factor authentication has been removed from your account on " + siteURL + "."
|
||||
utils.DeleteMailBox(email)
|
||||
|
||||
if err := SendMfaChangeEmail(email, activated, locale, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendInviteEmails(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
var email1 string = "test1@example.com"
|
||||
var email2 string = "test2@example.com"
|
||||
var senderName string = "TheBoss"
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
invites := []string{email1, email2}
|
||||
var expectedPartialMessage string = "The team member *" + senderName + "* , has invited you to join *" + th.BasicTeam.DisplayName + "*"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] " + senderName + " invited you to join " + th.BasicTeam.DisplayName + " Team"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email1)
|
||||
utils.DeleteMailBox(email2)
|
||||
|
||||
SendInviteEmails(th.BasicTeam, senderName, invites, siteURL)
|
||||
|
||||
//Check if the email was send to the rigth email address to email1
|
||||
var resultsMailbox utils.JSONMessageHeaderInbucket
|
||||
err := utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email1)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email1) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email1, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check if the email was send to the rigth email address to email2
|
||||
err = utils.RetryInbucket(5, func() error {
|
||||
var err error
|
||||
resultsMailbox, err = utils.GetMailBox(email2)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.Log("No email was received, maybe due load on the server. Disabling this verification")
|
||||
}
|
||||
if err == nil && len(resultsMailbox) > 0 {
|
||||
if !strings.ContainsAny(resultsMailbox[0].To[0], email2) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email2, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPasswordReset(t *testing.T) {
|
||||
a := Global()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
th := a.Setup().InitBasic()
|
||||
|
||||
var siteURL string = "http://test.mattermost.io"
|
||||
// var locale string = "en"
|
||||
var expectedPartialMessage string = "To change your password"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Reset your password"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(th.BasicUser.Email)
|
||||
|
||||
if _, err := a.SendPasswordReset(th.BasicUser.Email, siteURL); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should send change username email")
|
||||
} else {
|
||||
//Check if the email was send to the rigth email address
|
||||
if resultsMailbox, err := utils.GetMailBox(th.BasicUser.Email); err != nil && !strings.ContainsAny(resultsMailbox[0].To[0], th.BasicUser.Email) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser.Email, resultsMailbox[0].ID); err == nil {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
if !strings.Contains(resultsEmail.Body.Text, expectedPartialMessage) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Wrong Body message")
|
||||
}
|
||||
loc := strings.Index(resultsEmail.Body.Text, "token=")
|
||||
if loc == -1 {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Fatal("Code not found in email")
|
||||
}
|
||||
loc += 6
|
||||
recoveryTokenString := resultsEmail.Body.Text[loc : loc+model.TOKEN_SIZE]
|
||||
var recoveryToken *model.Token
|
||||
if result := <-a.Srv.Store.Token().GetByToken(recoveryTokenString); result.Err != nil {
|
||||
t.Log(recoveryTokenString)
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
recoveryToken = result.Data.(*model.Token)
|
||||
if !strings.Contains(resultsEmail.Body.Text, recoveryToken.Token) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recoveryToken.Token)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -36,8 +36,7 @@ func TestGeneratePublicLinkHash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDoUploadFile(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
teamId := model.NewId()
|
||||
channelId := model.NewId()
|
||||
@@ -45,12 +44,12 @@ func TestDoUploadFile(t *testing.T) {
|
||||
filename := "test"
|
||||
data := []byte("abcd")
|
||||
|
||||
info1, err := a.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
<-a.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
<-th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
|
||||
utils.RemoveFile(info1.Path)
|
||||
}()
|
||||
}
|
||||
@@ -59,12 +58,12 @@ func TestDoUploadFile(t *testing.T) {
|
||||
t.Fatal("stored file at incorrect path", info1.Path)
|
||||
}
|
||||
|
||||
info2, err := a.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
info2, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
<-a.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
<-th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
|
||||
utils.RemoveFile(info2.Path)
|
||||
}()
|
||||
}
|
||||
@@ -73,12 +72,12 @@ func TestDoUploadFile(t *testing.T) {
|
||||
t.Fatal("stored file at incorrect path", info2.Path)
|
||||
}
|
||||
|
||||
info3, err := a.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
info3, err := th.App.DoUploadFile(time.Date(2008, 3, 5, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
defer func() {
|
||||
<-a.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
<-th.App.Srv.Store.FileInfo().PermanentDelete(info3.Id)
|
||||
utils.RemoveFile(info3.Path)
|
||||
}()
|
||||
}
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -11,20 +11,19 @@ import (
|
||||
)
|
||||
|
||||
func TestGetJob(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
status := &model.Job{
|
||||
Id: model.NewId(),
|
||||
Status: model.NewId(),
|
||||
}
|
||||
if result := <-a.Srv.Store.Job().Save(status); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.Job().Save(status); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
defer a.Srv.Store.Job().Delete(status.Id)
|
||||
defer th.App.Srv.Store.Job().Delete(status.Id)
|
||||
|
||||
if received, err := a.GetJob(status.Id); err != nil {
|
||||
if received, err := th.App.GetJob(status.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if received.Id != status.Id || received.Status != status.Status {
|
||||
t.Fatal("inccorrect job status received")
|
||||
@@ -32,8 +31,7 @@ func TestGetJob(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetJobByType(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
jobType := model.NewId()
|
||||
|
||||
@@ -56,11 +54,11 @@ func TestGetJobByType(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, status := range statuses {
|
||||
store.Must(a.Srv.Store.Job().Save(status))
|
||||
defer a.Srv.Store.Job().Delete(status.Id)
|
||||
store.Must(th.App.Srv.Store.Job().Save(status))
|
||||
defer th.App.Srv.Store.Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
if received, err := a.GetJobsByType(jobType, 0, 2); err != nil {
|
||||
if received, err := th.App.GetJobsByType(jobType, 0, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 2 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
@@ -70,7 +68,7 @@ func TestGetJobByType(t *testing.T) {
|
||||
t.Fatal("should've received second newest job second")
|
||||
}
|
||||
|
||||
if received, err := a.GetJobsByType(jobType, 2, 2); err != nil {
|
||||
if received, err := th.App.GetJobsByType(jobType, 2, 2); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if len(received) != 1 {
|
||||
t.Fatal("received wrong number of statuses")
|
||||
|
||||
@@ -11,31 +11,28 @@ import (
|
||||
)
|
||||
|
||||
func TestLoadLicense(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
a.LoadLicense()
|
||||
th.App.LoadLicense()
|
||||
if utils.IsLicensed() {
|
||||
t.Fatal("shouldn't have a valid license")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSaveLicense(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
b1 := []byte("junk")
|
||||
|
||||
if _, err := a.SaveLicense(b1); err == nil {
|
||||
if _, err := th.App.SaveLicense(b1); err == nil {
|
||||
t.Fatal("shouldn't have saved license")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLicense(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
if err := a.RemoveLicense(); err != nil {
|
||||
if err := th.App.RemoveLicense(); err != nil {
|
||||
t.Fatal("should have removed license")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func TestSendNotifications(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
a.AddUserToChannel(th.BasicUser2, th.BasicChannel)
|
||||
th.App.AddUserToChannel(th.BasicUser2, th.BasicChannel)
|
||||
|
||||
post1, err := a.CreatePostMissingChannel(&model.Post{
|
||||
post1, err := th.App.CreatePostMissingChannel(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "@" + th.BasicUser2.Username,
|
||||
@@ -27,7 +26,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
mentions, err := a.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
mentions, err := th.App.SendNotifications(post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if mentions == nil {
|
||||
@@ -38,12 +37,12 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal("user should have been mentioned")
|
||||
}
|
||||
|
||||
dm, err := a.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
dm, err := th.App.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
post2, err := a.CreatePostMissingChannel(&model.Post{
|
||||
post2, err := th.App.CreatePostMissingChannel(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: dm.Id,
|
||||
Message: "dm message",
|
||||
@@ -53,15 +52,15 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = a.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
_, err = th.App.SendNotifications(post2, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
a.UpdateActive(th.BasicUser2, false)
|
||||
a.InvalidateAllCaches()
|
||||
th.App.UpdateActive(th.BasicUser2, false)
|
||||
th.App.InvalidateAllCaches()
|
||||
|
||||
post3, err := a.CreatePostMissingChannel(&model.Post{
|
||||
post3, err := th.App.CreatePostMissingChannel(&model.Post{
|
||||
UserId: th.BasicUser.Id,
|
||||
ChannelId: dm.Id,
|
||||
Message: "dm message",
|
||||
@@ -71,7 +70,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = a.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
_, err = th.App.SendNotifications(post3, th.BasicTeam, dm, th.BasicUser, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -409,8 +408,7 @@ func TestRemoveCodeFromMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMentionKeywords(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
// user with username or custom mentions enabled
|
||||
user1 := &model.User{
|
||||
Id: model.NewId(),
|
||||
@@ -835,8 +833,7 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
expectedPrefix := "[http://localhost:8065] New Direct Message from sender on"
|
||||
post := &model.Post{
|
||||
CreateAt: 1501804801000,
|
||||
@@ -849,8 +846,7 @@ func TestGetDirectMessageNotificationEmailSubject(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailSubject(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
Setup()
|
||||
expectedPrefix := "[http://localhost:8065] Notification in team on"
|
||||
post := &model.Post{
|
||||
CreateAt: 1501804801000,
|
||||
@@ -863,8 +859,7 @@ func TestGetNotificationEmailSubject(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -879,7 +874,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification.") {
|
||||
t.Fatal("Expected email text 'You have a new notification. Got " + body)
|
||||
}
|
||||
@@ -898,8 +893,7 @@ func TestGetNotificationEmailBodyFullNotificationPublicChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -914,7 +908,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification.") {
|
||||
t.Fatal("Expected email text 'You have a new notification. Got " + body)
|
||||
}
|
||||
@@ -933,8 +927,7 @@ func TestGetNotificationEmailBodyFullNotificationGroupChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -949,7 +942,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification.") {
|
||||
t.Fatal("Expected email text 'You have a new notification. Got " + body)
|
||||
}
|
||||
@@ -968,8 +961,7 @@ func TestGetNotificationEmailBodyFullNotificationPrivateChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -984,7 +976,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_FULL
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new direct message.") {
|
||||
t.Fatal("Expected email text 'You have a new direct message. Got " + body)
|
||||
}
|
||||
@@ -1001,8 +993,7 @@ func TestGetNotificationEmailBodyFullNotificationDirectChannel(t *testing.T) {
|
||||
|
||||
// from here
|
||||
func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1017,7 +1008,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
|
||||
}
|
||||
@@ -1033,8 +1024,7 @@ func TestGetNotificationEmailBodyGenericNotificationPublicChannel(t *testing.T)
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1049,7 +1039,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
|
||||
}
|
||||
@@ -1065,8 +1055,7 @@ func TestGetNotificationEmailBodyGenericNotificationGroupChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1081,7 +1070,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new notification from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new notification from " + senderName + "'. Got " + body)
|
||||
}
|
||||
@@ -1097,8 +1086,7 @@ func TestGetNotificationEmailBodyGenericNotificationPrivateChannel(t *testing.T)
|
||||
}
|
||||
|
||||
func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
recipient := &model.User{}
|
||||
post := &model.Post{
|
||||
Message: "This is the message",
|
||||
@@ -1113,7 +1101,7 @@ func TestGetNotificationEmailBodyGenericNotificationDirectChannel(t *testing.T)
|
||||
emailNotificationContentsType := model.EMAIL_NOTIFICATION_CONTENTS_GENERIC
|
||||
translateFunc := utils.GetUserTranslations("en")
|
||||
|
||||
body := a.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
body := th.App.getNotificationEmailBody(recipient, post, channel, senderName, teamName, teamURL, emailNotificationContentsType, translateFunc)
|
||||
if !strings.Contains(body, "You have a new direct message from "+senderName) {
|
||||
t.Fatal("Expected email text 'You have a new direct message from " + senderName + "'. Got " + body)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
if err := a.RevokeAccessToken(model.NewRandomString(16)); err == nil {
|
||||
th := Setup()
|
||||
if err := th.App.RevokeAccessToken(model.NewRandomString(16)); err == nil {
|
||||
t.Fatal("Should have failed bad token")
|
||||
}
|
||||
|
||||
@@ -24,8 +23,8 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
session.Roles = model.ROLE_SYSTEM_USER.Id
|
||||
session.SetExpireInDays(1)
|
||||
|
||||
session, _ = a.CreateSession(session)
|
||||
if err := a.RevokeAccessToken(session.Token); err == nil {
|
||||
session, _ = th.App.CreateSession(session)
|
||||
if err := th.App.RevokeAccessToken(session.Token); err == nil {
|
||||
t.Fatal("Should have failed does not have an access token")
|
||||
}
|
||||
|
||||
@@ -36,18 +35,17 @@ func TestOAuthRevokeAccessToken(t *testing.T) {
|
||||
accessData.ClientId = model.NewId()
|
||||
accessData.ExpiresAt = session.ExpiresAt
|
||||
|
||||
if result := <-a.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
if err := a.RevokeAccessToken(accessData.Token); err != nil {
|
||||
if err := th.App.RevokeAccessToken(accessData.Token); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOAuthDeleteApp(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
|
||||
oldSetting := utils.Cfg.ServiceSettings.EnableOAuthServiceProvider
|
||||
defer func() {
|
||||
@@ -62,7 +60,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
a1.Homepage = "https://nowhere.com"
|
||||
|
||||
var err *model.AppError
|
||||
a1, err = a.CreateOAuthApp(a1)
|
||||
a1, err = th.App.CreateOAuthApp(a1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -75,7 +73,7 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
session.IsOAuth = true
|
||||
session.SetExpireInDays(1)
|
||||
|
||||
session, _ = a.CreateSession(session)
|
||||
session, _ = th.App.CreateSession(session)
|
||||
|
||||
accessData := &model.AccessData{}
|
||||
accessData.Token = session.Token
|
||||
@@ -84,15 +82,15 @@ func TestOAuthDeleteApp(t *testing.T) {
|
||||
accessData.ClientId = a1.Id
|
||||
accessData.ExpiresAt = session.ExpiresAt
|
||||
|
||||
if result := <-a.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
if result := <-th.App.Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
}
|
||||
|
||||
if err := a.DeleteOAuthApp(a1.Id); err != nil {
|
||||
if err := th.App.DeleteOAuthApp(a1.Id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := a.GetSession(session.Token); err == nil {
|
||||
if _, err := th.App.GetSession(session.Token); err == nil {
|
||||
t.Fatal("should not get session from cache or db")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,13 @@ import (
|
||||
)
|
||||
|
||||
func TestUpdatePostEditAt(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
post := &model.Post{}
|
||||
*post = *th.BasicPost
|
||||
|
||||
post.IsPinned = true
|
||||
if saved, err := a.UpdatePost(post, true); err != nil {
|
||||
if saved, err := th.App.UpdatePost(post, true); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if saved.EditAt != post.EditAt {
|
||||
t.Fatal("shouldn't have updated post.EditAt when pinning post")
|
||||
@@ -37,7 +36,7 @@ func TestUpdatePostEditAt(t *testing.T) {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
|
||||
post.Message = model.NewId()
|
||||
if saved, err := a.UpdatePost(post, true); err != nil {
|
||||
if saved, err := th.App.UpdatePost(post, true); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if saved.EditAt == post.EditAt {
|
||||
t.Fatal("should have updated post.EditAt when updating post message")
|
||||
@@ -45,21 +44,20 @@ func TestUpdatePostEditAt(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
a := Global()
|
||||
// This test ensures that when replying to a root post made by a user who has since left the channel, the reply
|
||||
// post completes successfully. This is a regression test for PLT-6523.
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
channel := th.BasicChannel
|
||||
userInChannel := th.BasicUser2
|
||||
userNotInChannel := th.BasicUser
|
||||
rootPost := th.BasicPost
|
||||
|
||||
if _, err := a.AddUserToChannel(userInChannel, channel); err != nil {
|
||||
if _, err := th.App.AddUserToChannel(userInChannel, channel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil {
|
||||
if err := th.App.RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -73,14 +71,13 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
|
||||
CreateAt: 0,
|
||||
}
|
||||
|
||||
if _, err := a.CreatePostAsUser(&replyPost); err != nil {
|
||||
if _, err := th.App.CreatePostAsUser(&replyPost); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostAction(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
allowedInternalConnections := *utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections
|
||||
defer func() {
|
||||
@@ -125,7 +122,7 @@ func TestPostAction(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
post, err := a.CreatePostAsUser(&interactivePost)
|
||||
post, err := th.App.CreatePostAsUser(&interactivePost)
|
||||
require.Nil(t, err)
|
||||
|
||||
attachments, ok := post.Props["attachments"].([]*model.SlackAttachment)
|
||||
@@ -134,10 +131,10 @@ func TestPostAction(t *testing.T) {
|
||||
require.NotEmpty(t, attachments[0].Actions)
|
||||
require.NotEmpty(t, attachments[0].Actions[0].Id)
|
||||
|
||||
err = a.DoPostAction(post.Id, "notavalidid", th.BasicUser.Id)
|
||||
err = th.App.DoPostAction(post.Id, "notavalidid", th.BasicUser.Id)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, http.StatusNotFound, err.StatusCode)
|
||||
|
||||
err = a.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id)
|
||||
err = th.App.DoPostAction(post.Id, attachments[0].Actions[0].Id, th.BasicUser.Id)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
id := model.NewId()
|
||||
team := &model.Team{
|
||||
@@ -22,19 +21,18 @@ func TestCreateTeam(t *testing.T) {
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeam(team); err != nil {
|
||||
if _, err := th.App.CreateTeam(team); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should create a new team")
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeam(th.BasicTeam); err == nil {
|
||||
if _, err := th.App.CreateTeam(th.BasicTeam); err == nil {
|
||||
t.Fatal("Should not create a new team - team already exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateTeamWithUser(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
id := model.NewId()
|
||||
team := &model.Team{
|
||||
@@ -44,17 +42,17 @@ func TestCreateTeamWithUser(t *testing.T) {
|
||||
Type: model.TEAM_OPEN,
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeamWithUser(team, th.BasicUser.Id); err != nil {
|
||||
if _, err := th.App.CreateTeamWithUser(team, th.BasicUser.Id); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should create a new team with existing user")
|
||||
}
|
||||
|
||||
if _, err := a.CreateTeamWithUser(team, model.NewId()); err == nil {
|
||||
if _, err := th.App.CreateTeamWithUser(team, model.NewId()); err == nil {
|
||||
t.Fatal("Should not create a new team - user does not exist")
|
||||
}
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := a.CreateUser(&user)
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
|
||||
id = model.NewId()
|
||||
team2 := &model.Team{
|
||||
@@ -65,7 +63,7 @@ func TestCreateTeamWithUser(t *testing.T) {
|
||||
}
|
||||
|
||||
//Fail to create a team with user when user has set email without domain
|
||||
if _, err := a.CreateTeamWithUser(team2, ruser.Id); err == nil {
|
||||
if _, err := th.App.CreateTeamWithUser(team2, ruser.Id); err == nil {
|
||||
t.Log(err.Message)
|
||||
t.Fatal("Should not create a team with user when user has set email without domain")
|
||||
} else {
|
||||
@@ -77,12 +75,11 @@ func TestCreateTeamWithUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
th.BasicTeam.DisplayName = "Testing 123"
|
||||
|
||||
if updatedTeam, err := a.UpdateTeam(th.BasicTeam); err != nil {
|
||||
if updatedTeam, err := th.App.UpdateTeam(th.BasicTeam); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should update the team")
|
||||
} else {
|
||||
@@ -93,36 +90,33 @@ func TestUpdateTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddUserToTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := a.CreateUser(&user)
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
|
||||
if _, err := a.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err != nil {
|
||||
if _, err := th.App.AddUserToTeam(th.BasicTeam.Id, ruser.Id, ""); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should add user to the team")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddUserToTeamByTeamId(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
|
||||
ruser, _ := a.CreateUser(&user)
|
||||
ruser, _ := th.App.CreateUser(&user)
|
||||
|
||||
if err := a.AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil {
|
||||
if err := th.App.AddUserToTeamByTeamId(th.BasicTeam.Id, ruser); err != nil {
|
||||
t.Log(err)
|
||||
t.Fatal("Should add user to the team")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPermanentDeleteTeam(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
|
||||
team, err := a.CreateTeam(&model.Team{
|
||||
team, err := th.App.CreateTeam(&model.Team{
|
||||
DisplayName: "deletion-test",
|
||||
Name: "deletion-test",
|
||||
Email: "foo@foo.com",
|
||||
@@ -132,10 +126,10 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer func() {
|
||||
a.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
}()
|
||||
|
||||
command, err := a.CreateCommand(&model.Command{
|
||||
command, err := th.App.CreateCommand(&model.Command{
|
||||
CreatorId: th.BasicUser.Id,
|
||||
TeamId: team.Id,
|
||||
Trigger: "foo",
|
||||
@@ -145,37 +139,37 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteCommand(command.Id)
|
||||
defer th.App.DeleteCommand(command.Id)
|
||||
|
||||
if command, err = a.GetCommand(command.Id); command == nil || err != nil {
|
||||
if command, err = th.App.GetCommand(command.Id); command == nil || err != nil {
|
||||
t.Fatal("unable to get new command")
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteTeam(team); err != nil {
|
||||
if err := th.App.PermanentDeleteTeam(team); err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if command, err = a.GetCommand(command.Id); command != nil || err == nil {
|
||||
if command, err = th.App.GetCommand(command.Id); command != nil || err == nil {
|
||||
t.Fatal("command wasn't deleted")
|
||||
}
|
||||
|
||||
// Test deleting a team with no channels.
|
||||
team = th.CreateTeam()
|
||||
defer func() {
|
||||
a.PermanentDeleteTeam(team)
|
||||
th.App.PermanentDeleteTeam(team)
|
||||
}()
|
||||
|
||||
if channels, err := a.GetPublicChannelsForTeam(team.Id, 0, 1000); err != nil {
|
||||
if channels, err := th.App.GetPublicChannelsForTeam(team.Id, 0, 1000); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
for _, channel := range *channels {
|
||||
if err2 := a.PermanentDeleteChannel(channel); err2 != nil {
|
||||
if err2 := th.App.PermanentDeleteChannel(channel); err2 != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.PermanentDeleteTeam(team); err != nil {
|
||||
if err := th.App.PermanentDeleteTeam(team); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,9 @@ import (
|
||||
)
|
||||
|
||||
func TestIsUsernameTaken(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
user := th.BasicUser
|
||||
taken := a.IsUsernameTaken(user.Username)
|
||||
taken := th.App.IsUsernameTaken(user.Username)
|
||||
|
||||
if !taken {
|
||||
t.Logf("the username '%v' should be taken", user.Username)
|
||||
@@ -31,7 +30,7 @@ func TestIsUsernameTaken(t *testing.T) {
|
||||
}
|
||||
|
||||
newUsername := "randomUsername"
|
||||
taken = a.IsUsernameTaken(newUsername)
|
||||
taken = th.App.IsUsernameTaken(newUsername)
|
||||
|
||||
if taken {
|
||||
t.Logf("the username '%v' should not be taken", newUsername)
|
||||
@@ -40,8 +39,7 @@ func TestIsUsernameTaken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckUserDomain(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
user := th.BasicUser
|
||||
|
||||
cases := []struct {
|
||||
@@ -67,13 +65,12 @@ func TestCheckUserDomain(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateOAuthUser(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
th := Setup().InitBasic()
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
glUser := oauthgitlab.GitLabUser{Id: int64(r.Intn(1000)) + 1, Username: "o" + model.NewId(), Email: model.NewId() + "@simulator.amazonses.com", Name: "Joram Wilander"}
|
||||
|
||||
json := glUser.ToJson()
|
||||
user, err := a.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
user, err := th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -82,7 +79,7 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
t.Fatal("usernames didn't match")
|
||||
}
|
||||
|
||||
a.PermanentDeleteUser(user)
|
||||
th.App.PermanentDeleteUser(user)
|
||||
|
||||
userCreation := utils.Cfg.TeamSettings.EnableUserCreation
|
||||
defer func() {
|
||||
@@ -90,7 +87,7 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
}()
|
||||
utils.Cfg.TeamSettings.EnableUserCreation = false
|
||||
|
||||
_, err = a.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
_, err = th.App.CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
|
||||
if err == nil {
|
||||
t.Fatal("should have failed - user creation disabled")
|
||||
}
|
||||
@@ -118,8 +115,7 @@ func TestCreateProfileImage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
a := Global()
|
||||
a.Setup()
|
||||
th := Setup()
|
||||
id := model.NewId()
|
||||
id2 := model.NewId()
|
||||
gitlabProvider := einterfaces.GetOauthProvider("gitlab")
|
||||
@@ -142,7 +138,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Username != gitlabUserObj.Username {
|
||||
@@ -157,7 +153,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Username == gitlabUserObj.Username {
|
||||
@@ -173,7 +169,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Email != gitlabUserObj.Email {
|
||||
@@ -192,7 +188,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.Email == gitlabUserObj.Email {
|
||||
@@ -207,7 +203,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.FirstName != "Updated" {
|
||||
@@ -221,7 +217,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(user.Id, t)
|
||||
a.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab")
|
||||
user = getUserFromDB(user.Id, t)
|
||||
|
||||
if user.LastName != "Lastname" {
|
||||
|
||||
@@ -11,9 +11,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateWebhookPost(t *testing.T) {
|
||||
a := Global()
|
||||
th := a.Setup().InitBasic()
|
||||
defer a.TearDown()
|
||||
th := Setup().InitBasic()
|
||||
defer th.App.TearDown()
|
||||
|
||||
enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
|
||||
defer func() {
|
||||
@@ -23,13 +22,13 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
|
||||
utils.SetDefaultRolesBasedOnConfig()
|
||||
|
||||
hook, err := a.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
||||
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
defer a.DeleteIncomingWebhook(hook.Id)
|
||||
defer th.App.DeleteIncomingWebhook(hook.Id)
|
||||
|
||||
post, err := a.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", model.StringInterface{
|
||||
post, err := th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, "foo", "user", "http://iconurl", model.StringInterface{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
Text: "text",
|
||||
|
||||
Ссылка в новой задаче
Block a user