MCPcopy
hub / github.com/pocketbase/pocketbase / TestSendRecordAuthAlert

Function TestSendRecordAuthAlert

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

Source from the content-addressed store, hash-verified

10)
11
12func TestSendRecordAuthAlert(t *testing.T) {
13 t.Parallel()
14
15 testApp, _ := tests.NewTestApp()
16 defer testApp.Cleanup()
17
18 info := "<p>test_info</p>"
19
20 user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
21
22 // to test that it is escaped
23 user.Set("name", "<p>"+user.GetString("name")+"</p>")
24
25 err := mails.SendRecordAuthAlert(testApp, user, info)
26 if err != nil {
27 t.Fatal(err)
28 }
29
30 if testApp.TestMailer.TotalSend() != 1 {
31 t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
32 }
33
34 expectedParts := []string{
35 html.EscapeString(user.GetString("name")) + "{RECORD:tokenKey}", // public and private record placeholder checks
36 "login to your " + testApp.Settings().Meta.AppName + " account from a new location",
37 "If this was you",
38 "If this wasn't you",
39 html.EscapeString(info),
40 }
41 for _, part := range expectedParts {
42 if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
43 t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
44 }
45 }
46}
47
48func TestSendRecordPasswordReset(t *testing.T) {
49 t.Parallel()

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…