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

Add refute_email_delivered_with helper, tests #484

Merged

Conversation

mtarnovan
Copy link
Contributor

See #474

Let me know if you want to see more tests or if i missed anything obvious. Thanks.

@@ -203,6 +203,26 @@ defmodule Bamboo.Test do
end
end

defmacro refute_email_delivered_with(email_params) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!! Thoughts on adding some documentation for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|> TestMailer.deliver_now()

refute_email_delivered_with(text_body: ~r/tea/)
refute_email_delivered_with(to: "bla")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there can only be one assertion of this type per email delivery -- the received email params are only pulled for the first assertion. If you switch this line to refute_email_delivered_with(to: [nil: "foo@bar.com"]) it passes which it should not? So I think for these additional assertions to be relevant, we need to call deliver_now again before each - similar to https://github.com/thoughtbot/bamboo/blob/3f79b73a4e27d9b27694fb4a72473caab46c857f/test/lib/bamboo/adapters/test_adapter_test.exs#L56-L63

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, of course, will fix.

I wonder though if this is the best way to implement these assertions. It would be better to store the emails in an agent and match over all of them. That would require a big refactor, but it might be worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder though if this is the best way to implement these assertions. It would be better to store the emails in an agent and match over all of them. That would require a big refactor, but it might be worth it.

What do you think about keeping it as is for now and merging this and opening a new issue for the potential refactor?

@mtarnovan mtarnovan force-pushed the add_refute_email_delivered_with branch from f5ea1eb to 1deb19c Compare July 25, 2019 12:22
Copy link
Contributor

@maymillerricci maymillerricci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes!! I left a few more comments/questions.

lib/bamboo/test.ex Outdated Show resolved Hide resolved
TestMailer.deliver_now(mail)

try do
refute_email_delivered_with(subject: subject)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and the others below, are in the test called when email does not match but it seems they are testing when email matches, which there is a separate test for? Thoughts on regrouping them, or alternatively removing some of them if they don't each add much additional value?

Also, if we do keep all of them, thoughts on extracting a helper function for the repeated code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I don't think they add too much value. I've refactored the tests a bit if you want to take another look.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks so much for this!

test/lib/bamboo/adapters/test_adapter_test.exs Outdated Show resolved Hide resolved
@mtarnovan mtarnovan force-pushed the add_refute_email_delivered_with branch from 3928f3e to e8fb16d Compare October 4, 2019 10:31
Copy link
Contributor

@maymillerricci maymillerricci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@maymillerricci maymillerricci merged commit 00ebc40 into beam-community:master Oct 25, 2019
if is_nil(received_email_params) do
refute false
else
refute Enum.any?(email_params, fn {k, v} -> do_match(received_email_params[k], v) end),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be all? instead 🤔 @mtarnovan

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

Successfully merging this pull request may close these issues.

2 participants