1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.ReportViewTest do
10 alias Pleroma.Web.AdminAPI
11 alias Pleroma.Web.AdminAPI.Report
12 alias Pleroma.Web.AdminAPI.ReportView
13 alias Pleroma.Web.CommonAPI
14 alias Pleroma.Web.MastodonAPI
15 alias Pleroma.Web.MastodonAPI.StatusView
17 test "renders a report" do
19 other_user = insert(:user)
21 {:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
27 MastodonAPI.AccountView.render("show.json", %{user: user, force: true}),
28 AdminAPI.AccountView.render("show.json", %{user: user})
32 MastodonAPI.AccountView.render("show.json", %{user: other_user, force: true}),
33 AdminAPI.AccountView.render("show.json", %{user: other_user})
42 ReportView.render("show.json", Report.extract_report_info(activity))
43 |> Map.delete(:created_at)
45 assert result == expected
48 test "includes reported statuses" do
50 other_user = insert(:user)
51 {:ok, activity} = CommonAPI.post(other_user, %{status: "toot"})
53 {:ok, report_activity} =
54 CommonAPI.report(user, %{account_id: other_user.id, status_ids: [activity.id]})
56 other_user = Pleroma.User.get_by_id(other_user.id)
62 MastodonAPI.AccountView.render("show.json", %{user: user, force: true}),
63 AdminAPI.AccountView.render("show.json", %{user: user})
67 MastodonAPI.AccountView.render("show.json", %{user: other_user, force: true}),
68 AdminAPI.AccountView.render("show.json", %{user: other_user})
70 statuses: [StatusView.render("show.json", %{activity: activity})],
73 id: report_activity.id
77 ReportView.render("show.json", Report.extract_report_info(report_activity))
78 |> Map.delete(:created_at)
80 assert result == expected
83 test "renders report's state" do
85 other_user = insert(:user)
87 {:ok, activity} = CommonAPI.report(user, %{account_id: other_user.id})
88 {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
90 assert %{state: "closed"} =
91 ReportView.render("show.json", Report.extract_report_info(activity))
94 test "renders report description" do
96 other_user = insert(:user)
99 CommonAPI.report(user, %{
100 account_id: other_user.id,
101 comment: "posts are too good for this instance"
104 assert %{content: "posts are too good for this instance"} =
105 ReportView.render("show.json", Report.extract_report_info(activity))
108 test "sanitizes report description" do
110 other_user = insert(:user)
113 CommonAPI.report(user, %{
114 account_id: other_user.id,
118 data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
119 activity = Map.put(activity, :data, data)
121 refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
122 ReportView.render("show.json", Report.extract_report_info(activity))[:content]
125 test "doesn't error out when the user doesn't exists" do
127 other_user = insert(:user)
130 CommonAPI.report(user, %{
131 account_id: other_user.id,
135 Pleroma.User.delete(other_user)
136 Pleroma.User.invalidate_cache(other_user)
138 assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))