Make all emails with the same pattern on subject (#5198)
* make all email subject standard * move SendPasswordReset to app/email.go update per review * update email subjects per review update error fix expected subject * Update email_test.go * Update en.json * fix missing quotes
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
c1d5e9a9e6
Коммит
e5065cf757
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
@@ -18,8 +19,8 @@ func TestSendChangeUsernameEmail(t *testing.T) {
|
||||
var newUsername string = "fancyusername"
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var expectedPartialMessage string = "Your username for Mattermost has been changed to " + newUsername + "."
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your username has changed for Mattermost"
|
||||
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)
|
||||
@@ -33,7 +34,7 @@ func TestSendChangeUsernameEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(emailTo, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -55,7 +56,7 @@ func TestSendEmailChangeVerifyEmail(t *testing.T) {
|
||||
var locale string = "en"
|
||||
var siteURL string = ""
|
||||
var expectedPartialMessage string = "You updated your email"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Verify new email address for Mattermost"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Verify new email address"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(newUserEmail)
|
||||
@@ -69,7 +70,7 @@ func TestSendEmailChangeVerifyEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(newUserEmail, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -95,7 +96,7 @@ func TestSendEmailChangeEmail(t *testing.T) {
|
||||
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 for Mattermost"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your email address has changed"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(oldEmail)
|
||||
@@ -109,7 +110,7 @@ func TestSendEmailChangeEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(oldEmail, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -145,7 +146,7 @@ func TestSendVerifyEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(userEmail, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -171,7 +172,7 @@ func TestSendSignInChangeEmail(t *testing.T) {
|
||||
var siteURL string = ""
|
||||
var method string = "AD/LDAP"
|
||||
var expectedPartialMessage string = "You updated your sign-in method on Mattermost to " + method + "."
|
||||
var expectedSubject string = "You updated your sign-in method on Mattermost"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] You updated your sign-in method on " + utils.Cfg.TeamSettings.SiteName
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
@@ -185,7 +186,7 @@ func TestSendSignInChangeEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -208,7 +209,7 @@ func TestSendWelcomeEmail(t *testing.T) {
|
||||
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 = "You joined test.mattermost.io"
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] You joined test.mattermost.io"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
@@ -222,7 +223,7 @@ func TestSendWelcomeEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -277,7 +278,7 @@ func TestSendPasswordChangeEmail(t *testing.T) {
|
||||
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 = "Your password has been updated for " + utils.Cfg.TeamSettings.SiteName + " on " + utils.Cfg.TeamSettings.SiteName
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your password has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
@@ -291,7 +292,7 @@ func TestSendPasswordChangeEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -313,7 +314,7 @@ func TestSendMfaChangeEmail(t *testing.T) {
|
||||
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 = "Your MFA has been updated on " + utils.Cfg.TeamSettings.SiteName
|
||||
var expectedSubject string = "[" + utils.Cfg.TeamSettings.SiteName + "] Your MFA has been updated"
|
||||
|
||||
//Delete all the messages before check the sample email
|
||||
utils.DeleteMailBox(email)
|
||||
@@ -327,7 +328,7 @@ func TestSendMfaChangeEmail(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Fatal("Wrong Subject")
|
||||
}
|
||||
@@ -375,7 +376,7 @@ func TestSendInviteEmails(t *testing.T) {
|
||||
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 = senderName + " invited you to join " + th.BasicTeam.DisplayName + " Team on " + utils.Cfg.TeamSettings.SiteName
|
||||
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)
|
||||
@@ -388,7 +389,7 @@ func TestSendInviteEmails(t *testing.T) {
|
||||
t.Fatal("Wrong To recipient")
|
||||
} else {
|
||||
if resultsEmail, err := utils.GetMessageFromMailbox(email1, resultsMailbox[0].ID); err == nil {
|
||||
if !strings.Contains(resultsEmail.Subject, expectedSubject) {
|
||||
if resultsEmail.Subject != expectedSubject {
|
||||
t.Log(resultsEmail.Subject)
|
||||
t.Log(expectedSubject)
|
||||
t.Fatal("Wrong Subject")
|
||||
@@ -417,3 +418,48 @@ func TestSendInviteEmails(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPasswordReset(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
utils.LoadConfig("config.json")
|
||||
|
||||
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 := 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")
|
||||
}
|
||||
var recoveryKey *model.PasswordRecovery
|
||||
if result := <-Srv.Store.PasswordRecovery().Get(th.BasicUser.Id); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
} else {
|
||||
recoveryKey = result.Data.(*model.PasswordRecovery)
|
||||
if !strings.Contains(resultsEmail.Body.Text, recoveryKey.Code) {
|
||||
t.Log(resultsEmail.Body.Text)
|
||||
t.Log(recoveryKey.Code)
|
||||
t.Fatal("Received wrong recovery code")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user