Merge pull request 'Magical patches' (#357) from magical-patches into develop
[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=\"#{account_url}\">#{account.nickname}</a></p>\n<p>Comment: Test comment\n<p> Statuses:\n <ul>\n <li><a href=\"#{status_url}\">#{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"
31 end
32
33 test "it works when the reporter is a remote user without email" do
34 config = Pleroma.Config.get(:instance)
35 to_user = insert(:user)
36 reporter = insert(:user, email: nil, local: false)
37 account = insert(:user)
38
39 res =
40 AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
41
42 assert res.to == [{to_user.name, to_user.email}]
43 assert res.from == {config[:name], config[:notify_email]}
44 end
45
46 test "new unapproved registration email" do
47 config = Pleroma.Config.get(:instance)
48 to_user = insert(:user)
49 account = insert(:user, registration_reason: "Plz let me in")
50
51 res = AdminEmail.new_unapproved_registration(to_user, account)
52
53 account_url = account.ap_id
54
55 assert res.to == [{to_user.name, to_user.email}]
56 assert res.from == {config[:name], config[:notify_email]}
57 assert res.subject == "New account up for review on #{config[:name]} (@#{account.nickname})"
58
59 assert res.html_body == """
60 <p>New account for review: <a href="#{account_url}">@#{account.nickname}</a></p>
61 <blockquote>Plz let me in</blockquote>
62 <a href="http://localhost:4001/pleroma/admin/#/users/#{account.id}/">Visit AdminFE</a>
63 """
64 end
65 end