MCPcopy
hub / github.com/pocketbase/pocketbase / TestSendRecordOTP

Function TestSendRecordOTP

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

Source from the content-addressed store, hash-verified

139}
140
141func TestSendRecordOTP(t *testing.T) {
142 t.Parallel()
143
144 testApp, _ := tests.NewTestApp()
145 defer testApp.Cleanup()
146
147 user, _ := testApp.FindFirstRecordByData("users", "email", "test@example.com")
148
149 // to test that it is escaped
150 user.Set("name", "<p>"+user.GetString("name")+"</p>")
151
152 err := mails.SendRecordOTP(testApp, user, "test_otp_id", "test_otp_code")
153 if err != nil {
154 t.Fatal(err)
155 }
156
157 if testApp.TestMailer.TotalSend() != 1 {
158 t.Fatalf("Expected one email to be sent, got %d", testApp.TestMailer.TotalSend())
159 }
160
161 expectedParts := []string{
162 html.EscapeString(user.GetString("name")) + "{RECORD:tokenKey}", // the record name as {RECORD:name}
163 "one-time password",
164 "test_otp_code",
165 }
166 for _, part := range expectedParts {
167 if !strings.Contains(testApp.TestMailer.LastMessage().HTML, part) {
168 t.Fatalf("Couldn't find %s \nin\n %s", part, testApp.TestMailer.LastMessage().HTML)
169 }
170 }
171}

Callers

nothing calls this directly

Calls 8

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