2022-07-06 23:19:05 +02:00
|
|
|
package mails_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pocketbase/pocketbase/mails"
|
|
|
|
"github.com/pocketbase/pocketbase/tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSendAdminPasswordReset(t *testing.T) {
|
|
|
|
testApp, _ := tests.NewTestApp()
|
|
|
|
defer testApp.Cleanup()
|
|
|
|
|
|
|
|
// ensure that action url normalization will be applied
|
|
|
|
testApp.Settings().Meta.AppUrl = "http://localhost:8090////"
|
|
|
|
|
|
|
|
admin, _ := testApp.Dao().FindAdminByEmail("test@example.com")
|
|
|
|
|
|
|
|
err := mails.SendAdminPasswordReset(testApp, admin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if testApp.TestMailer.TotalSend != 1 {
|
|
|
|
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedParts := []string{
|
2022-08-12 16:08:36 +02:00
|
|
|
"http://localhost:8090/_/#/confirm-password-reset/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
for _, part := range expectedParts {
|
2022-11-21 14:53:05 +02:00
|
|
|
if !strings.Contains(testApp.TestMailer.LastMessage.HTML, part) {
|
|
|
|
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage.HTML)
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|