merge v0.23.0-rc changes
This commit is contained in:
+60
-30
@@ -8,31 +8,32 @@ import (
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
)
|
||||
|
||||
func TestSendRecordPasswordLoginAlert(t *testing.T) {
|
||||
func TestSendRecordAuthAlert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
// ensure that action url normalization will be applied
|
||||
testApp.Settings().Meta.AppUrl = "http://localhost:8090////"
|
||||
user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
|
||||
|
||||
user, _ := testApp.Dao().FindFirstRecordByData("users", "email", "test@example.com")
|
||||
|
||||
err := mails.SendRecordPasswordLoginAlert(testApp, user, "test1", "test2")
|
||||
err := mails.SendRecordAuthAlert(testApp, user)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if testApp.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend)
|
||||
if testApp.TestMailer.TotalSend() != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
|
||||
}
|
||||
|
||||
expectedParts := []string{"using a password", "OAuth2", "test1", "test2", "auth linked"}
|
||||
|
||||
expectedParts := []string{
|
||||
user.GetString("name") + "{RECORD:tokenKey}", // public and private record placeholder checks
|
||||
"login to your " + testApp.Settings().Meta.AppName + " account from a new location",
|
||||
"If this was you",
|
||||
"If this wasn't you",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage.HTML, part) {
|
||||
t.Fatalf("Couldn't find %s\n in\n %s", part, testApp.TestMailer.LastMessage.HTML)
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,26 +44,24 @@ func TestSendRecordPasswordReset(t *testing.T) {
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
// ensure that action url normalization will be applied
|
||||
testApp.Settings().Meta.AppUrl = "http://localhost:8090////"
|
||||
|
||||
user, _ := testApp.Dao().FindFirstRecordByData("users", "email", "test@example.com")
|
||||
user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
|
||||
|
||||
err := mails.SendRecordPasswordReset(testApp, user)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if testApp.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend)
|
||||
if testApp.TestMailer.TotalSend() != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
|
||||
}
|
||||
|
||||
expectedParts := []string{
|
||||
user.GetString("name") + "{RECORD:tokenKey}", // the record name as {RECORD:name}
|
||||
"http://localhost:8090/_/#/auth/confirm-password-reset/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage.HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage.HTML)
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,23 +72,24 @@ func TestSendRecordVerification(t *testing.T) {
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
user, _ := testApp.Dao().FindFirstRecordByData("users", "email", "test@example.com")
|
||||
user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
|
||||
|
||||
err := mails.SendRecordVerification(testApp, user)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if testApp.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend)
|
||||
if testApp.TestMailer.TotalSend() != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
|
||||
}
|
||||
|
||||
expectedParts := []string{
|
||||
user.GetString("name") + "{RECORD:tokenKey}", // the record name as {RECORD:name}
|
||||
"http://localhost:8090/_/#/auth/confirm-verification/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage.HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage.HTML)
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,23 +100,53 @@ func TestSendRecordChangeEmail(t *testing.T) {
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
user, _ := testApp.Dao().FindFirstRecordByData("users", "email", "test@example.com")
|
||||
user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
|
||||
|
||||
err := mails.SendRecordChangeEmail(testApp, user, "new_test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if testApp.TestMailer.TotalSend != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend)
|
||||
if testApp.TestMailer.TotalSend() != 1 {
|
||||
t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
|
||||
}
|
||||
|
||||
expectedParts := []string{
|
||||
user.GetString("name") + "{RECORD:tokenKey}", // the record name as {RECORD:name}
|
||||
"http://localhost:8090/_/#/auth/confirm-email-change/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage.HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage.HTML)
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendRecordOTP(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
|
||||
|
||||
err := mails.SendRecordOTP(testApp, user, "test_otp_id", "test_otp_code")
|
||||
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{
|
||||
user.GetString("name") + "{RECORD:tokenKey}", // the record name as {RECORD:name}
|
||||
"one-time password",
|
||||
"test_otp_code",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user