func TestRecover_sendRecoverEmail(t *testing.T) { t.Parallel() r, _, _ := testSetup() mailer := mocks.NewMockMailer() r.EmailSubjectPrefix = "foo " r.RootURL = "bar" r.Mailer = mailer r.sendRecoverEmail("[email protected]", "abc=") if len(mailer.Last.To) != 1 { t.Error("Expected 1 to email") } if mailer.Last.To[0] != "[email protected]" { t.Error("Unexpected to email:", mailer.Last.To[0]) } if mailer.Last.Subject != "foo Password Reset" { t.Error("Unexpected subject:", mailer.Last.Subject) } url := fmt.Sprintf("%s/recover/complete?token=abc%%3D", r.RootURL) if !strings.Contains(mailer.Last.HTMLBody, url) { t.Error("Expected HTMLBody to contain url:", url) } if !strings.Contains(mailer.Last.TextBody, url) { t.Error("Expected TextBody to contain url:", url) } }
func TestRecover_sendRecoverMail_FailToSend(t *testing.T) { t.Parallel() r, _, logger := testSetup() mailer := mocks.NewMockMailer() mailer.SendErr = "failed to send" r.Mailer = mailer r.sendRecoverEmail("", "") if !strings.Contains(logger.String(), "failed to send") { t.Error("Expected logged to have msg:", "failed to send") } }