1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Emails.AdminEmailTest do
6 use Pleroma.DataCase, async: true
9 alias Pleroma.Emails.AdminEmail
10 alias Pleroma.Web.Router.Helpers
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)
19 AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
21 status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12")
22 reporter_url = reporter.ap_id
23 account_url = account.ap_id
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"
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"
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)
40 AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
42 assert res.to == [{to_user.name, to_user.email}]
43 assert res.from == {config[:name], config[:notify_email]}
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")
51 res = AdminEmail.new_unapproved_registration(to_user, account)
53 account_url = account.ap_id
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})"
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>