2022-07-06 23:19:05 +02:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pocketbase/pocketbase/tools/mailer"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ mailer.Mailer = (*TestMailer)(nil)
|
|
|
|
|
|
|
|
// TestMailer is a mock `mailer.Mailer` implementation.
|
|
|
|
type TestMailer struct {
|
2022-11-21 14:53:05 +02:00
|
|
|
TotalSend int
|
|
|
|
LastMessage mailer.Message
|
2023-12-29 23:31:54 +02:00
|
|
|
|
|
|
|
// @todo consider deprecating the above 2 fields?
|
|
|
|
SentMessages []mailer.Message
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset clears any previously test collected data.
|
2024-01-23 20:56:14 +02:00
|
|
|
func (tm *TestMailer) Reset() {
|
|
|
|
tm.TotalSend = 0
|
|
|
|
tm.LastMessage = mailer.Message{}
|
|
|
|
tm.SentMessages = nil
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send implements `mailer.Mailer` interface.
|
2024-01-23 20:56:14 +02:00
|
|
|
func (tm *TestMailer) Send(m *mailer.Message) error {
|
|
|
|
tm.TotalSend++
|
|
|
|
tm.LastMessage = *m
|
|
|
|
tm.SentMessages = append(tm.SentMessages, tm.LastMessage)
|
2022-11-21 14:53:05 +02:00
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
return nil
|
|
|
|
}
|