forked from migadu/mailex
minimal test
This commit is contained in:
parent
fbf3992a6a
commit
8ed977aa02
@ -109,13 +109,13 @@ defmodule Mailex.Render do
|
|||||||
def headers_for(email) do
|
def headers_for(email) do
|
||||||
headers = []
|
headers = []
|
||||||
|
|
||||||
if email.reply_to, do:
|
if email.reply_to && (length(email.reply_to) > 0), do:
|
||||||
headers = [ { "Reply-To", email.reply_to |> stringify_addresses } ]
|
headers = [ { "Reply-To", email.reply_to |> stringify_addresses } ]
|
||||||
|
|
||||||
if email.bcc, do:
|
if email.bcc && (length(email.bcc) > 0), do:
|
||||||
headers = [ { "Bcc", email.bcc |> stringify_addresses } | headers ]
|
headers = [ { "Bcc", email.bcc |> stringify_addresses } | headers ]
|
||||||
|
|
||||||
if email.cc, do:
|
if email.cc && (length(email.cc) > 0), do:
|
||||||
headers = [ { "Cc", email.cc |> stringify_addresses } | headers ]
|
headers = [ { "Cc", email.cc |> stringify_addresses } | headers ]
|
||||||
|
|
||||||
[ { "From", email.from |> stringify_addresses },
|
[ { "From", email.from |> stringify_addresses },
|
||||||
@ -124,6 +124,9 @@ defmodule Mailex.Render do
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def stringify_addresses(nil), do: ""
|
||||||
|
def stringify_addresses([]), do: ""
|
||||||
|
|
||||||
def stringify_addresses(addresses) do
|
def stringify_addresses(addresses) do
|
||||||
addresses = addresses |> Address.rfc_822_format
|
addresses = addresses |> Address.rfc_822_format
|
||||||
if is_list(addresses) do
|
if is_list(addresses) do
|
||||||
|
@ -2,7 +2,47 @@ defmodule MailexTest do
|
|||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
doctest Mailex
|
doctest Mailex
|
||||||
|
|
||||||
test "the truth" do
|
defp email_minimal do
|
||||||
assert 1 + 1 == 2
|
%Mailex.Email{
|
||||||
|
from: %Mailex.Address{ address: "test_a@gmail.com" },
|
||||||
|
to: [%Mailex.Address{ address: "test_b@gmail.com" }]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp email_with_reply_to do
|
||||||
|
%Mailex.Email{
|
||||||
|
from: %Mailex.Address{ address: "test_a@gmail.com" },
|
||||||
|
to: [%Mailex.Address{ address: "test_b@gmail.com" }],
|
||||||
|
reply_to: [%Mailex.Address{ address: "test_aa@gmail.com" }, %Mailex.Address{ address: "test_a@gmx.com" }],
|
||||||
|
subject: "You've got mail",
|
||||||
|
text: "Hello World!"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp email_without_attachments do
|
||||||
|
%Mailex.Email{
|
||||||
|
from: %Mailex.Address{ name: "Yankee", address: "test_a@gmail.com" },
|
||||||
|
to: [%Mailex.Address{ address: "test_c@gmail.com" }],
|
||||||
|
subject: "You've got mail",
|
||||||
|
text: "Hello World!"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp email_with_attachments do
|
||||||
|
%Mailex.Email{
|
||||||
|
from: %Mailex.Address{ name: "Yankee", address: "test_a@gmail.com" },
|
||||||
|
to: [%Mailex.Address{ address: "test_c@gmail.com" }],
|
||||||
|
subject: "You've got mail",
|
||||||
|
text: "Hello World",
|
||||||
|
attachments: [Mailex.Attachment.inline!("test/data/logo.gif")]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Messages render" do
|
||||||
|
assert email_minimal |> Mailex.Render.render
|
||||||
|
assert email_with_reply_to |> Mailex.Render.render
|
||||||
|
assert email_without_attachments |> Mailex.Render.render
|
||||||
|
assert email_with_attachments |> Mailex.Render.render
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user