1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.ReportViewTest do
8 alias Pleroma.Web.AdminAPI.Report
9 alias Pleroma.Web.AdminAPI.ReportView
10 alias Pleroma.Web.CommonAPI
11 alias Pleroma.Web.MastodonAPI.AccountView
12 alias Pleroma.Web.MastodonAPI.StatusView
14 test "renders a report" do
16 other_user = insert(:user)
18 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
24 AccountView.render("show.json", %{user: user}),
25 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
29 AccountView.render("show.json", %{user: other_user}),
30 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
38 ReportView.render("show.json", Report.extract_report_info(activity))
39 |> Map.delete(:created_at)
41 assert result == expected
44 test "includes reported statuses" do
46 other_user = insert(:user)
47 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
49 {:ok, report_activity} =
50 CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
56 AccountView.render("show.json", %{user: user}),
57 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
61 AccountView.render("show.json", %{user: other_user}),
62 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
64 statuses: [StatusView.render("show.json", %{activity: activity})],
66 id: report_activity.id
70 ReportView.render("show.json", Report.extract_report_info(report_activity))
71 |> Map.delete(:created_at)
73 assert result == expected
76 test "renders report's state" do
78 other_user = insert(:user)
80 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
81 {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
83 assert %{state: "closed"} =
84 ReportView.render("show.json", Report.extract_report_info(activity))
87 test "renders report description" do
89 other_user = insert(:user)
92 CommonAPI.report(user, %{
93 "account_id" => other_user.id,
94 "comment" => "posts are too good for this instance"
97 assert %{content: "posts are too good for this instance"} =
98 ReportView.render("show.json", Report.extract_report_info(activity))
101 test "sanitizes report description" do
103 other_user = insert(:user)
106 CommonAPI.report(user, %{
107 "account_id" => other_user.id,
111 data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
112 activity = Map.put(activity, :data, data)
114 refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
115 ReportView.render("show.json", Report.extract_report_info(activity))[:content]
118 test "doesn't error out when the user doesn't exists" do
120 other_user = insert(:user)
123 CommonAPI.report(user, %{
124 "account_id" => other_user.id,
128 Pleroma.User.delete(other_user)
129 Pleroma.User.invalidate_cache(other_user)
131 assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))