notifications

package
v0.0.85-test Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2023 License: AGPL-3.0 Imports: 29 Imported by: 208

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NetClient = &netClient

NetClient is used to export original in test.

Functions

func SetWebhookClient

func SetWebhookClient(client WebhookClient)

SetWebhookClient is used to mock in test.

Types

type AttachedFile

type AttachedFile struct {
	Name    string
	Content []byte
}

AttachedFile struct represents email attached files.

type EmailSender

type EmailSender interface {
	SendEmailCommandHandlerSync(ctx context.Context, cmd *models.SendEmailCommandSync) error
	SendEmailCommandHandler(ctx context.Context, cmd *models.SendEmailCommand) error
}

type FakeDisconnectedMailer

type FakeDisconnectedMailer struct{}

func NewFakeDisconnectedMailer

func NewFakeDisconnectedMailer() *FakeDisconnectedMailer

func (*FakeDisconnectedMailer) Send

func (fdm *FakeDisconnectedMailer) Send(messages ...*Message) (int, error)

type FakeMailer

type FakeMailer struct {
	Sent []*Message
}

func NewFakeMailer

func NewFakeMailer() *FakeMailer

func (*FakeMailer) Send

func (fm *FakeMailer) Send(messages ...*Message) (int, error)

type GetUserByLoginFunc

type GetUserByLoginFunc = func(c context.Context, login string) (*models.User, error)

type Mailer

type Mailer interface {
	Send(messages ...*Message) (int, error)
}

func ProvideSmtpService

func ProvideSmtpService(cfg *setting.Cfg) (Mailer, error)

type Message

type Message struct {
	To            []string
	SingleEmail   bool
	From          string
	Subject       string
	Body          map[string]string
	Info          string
	ReplyTo       []string
	EmbeddedFiles []string
	AttachedFiles []*AttachedFile
}

Message is representation of the email message.

type NotificationService

type NotificationService struct {
	Bus bus.Bus
	Cfg *setting.Cfg
	// contains filtered or unexported fields
}

func ProvideService

func ProvideService(bus bus.Bus, cfg *setting.Cfg, mailer Mailer, store TempUserStore) (*NotificationService, error)

func (*NotificationService) GetMailer

func (ns *NotificationService) GetMailer() Mailer

func (*NotificationService) Run

func (*NotificationService) Send

func (ns *NotificationService) Send(msg *Message) (int, error)

func (*NotificationService) SendEmailCommandHandler

func (ns *NotificationService) SendEmailCommandHandler(ctx context.Context, cmd *models.SendEmailCommand) error

func (*NotificationService) SendEmailCommandHandlerSync

func (ns *NotificationService) SendEmailCommandHandlerSync(ctx context.Context, cmd *models.SendEmailCommandSync) error

func (*NotificationService) SendResetPasswordEmail

func (ns *NotificationService) SendResetPasswordEmail(ctx context.Context, cmd *models.SendResetPasswordEmailCommand) error

func (*NotificationService) SendWebhookSync

func (ns *NotificationService) SendWebhookSync(ctx context.Context, cmd *models.SendWebhookSync) error

func (*NotificationService) ValidateResetPasswordCode

func (ns *NotificationService) ValidateResetPasswordCode(ctx context.Context, query *models.ValidateResetPasswordCodeQuery, userByLogin GetUserByLoginFunc) error

type NotificationServiceMock

type NotificationServiceMock struct {
	Webhook     models.SendWebhookSync
	EmailSync   models.SendEmailCommandSync
	Email       models.SendEmailCommand
	ShouldError error

	WebhookHandler   func(context.Context, *models.SendWebhookSync) error
	EmailHandlerSync func(context.Context, *models.SendEmailCommandSync) error
	EmailHandler     func(context.Context, *models.SendEmailCommand) error
}

func MockNotificationService

func MockNotificationService() *NotificationServiceMock

func (*NotificationServiceMock) SendEmailCommandHandler

func (ns *NotificationServiceMock) SendEmailCommandHandler(ctx context.Context, cmd *models.SendEmailCommand) error

func (*NotificationServiceMock) SendEmailCommandHandlerSync

func (ns *NotificationServiceMock) SendEmailCommandHandlerSync(ctx context.Context, cmd *models.SendEmailCommandSync) error

func (*NotificationServiceMock) SendWebhookSync

func (ns *NotificationServiceMock) SendWebhookSync(ctx context.Context, cmd *models.SendWebhookSync) error

type Service

type Service interface {
	WebhookSender
	EmailSender
}

type SmtpClient

type SmtpClient struct {
	// contains filtered or unexported fields
}

func NewSmtpClient

func NewSmtpClient(cfg setting.SmtpSettings) (*SmtpClient, error)

func (*SmtpClient) Send

func (sc *SmtpClient) Send(messages ...*Message) (int, error)

type TempUserStore

type TempUserStore interface {
	UpdateTempUserWithEmailSent(ctx context.Context, cmd *models.UpdateTempUserWithEmailSentCommand) error
}

type Webhook

type Webhook struct {
	Url         string
	User        string
	Password    string
	Body        string
	HttpMethod  string
	HttpHeader  map[string]string
	ContentType string

	// Validation is a function that will validate the response body and statusCode of the webhook. Any returned error will cause the webhook request to be considered failed.
	// This can be useful when a webhook service communicates failures in creative ways, such as using the response body instead of the status code.
	Validation func(body []byte, statusCode int) error
}

type WebhookClient

type WebhookClient interface {
	Do(req *http.Request) (*http.Response, error)
}

WebhookClient exists to mock the client in tests.

type WebhookSender

type WebhookSender interface {
	SendWebhookSync(ctx context.Context, cmd *models.SendWebhookSync) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL