SparkPost/elixir-sparkpost

"test" mode

Closed this issue · 1 comments

One of the nice things about Swoosh is the Test adapter which causes emails to be sent to the calling process. We end up with very nice tests that look like:

// do_something_that_causes_an_email_to_be_sent()
token = receive do
  {:email, msg} ->
    assert msg.subject == "Password Reset"
    %{"token" => token} = Regex.named_captures(~r/token=(?<token>[^"]+)/, msg.html_body)
    token
after
  500 -> assert false
end
// assert that token was stored in the DB

Very interesting topic, thanks for bringing it up! Since Swoosh has both a SparkPost adapter and a test adapter so one could manage this type of testing by just using Swoosh. However, since SparkPost is API-driven, a similar test mode in elixir-sparkpost could deliver only API request data to your tests and not fully-formed email. On that basis, I'm not sure this capability translates well so I'm going closing this for now.