MCPcopy
hub / github.com/pocketbase/pocketbase / TestSendRecordVerification

Function TestSendRecordVerification

mails/record_test.go:79–108  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestSendRecordVerification(t *testing.T) {
80 t.Parallel()
81
82 testApp, _ := tests.NewTestApp()
83 defer testApp.Cleanup()
84
85 user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
86
87 // to test that it is escaped
88 user.Set("name", "<p>"+user.GetString("name")+"</p>")
89
90 err := mails.SendRecordVerification(testApp, user)
91 if err != nil {
92 t.Fatal(err)
93 }
94
95 if testApp.TestMailer.TotalSend() != 1 {
96 t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
97 }
98
99 expectedParts := []string{
100 html.EscapeString(user.GetString("name")) + "{RECORD:tokenKey}", // the record name as {RECORD:name}
101 "http://localhost:8090/_/#/auth/confirm-verification/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
102 }
103 for _, part := range expectedParts {
104 if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
105 t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
106 }
107 }
108}
109
110func TestSendRecordChangeEmail(t *testing.T) {
111 t.Parallel()

Callers

nothing calls this directly

Calls 8

CleanupMethod · 0.95
NewTestAppFunction · 0.92
SendRecordVerificationFunction · 0.92
GetStringMethod · 0.80
TotalSendMethod · 0.80
LastMessageMethod · 0.80
FindFirstRecordByDataMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…