2019-09-24 01:02:49 -04:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-09-24 01:02:49 -04:00
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
2024-05-17 10:45:41 -04:00
|
|
|
"context"
|
2019-09-24 01:02:49 -04:00
|
|
|
"testing"
|
|
|
|
|
2021-11-12 09:36:47 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2024-05-17 10:45:41 -04:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"code.gitea.io/gitea/modules/templates"
|
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
"code.gitea.io/gitea/modules/translation"
|
2023-09-08 00:51:15 -04:00
|
|
|
|
|
|
|
_ "code.gitea.io/gitea/models/actions"
|
2024-05-17 10:45:41 -04:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-09-24 01:02:49 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-09-27 21:38:53 -04:00
|
|
|
unittest.MainTest(m)
|
2019-09-24 01:02:49 -04:00
|
|
|
}
|
2024-05-17 10:45:41 -04:00
|
|
|
|
2024-07-22 18:17:06 -04:00
|
|
|
func AssertTranslatedLocale(t *testing.T, message string, prefixes ...string) {
|
2024-05-17 10:45:41 -04:00
|
|
|
t.Helper()
|
|
|
|
for _, prefix := range prefixes {
|
|
|
|
assert.NotContains(t, message, prefix, "there is an untranslated locale prefix")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 18:17:06 -04:00
|
|
|
func MockMailSettings(send func(msgs ...*Message)) func() {
|
2024-05-17 10:45:41 -04:00
|
|
|
translation.InitLocales(context.Background())
|
|
|
|
subjectTemplates, bodyTemplates = templates.Mailer(context.Background())
|
|
|
|
mailService := setting.Mailer{
|
|
|
|
From: "test@gitea.com",
|
|
|
|
}
|
|
|
|
cleanups := []func(){
|
|
|
|
test.MockVariableValue(&setting.MailService, &mailService),
|
|
|
|
test.MockVariableValue(&setting.Domain, "localhost"),
|
|
|
|
test.MockVariableValue(&SendAsync, send),
|
|
|
|
}
|
|
|
|
return func() {
|
|
|
|
for _, cleanup := range cleanups {
|
|
|
|
cleanup()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|