-
Notifications
You must be signed in to change notification settings - Fork 6
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
Replace Mockito mocked EmailSender in tests #2547
Conversation
As part of investigating removing the mocking from the tests (for #2534), this switches from using a `mock(EmailSender)` to creating a bean under test which tracks the calls made to it in a simple list. If the `replace.mailjet.factory` property is set in a test then the standard `MailJetFactory` is replaced by our factory. This generates EmailSender instances (for HTML and TEXT) which track the calls to their methods in a list of strings. We can also remove the `setEmailSender` methods which we had to use to force the mock bean into the running services. I believe this has uncovered a bug in the Guild Service whereby too many emails are being sent. (see `com.objectcomputing.checkins.services.guild.GuildControllerTest#testEmailSentToGuildLeadWhenGuildMembersAdded`) I would have expected a single email, but we are sending 2... 🤔
assertEquals(2, emailSender.events.size()); | ||
assertEquals( | ||
List.of( | ||
// Email to the Guild lead | ||
List.of("SEND_EMAIL", "null", "null", "Membership changes have been made to the Ninja guild", "<h3>Bill Charles has joined the Ninja guild.</h3><a href=\"https://checkins.objectcomputing.com/guilds\">Click here</a> to view the changes in the Check-Ins app.", memberProfile.getWorkEmail() + "," + memberProfile2.getWorkEmail()), | ||
// Email to both the Guild leads | ||
List.of("SEND_EMAIL", "null", "null", "Membership Changes have been made to the Ninja guild", "<h3>Changes have been made to the Ninja guild.</h3><h4>The following members have been added:</h4><ul><li>Bill Charles</li></ul><a href=\"https://checkins.objectcomputing.com/guilds\">Click here</a> to view the changes in the Check-Ins app.", memberProfile.getWorkEmail() + "," + memberProfile2.getWorkEmail()) | ||
), | ||
emailSender.events | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is a bug and we may be sending too many emails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised #2549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potential PR to fix is in #2551
If that gets merged, we need to remove one of the Lists in this assert (and reduce the size assertion to 1)
assertEquals(2, emailSender.events.size()); | ||
assertEquals(List.of( | ||
List.of("SEND_EMAIL", "null", "null", "Membership Changes have been made to the Ninja guild", "<h3>Bill Charles has left the Ninja guild.</h3><a href=\"https://checkins.objectcomputing.com/guilds\">Click here</a> to view the changes in the Check-Ins app.", memberProfile.getWorkEmail()), | ||
List.of("SEND_EMAIL", "null", "null", "Membership Changes have been made to the Ninja guild", "<h3>Changes have been made to the Ninja guild.</h3><h4>The following members have been removed:</h4><ul><li>Bill Charles</li></ul><a href=\"https://checkins.objectcomputing.com/guilds\">Click here</a> to view the changes in the Check-Ins app.", memberProfile.getWorkEmail()) | ||
), | ||
emailSender.events | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here... I believe this is too many emails being sent 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raised #2549
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potential PR to fix is in #2551
If that gets merged, we need to remove one of the Lists in this assert (and reduce the size assertion to 1)
As part of investigating removing the mocking from the tests (for #2534), this switches from using a
mock(EmailSender)
to creating a bean under test which tracks the calls made to it in a simple list.If the
replace.mailjet.factory
property is set in a test then the standardMailJetFactory
is replaced by our factory.This generates EmailSender instances (for HTML and TEXT) which track the calls to their methods in a list of strings.
We can also remove the
setEmailSender
methods which we had to use to force the mock bean into the running services.I believe this has uncovered a bug in the Guild Service whereby too many emails are being sent. (see
com.objectcomputing.checkins.services.guild.GuildControllerTest#testEmailSentToGuildLeadWhenGuildMembersAdded
) I would have expected a single email, but we are sending 2... 🤔