MCPcopy
hub / github.com/pocketbase/pocketbase / TestSendRecordPasswordReset

Function TestSendRecordPasswordReset

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

Source from the content-addressed store, hash-verified

46}
47
48func TestSendRecordPasswordReset(t *testing.T) {
49 t.Parallel()
50
51 testApp, _ := tests.NewTestApp()
52 defer testApp.Cleanup()
53
54 user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
55
56 // to test that it is escaped
57 user.Set("name", "<p>"+user.GetString("name")+"</p>")
58
59 err := mails.SendRecordPasswordReset(testApp, user)
60 if err != nil {
61 t.Fatal(err)
62 }
63
64 if testApp.TestMailer.TotalSend() != 1 {
65 t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
66 }
67
68 expectedParts := []string{
69 html.EscapeString(user.GetString("name")) + "{RECORD:tokenKey}", // the record name as {RECORD:name}
70 "http://localhost:8090/_/#/auth/confirm-password-reset/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.",
71 }
72 for _, part := range expectedParts {
73 if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
74 t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
75 }
76 }
77}
78
79func TestSendRecordVerification(t *testing.T) {
80 t.Parallel()

Callers

nothing calls this directly

Calls 8

CleanupMethod · 0.95
NewTestAppFunction · 0.92
SendRecordPasswordResetFunction · 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…