SparkPost / elixir-sparkpost

SparkPost client library for Elixir https://developers.sparkpost.com
Apache License 2.0
44 stars 13 forks source link

"test" mode #29

Closed karlseguin closed 7 years ago

karlseguin commented 7 years ago

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
ewandennis commented 7 years ago

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.