fix formatting
[akkoma] / test / tasks / digest_test.exs
1 defmodule Mix.Tasks.Pleroma.DigestTest do
2 use Pleroma.DataCase
3
4 import Pleroma.Factory
5 import Swoosh.TestAssertions
6
7 alias Pleroma.Web.CommonAPI
8
9 setup_all do
10 Mix.shell(Mix.Shell.Process)
11
12 on_exit(fn ->
13 Mix.shell(Mix.Shell.IO)
14 end)
15
16 :ok
17 end
18
19 describe "pleroma.digest test" do
20 test "Sends digest to the given user" do
21 user1 = insert(:user)
22 user2 = insert(:user)
23
24 Enum.each(0..10, fn i ->
25 {:ok, _activity} =
26 CommonAPI.post(user1, %{
27 "status" => "hey ##{i} @#{user2.nickname}!"
28 })
29 end)
30
31 yesterday =
32 NaiveDateTime.add(
33 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
34 -60 * 60 * 24,
35 :second
36 )
37
38 {:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
39
40 :ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
41
42 assert_receive {:mix_shell, :info, [message]}
43 assert message =~ "Digest email have been sent"
44
45 assert_email_sent(
46 to: {user2.name, user2.email},
47 html_body: ~r/here is what you've missed!/i
48 )
49 end
50 end
51 end