riverrun / phauxth_installer

No longer maintained - Installer for the Phauxth authentication library
13 stars 4 forks source link

Email module set up makes it tricky to test that emails are delivered #19

Open michaeljones opened 4 years ago

michaeljones commented 4 years ago

I've been struggling a bit today as my tests indicated that I was sending an email when I thought the logic being called isn't sending any. But I was overlooking the fact that the confirm_request and other methods in the Email module call Mailer.deliver_later directly.

From the bamboo docs, it seems like typical email test code might look like:

      conn = post(conn, Routes.premium_signup_path(conn, :create), %{"form" => form})
      assert redirected_to(conn) == Routes.session_path(conn, :new)

      expected_email = Email.confirm_request(email, link)
      assert_delivered_email expected_email

In order to test that the premium_signup_path generates and sends a confirm_request email.

However this always passes no matter what the logic in the controller trigger by Routes.premium_signup_path(conn, :create) is because expected_email = Email.confirm_request(email, link) sends an email itself.

It might be worth adjusting the approach so that it is possible to ask the Email module to generate an email without sending it so that tests like the above can be done. I've taken to calling Mailer.deliver_later at the various call sites but maybe there could be separate confirm_request and send_confirm_request methods in the Email module or something like that.

Edit: I'm very appreciative of the work you've put into this project. It has helped me to get started much more confidently with Elixir & Phoenix. It also seems like you're quite busy these days. I don't feel like this is super pressing or anything.

If you have a preferred way forward, I could attempt to make a pull request if that would be useful. Or we can leave it as it is.

riverrun commented 4 years ago

Thanks for opening the issue. I will have another look at the bamboo docs and get back to you soon.

riverrun commented 4 years ago

Yes, you are right. It looks like the design of Bamboo encourages separating the email generation from sending.

I will make the changes to the example app first, and then I will update the installer.

riverrun commented 2 years ago

First, sorry for the delay in responding to this issue.

Second, this repository is no longer actively maintained. I just do not have the time or energy needed to continue maintaining it.

michaeljones commented 2 years ago

No trouble at all. I understand what it is to stop having time or motivation for an open source project. Always good to draw a line in the sand and move on. I suspect the new semi-official Phoenix Auth stuff has probably reduced the need or focus on this too. All the best!