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

Getting emails from TestAdapter #233

Closed
optikfluffel opened this issue Dec 7, 2016 · 3 comments
Closed

Getting emails from TestAdapter #233

optikfluffel opened this issue Dec 7, 2016 · 3 comments

Comments

@optikfluffel
Copy link

Is there a way to get the emails sent through Bamboo.TestAdapter?

I'm trying to test a passwordless SessionController in which I generate a Phoenix.Token and send it out via email without storing it anywhere. It would be cool to be able to catch these emails and read the tokens to test the sign in mechanism.

@paulcsmith
Copy link
Contributor

@optikfluffel I think the best way to handle this might be to do a unit test on the email. That way you can do something like:

assert email.html_body =~ the_generated_token

Then in your integration tests you can use the new feature in #228 to test that the email with the correct subject is sent. Either that or use a fake token during test so it's always the same. Then you can use regular assert_delivered and pass it an email. If you use a fake token that's always the same, then the body should be the same and the current test functions should do the trick. Does that help?

@optikfluffel
Copy link
Author

The unit test I already had ^^
Using the :subject for integration testing, when #228 is ready, sounds fine.

Thanks :)

FYI: To test my sign in mechanism, since it only checks if the :token is younger than a minute and then uses the signed content to get the user out of the database, I simply generate a brand new one inside the test so I don't rely on mail things there (which feels somewhat cleaner as well).

@petejkim
Copy link

petejkim commented May 2, 2017

I ran into a similar issue recently, I ended up doing the following to get the Bamboo.Email struct:

assert_receive({:delivered_email, %Bamboo.Email{} = email}, 100, Bamboo.Test.flunk_no_emails_received)

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

No branches or pull requests

3 participants