You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-11-29 16:58:00 +02:00
initial v0.8 pre-release
This commit is contained in:
87
mails/record_test.go
Normal file
87
mails/record_test.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package mails_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pocketbase/pocketbase/mails"
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
expectedParts := []string{
|
||||
"http://localhost:8090/_/#/auth/confirm-password-reset/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastHtmlBody, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastHtmlBody)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendRecordVerification(t *testing.T) {
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
user, _ := testApp.Dao().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)
|
||||
}
|
||||
|
||||
expectedParts := []string{
|
||||
"http://localhost:8090/_/#/auth/confirm-verification/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastHtmlBody, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastHtmlBody)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendRecordChangeEmail(t *testing.T) {
|
||||
testApp, _ := tests.NewTestApp()
|
||||
defer testApp.Cleanup()
|
||||
|
||||
user, _ := testApp.Dao().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)
|
||||
}
|
||||
|
||||
expectedParts := []string{
|
||||
"http://localhost:8090/_/#/auth/confirm-email-change/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
|
||||
}
|
||||
for _, part := range expectedParts {
|
||||
if !strings.Contains(testApp.TestMailer.LastHtmlBody, part) {
|
||||
t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastHtmlBody)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user