(t *testing.T)
| 139 | } |
| 140 | |
| 141 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…