(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func 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 | |
| 48 | func TestSendRecordPasswordReset(t *testing.T) { |
| 49 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…