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})
39 ReportView.render("show.json", Report.extract_report_info(activity))
40 |> Map.delete(:created_at)
42 assert result == expected
45 test "includes reported statuses" do
47 other_user = insert(:user)
48 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
50 {:ok, report_activity} =
51 CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
53 other_user = Pleroma.User.get_by_id(other_user.id)
59 AccountView.render("show.json", %{user: user}),
60 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
64 AccountView.render("show.json", %{user: other_user}),
65 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
67 statuses: [StatusView.render("show.json", %{activity: activity})],
70 id: report_activity.id
74 ReportView.render("show.json", Report.extract_report_info(report_activity))
75 |> Map.delete(:created_at)
77 assert result == expected
80 test "renders report's state" do
82 other_user = insert(:user)
84 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
85 {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
87 assert %{state: "closed"} =
88 ReportView.render("show.json", Report.extract_report_info(activity))
91 test "renders report description" do
93 other_user = insert(:user)
96 CommonAPI.report(user, %{
97 "account_id" => other_user.id,
98 "comment" => "posts are too good for this instance"
101 assert %{content: "posts are too good for this instance"} =
102 ReportView.render("show.json", Report.extract_report_info(activity))
105 test "sanitizes report description" do
107 other_user = insert(:user)
110 CommonAPI.report(user, %{
111 "account_id" => other_user.id,
115 data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
116 activity = Map.put(activity, :data, data)
118 refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
119 ReportView.render("show.json", Report.extract_report_info(activity))[:content]
122 test "doesn't error out when the user doesn't exists" do
124 other_user = insert(:user)
127 CommonAPI.report(user, %{
128 "account_id" => other_user.id,
132 Pleroma.User.delete(other_user)
133 Pleroma.User.invalidate_cache(other_user)
135 assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))