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]})
52 other_user = Pleroma.User.get_by_id(other_user.id)
58 AccountView.render("show.json", %{user: user}),
59 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
63 AccountView.render("show.json", %{user: other_user}),
64 Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
66 statuses: [StatusView.render("show.json", %{activity: activity})],
68 id: report_activity.id
72 ReportView.render("show.json", Report.extract_report_info(report_activity))
73 |> Map.delete(:created_at)
75 assert result == expected
78 test "renders report's state" do
80 other_user = insert(:user)
82 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
83 {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
85 assert %{state: "closed"} =
86 ReportView.render("show.json", Report.extract_report_info(activity))
89 test "renders report description" do
91 other_user = insert(:user)
94 CommonAPI.report(user, %{
95 "account_id" => other_user.id,
96 "comment" => "posts are too good for this instance"
99 assert %{content: "posts are too good for this instance"} =
100 ReportView.render("show.json", Report.extract_report_info(activity))
103 test "sanitizes report description" do
105 other_user = insert(:user)
108 CommonAPI.report(user, %{
109 "account_id" => other_user.id,
113 data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
114 activity = Map.put(activity, :data, data)
116 refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
117 ReportView.render("show.json", Report.extract_report_info(activity))[:content]
120 test "doesn't error out when the user doesn't exists" do
122 other_user = insert(:user)
125 CommonAPI.report(user, %{
126 "account_id" => other_user.id,
130 Pleroma.User.delete(other_user)
131 Pleroma.User.invalidate_cache(other_user)
133 assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))