Merge branch 'develop' into refactor/subscription
[akkoma] / test / daemons / digest_email_daemon_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.DigestEmailDaemonTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8
9 alias Pleroma.Daemons.DigestEmailDaemon
10 alias Pleroma.Tests.ObanHelpers
11 alias Pleroma.User
12 alias Pleroma.Web.CommonAPI
13
14 test "it sends digest emails" do
15 user = insert(:user)
16
17 date =
18 Timex.now()
19 |> Timex.shift(days: -10)
20 |> Timex.to_naive_datetime()
21
22 user2 = insert(:user, last_digest_emailed_at: date)
23 User.switch_email_notifications(user2, "digest", true)
24 CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
25
26 DigestEmailDaemon.perform()
27 ObanHelpers.perform_all()
28 # Performing job(s) enqueued at previous step
29 ObanHelpers.perform_all()
30
31 assert_received {:email, email}
32 assert email.to == [{user2.name, user2.email}]
33 assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
34 end
35 end