54cf0ca46feec52cf79b118f1cc69c268873ec36
[akkoma] / test / workers / cron / new_users_digest_worker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8
9 alias Pleroma.Tests.ObanHelpers
10 alias Pleroma.Web.CommonAPI
11 alias Pleroma.Workers.Cron.NewUsersDigestWorker
12
13 test "it sends new users digest emails" do
14 yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)
15 admin = insert(:user, %{is_admin: true})
16 user = insert(:user, %{inserted_at: yesterday})
17 user2 = insert(:user, %{inserted_at: yesterday})
18 CommonAPI.post(user, %{status: "cofe"})
19
20 NewUsersDigestWorker.perform(nil, nil)
21 ObanHelpers.perform_all()
22
23 assert_received {:email, email}
24 assert email.to == [{admin.name, admin.email}]
25 assert email.subject == "#{Pleroma.Config.get([:instance, :name])} New Users"
26
27 refute email.html_body =~ admin.nickname
28 assert email.html_body =~ user.nickname
29 assert email.html_body =~ user2.nickname
30 assert email.html_body =~ "cofe"
31 end
32
33 test "it doesn't fail when admin has no email" do
34 yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)
35 insert(:user, %{is_admin: true, email: nil})
36 insert(:user, %{inserted_at: yesterday})
37 user = insert(:user, %{inserted_at: yesterday})
38
39 CommonAPI.post(user, %{status: "cofe"})
40
41 NewUsersDigestWorker.perform(nil, nil)
42 ObanHelpers.perform_all()
43 end
44 end