79 lines
1.3 KiB
Elixir
79 lines
1.3 KiB
Elixir
# TODO rewrite with exunit
|
|
|
|
Mix.install(
|
|
[
|
|
{:swoosh, "~> 1.7"},
|
|
{:gen_smtp, "~> 1.1"},
|
|
{:hackney, "~> 1.8"},
|
|
{:swoosh_mailinator, path: "."}, #app: false }
|
|
]
|
|
)
|
|
|
|
defmodule Main do
|
|
import Swoosh.Email
|
|
import Swoosh.Mailer
|
|
|
|
def test_both() do
|
|
prep()
|
|
end
|
|
|
|
def test_text_only() do
|
|
prep()
|
|
|> Map.delete(:html_body)
|
|
end
|
|
|
|
def test_text_nil() do
|
|
prep()
|
|
|> text_body(nil)
|
|
end
|
|
|
|
def test_html_only() do
|
|
prep()
|
|
|> Map.delete(:text_body)
|
|
end
|
|
|
|
def test_html_nil() do
|
|
prep()
|
|
|> html_body(nil)
|
|
end
|
|
|
|
def test_both_absent() do
|
|
prep()
|
|
|> Map.delete(:html_body)
|
|
|> Map.delete(:text_body)
|
|
end
|
|
|
|
def prep do
|
|
mess = "mess"
|
|
new()
|
|
|> to("mlkjhg@kiujygtrfedc.com")
|
|
|> from({"Who Knows", "who.knows@nonexisting.tld"})
|
|
|> subject("Hello, Swoosh!")
|
|
|> html_body("<h1>Hello World</h1><p>"<>mess<>"</p>")
|
|
|> text_body(mess)
|
|
end
|
|
|
|
def send(email) do
|
|
email
|
|
|> deliver([
|
|
adapter: Swoosh.Adapters.Mailinator
|
|
])
|
|
end
|
|
end
|
|
|
|
# ok cases
|
|
Main.test_both() |> Main.send()
|
|
Main.test_text_only() |> Main.send()
|
|
Main.test_html_only() |> Main.send()
|
|
Main.test_text_nil() |> Main.send()
|
|
Main.test_html_nil() |> Main.send()
|
|
|
|
# failing cases
|
|
try do
|
|
Main.test_both_absent() |> Main.send()
|
|
rescue
|
|
FunctionClauseError -> "expected"
|
|
else
|
|
_ -> "shoud have failed"
|
|
end
|