04c907697452f469715dd997d9a773e77f6e09fd
[akkoma] / test / pleroma / emails / admin_email_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Emails.AdminEmailTest do
6 use Pleroma.DataCase, async: true
7 import Pleroma.Factory
8
9 alias Pleroma.Emails.AdminEmail
10 alias Pleroma.Web.Router.Helpers
11
12 test "build report email" do
13 config = Pleroma.Config.get(:instance)
14 to_user = insert(:user)
15 reporter = insert(:user)
16 account = insert(:user)
17
18 res =
19 AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
20
21 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
22 reporter_url = reporter.ap_id
23 account_url = account.ap_id
24
25 assert res.to == [{to_user.name, to_user.email}]
26 assert res.from == {config[:name], config[:notify_email]}
27 assert res.subject == "#{config[:name]} Report"
28
29 assert res.html_body ==
30 "<p>Reported by: <a href=\"#{reporter_url}\">#{reporter.nickname}</a></p>\n<p>Reported Account: <a href=\"#{
31 account_url
32 }\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{
33 status_url
34 }\">#{status_url}</li>\n </ul>\n</p>\n\n<p>\n<a href=\"http://localhost:4001/pleroma/admin/#/reports/index\">View Reports in AdminFE</a>\n"
35 end
36
37 test "it works when the reporter is a remote user without email" do
38 config = Pleroma.Config.get(:instance)
39 to_user = insert(:user)
40 reporter = insert(:user, email: nil, local: false)
41 account = insert(:user)
42
43 res =
44 AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
45
46 assert res.to == [{to_user.name, to_user.email}]
47 assert res.from == {config[:name], config[:notify_email]}
48 end
49
50 test "new unapproved registration email" do
51 config = Pleroma.Config.get(:instance)
52 to_user = insert(:user)
53 account = insert(:user, registration_reason: "Plz let me in")
54
55 res = AdminEmail.new_unapproved_registration(to_user, account)
56
57 account_url = account.ap_id
58
59 assert res.to == [{to_user.name, to_user.email}]
60 assert res.from == {config[:name], config[:notify_email]}
61 assert res.subject == "New account up for review on #{config[:name]} (@#{account.nickname})"
62
63 assert res.html_body == """
64 <p>New account for review: <a href="#{account_url}">@#{account.nickname}</a></p>
65 <blockquote>Plz let me in</blockquote>
66 <a href="http://localhost:4001/pleroma/admin/#/users/#{account.id}/">Visit AdminFE</a>
67 """
68 end
69 end