forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pocketbase#1069] added default Message-ID and more options to custom…
…ize the mail message
- Loading branch information
1 parent
c4a660d
commit 3e1a196
Showing
11 changed files
with
186 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,12 +303,12 @@ func TestSettingsTestEmail(t *testing.T) { | |
t.Fatalf("[verification] Expected 1 sent email, got %d", app.TestMailer.TotalSend) | ||
} | ||
|
||
if app.TestMailer.LastToAddress.Address != "[email protected]" { | ||
t.Fatalf("[verification] Expected the email to be sent to %s, got %s", "[email protected]", app.TestMailer.LastToAddress.Address) | ||
if app.TestMailer.LastMessage.To.Address != "[email protected]" { | ||
t.Fatalf("[verification] Expected the email to be sent to %s, got %s", "[email protected]", app.TestMailer.LastMessage.To.Address) | ||
} | ||
|
||
if !strings.Contains(app.TestMailer.LastHtmlBody, "Verify") { | ||
t.Fatalf("[verification] Expected to sent a verification email, got \n%v\n%v", app.TestMailer.LastHtmlSubject, app.TestMailer.LastHtmlBody) | ||
if !strings.Contains(app.TestMailer.LastMessage.HTML, "Verify") { | ||
t.Fatalf("[verification] Expected to sent a verification email, got \n%v\n%v", app.TestMailer.LastMessage.Subject, app.TestMailer.LastMessage.HTML) | ||
} | ||
}, | ||
ExpectedStatus: 204, | ||
|
@@ -334,12 +334,12 @@ func TestSettingsTestEmail(t *testing.T) { | |
t.Fatalf("[password-reset] Expected 1 sent email, got %d", app.TestMailer.TotalSend) | ||
} | ||
|
||
if app.TestMailer.LastToAddress.Address != "[email protected]" { | ||
t.Fatalf("[password-reset] Expected the email to be sent to %s, got %s", "[email protected]", app.TestMailer.LastToAddress.Address) | ||
if app.TestMailer.LastMessage.To.Address != "[email protected]" { | ||
t.Fatalf("[password-reset] Expected the email to be sent to %s, got %s", "[email protected]", app.TestMailer.LastMessage.To.Address) | ||
} | ||
|
||
if !strings.Contains(app.TestMailer.LastHtmlBody, "Reset password") { | ||
t.Fatalf("[password-reset] Expected to sent a password-reset email, got \n%v\n%v", app.TestMailer.LastHtmlSubject, app.TestMailer.LastHtmlBody) | ||
if !strings.Contains(app.TestMailer.LastMessage.HTML, "Reset password") { | ||
t.Fatalf("[password-reset] Expected to sent a password-reset email, got \n%v\n%v", app.TestMailer.LastMessage.Subject, app.TestMailer.LastMessage.HTML) | ||
} | ||
}, | ||
ExpectedStatus: 204, | ||
|
@@ -365,12 +365,12 @@ func TestSettingsTestEmail(t *testing.T) { | |
t.Fatalf("[email-change] Expected 1 sent email, got %d", app.TestMailer.TotalSend) | ||
} | ||
|
||
if app.TestMailer.LastToAddress.Address != "[email protected]" { | ||
t.Fatalf("[email-change] Expected the email to be sent to %s, got %s", "[email protected]", app.TestMailer.LastToAddress.Address) | ||
if app.TestMailer.LastMessage.To.Address != "[email protected]" { | ||
t.Fatalf("[email-change] Expected the email to be sent to %s, got %s", "[email protected]", app.TestMailer.LastMessage.To.Address) | ||
} | ||
|
||
if !strings.Contains(app.TestMailer.LastHtmlBody, "Confirm new email") { | ||
t.Fatalf("[email-change] Expected to sent a confirm new email email, got \n%v\n%v", app.TestMailer.LastHtmlSubject, app.TestMailer.LastHtmlBody) | ||
if !strings.Contains(app.TestMailer.LastMessage.HTML, "Confirm new email") { | ||
t.Fatalf("[email-change] Expected to sent a confirm new email email, got \n%v\n%v", app.TestMailer.LastMessage.Subject, app.TestMailer.LastMessage.HTML) | ||
} | ||
}, | ||
ExpectedStatus: 204, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,27 @@ | ||
package tests | ||
|
||
import ( | ||
"io" | ||
"net/mail" | ||
|
||
"github.com/pocketbase/pocketbase/tools/mailer" | ||
) | ||
|
||
var _ mailer.Mailer = (*TestMailer)(nil) | ||
|
||
// TestMailer is a mock `mailer.Mailer` implementation. | ||
type TestMailer struct { | ||
TotalSend int | ||
LastFromAddress mail.Address | ||
LastToAddress mail.Address | ||
LastHtmlSubject string | ||
LastHtmlBody string | ||
TotalSend int | ||
LastMessage mailer.Message | ||
} | ||
|
||
// Reset clears any previously test collected data. | ||
func (m *TestMailer) Reset() { | ||
m.TotalSend = 0 | ||
m.LastFromAddress = mail.Address{} | ||
m.LastToAddress = mail.Address{} | ||
m.LastHtmlSubject = "" | ||
m.LastHtmlBody = "" | ||
m.LastMessage = mailer.Message{} | ||
} | ||
|
||
// Send implements `mailer.Mailer` interface. | ||
func (m *TestMailer) Send(fromEmail mail.Address, toEmail mail.Address, subject string, html string, attachments map[string]io.Reader) error { | ||
m.LastFromAddress = fromEmail | ||
m.LastToAddress = toEmail | ||
m.LastHtmlSubject = subject | ||
m.LastHtmlBody = html | ||
m.TotalSend++ | ||
func (c *TestMailer) Send(m *mailer.Message) error { | ||
c.TotalSend++ | ||
c.LastMessage = *m | ||
|
||
return nil | ||
} |
Oops, something went wrong.