Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Sender interface, split SendEvents method #794

Open
Dimedrolity opened this issue Oct 27, 2022 · 1 comment
Open

Refactor Sender interface, split SendEvents method #794

Dimedrolity opened this issue Oct 27, 2022 · 1 comment

Comments

@Dimedrolity
Copy link
Contributor

Overview

We have Sender interface with SendEvents method.

// Sender interface for implementing specified contact type sender
type Sender interface {
	SendEvents(events NotificationEvents, contact ContactData, trigger TriggerData, plot [][]byte, throttled bool) error
	Init(senderSettings map[string]string, logger Logger, location *time.Location, dateTimeFormat string) error
}

SendEvents is public method of Sender interface, so it is part of public API.

Problem

Now public API is doesn't allow to test that message is built correctly, because SendEvents has only error in return params. How to check that message is built correctly?

Quick solution (current solution)

Now we have test of internal methods buildMessage and sendMessage.

Right solution (TODO)

Need to separate interface method SendEvents to two methods - BuildMessage and SendMessage - to test methods separately as public API. Also method doesn't fit SRP, because it has two reasons to change, for example when need to change message format and need to change delivery of message.

@Dimedrolity
Copy link
Contributor Author

After that we can separate to 2 interfaces, Sender and MessageBuilder. Also we can extract Message struct. Just thoughts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant