Merge branch 'develop' into tests/mastodon_api_controller.ex
[akkoma] / test / emails / admin_email_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.Emails.AdminEmailTest do
6 use Pleroma.DataCase
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 = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, reporter.nickname)
23 account_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :feed_redirect, account.nickname)
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"
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 end