Merge branch 'feature/optimize_rich_media_parser' into 'develop'
[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.Tests.ObanHelpers
8 alias Pleroma.Web.CommonAPI
9
10 setup_all do
11 Mix.shell(Mix.Shell.Process)
12
13 on_exit(fn ->
14 Mix.shell(Mix.Shell.IO)
15 end)
16
17 :ok
18 end
19
20 describe "pleroma.digest test" do
21 test "Sends digest to the given user" do
22 user1 = insert(:user)
23 user2 = insert(:user)
24
25 Enum.each(0..10, fn i ->
26 {:ok, _activity} =
27 CommonAPI.post(user1, %{
28 "status" => "hey ##{i} @#{user2.nickname}!"
29 })
30 end)
31
32 yesterday =
33 NaiveDateTime.add(
34 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
35 -60 * 60 * 24,
36 :second
37 )
38
39 {:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
40
41 :ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
42
43 ObanHelpers.perform_all()
44
45 assert_receive {:mix_shell, :info, [message]}
46 assert message =~ "Digest email have been sent"
47
48 assert_email_sent(
49 to: {user2.name, user2.email},
50 html_body: ~r/here is what you've missed!/i
51 )
52 end
53 end
54 end