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.ReportView
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.MastodonAPI.AccountView
11 alias Pleroma.Web.MastodonAPI.StatusView
13 test "renders a report" do
15 other_user = insert(:user)
17 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
23 AccountView.render("account.json", %{user: user}),
24 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
28 AccountView.render("account.json", %{user: other_user}),
29 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
37 ReportView.render("show.json", %{report: activity})
38 |> Map.delete(:created_at)
40 assert result == expected
43 test "includes reported statuses" do
45 other_user = insert(:user)
46 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
48 {:ok, report_activity} =
49 CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
55 AccountView.render("account.json", %{user: user}),
56 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
60 AccountView.render("account.json", %{user: other_user}),
61 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
63 statuses: [StatusView.render("status.json", %{activity: activity})],
65 id: report_activity.id
69 ReportView.render("show.json", %{report: report_activity})
70 |> Map.delete(:created_at)
72 assert result == expected
75 test "renders report's state" do
77 other_user = insert(:user)
79 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
80 {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
81 assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
84 test "renders report description" do
86 other_user = insert(:user)
89 CommonAPI.report(user, %{
90 "account_id" => other_user.id,
91 "comment" => "posts are too good for this instance"
94 assert %{content: "posts are too good for this instance"} =
95 ReportView.render("show.json", %{report: activity})
98 test "sanitizes report description" do
100 other_user = insert(:user)
103 CommonAPI.report(user, %{
104 "account_id" => other_user.id,
108 data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
109 activity = Map.put(activity, :data, data)
111 refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
112 ReportView.render("show.json", %{report: activity})[:content]
115 test "doesn't error out when the user doesn't exists" do
117 other_user = insert(:user)
120 CommonAPI.report(user, %{
121 "account_id" => other_user.id,
125 Pleroma.User.delete(other_user)
126 Pleroma.User.invalidate_cache(other_user)
128 assert %{} = ReportView.render("show.json", %{report: activity})