spc-pleroma/test/mix/tasks/pleroma.digest_test.exs

52 lines
1.1 KiB
Elixir
Raw Normal View History

2019-06-03 23:48:21 +00:00
defmodule Mix.Tasks.Pleroma.DigestTest do
use Pleroma.DataCase
import Pleroma.Factory
import Swoosh.TestAssertions
alias Pleroma.Web.CommonAPI
setup_all do
Mix.shell(Mix.Shell.Process)
on_exit(fn ->
Mix.shell(Mix.Shell.IO)
end)
:ok
end
describe "pleroma.digest test" do
test "Sends digest to the given user" do
user1 = insert(:user)
user2 = insert(:user)
Enum.each(0..10, fn i ->
{:ok, _activity} =
CommonAPI.post(user1, %{
"status" => "hey ##{i} @#{user2.nickname}!"
})
end)
2019-06-04 00:38:53 +00:00
yesterday =
NaiveDateTime.add(
NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
-60 * 60 * 24,
:second
)
2019-06-03 23:48:21 +00:00
2019-06-04 00:38:53 +00:00
{:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
:ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
assert_receive {:mix_shell, :info, [message]}
2019-06-04 00:07:49 +00:00
assert message =~ "Digest email have been sent"
2019-06-03 23:48:21 +00:00
assert_email_sent(
to: {user2.name, user2.email},
html_body: ~r/new mentions:/i
)
end
end
end