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})
21 actor: AccountView.render("account.json", %{user: user}),
22 account: AccountView.render("account.json", %{user: other_user}),
29 ReportView.render("show.json", %{report: activity})
30 |> Map.delete(:created_at)
32 assert result == expected
35 test "includes reported statuses" do
37 other_user = insert(:user)
38 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
40 {:ok, report_activity} =
41 CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
45 actor: AccountView.render("account.json", %{user: user}),
46 account: AccountView.render("account.json", %{user: other_user}),
47 statuses: [StatusView.render("status.json", %{activity: activity})],
49 id: report_activity.id
53 ReportView.render("show.json", %{report: report_activity})
54 |> Map.delete(:created_at)
56 assert result == expected
59 test "renders report's state" do
61 other_user = insert(:user)
63 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
64 {:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
65 assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
68 test "renders report description" do
70 other_user = insert(:user)
73 CommonAPI.report(user, %{
74 "account_id" => other_user.id,
75 "comment" => "posts are too good for this instance"
78 assert %{content: "posts are too good for this instance"} =
79 ReportView.render("show.json", %{report: activity})
82 test "sanitizes report description" do
84 other_user = insert(:user)
87 CommonAPI.report(user, %{
88 "account_id" => other_user.id,
92 data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
93 activity = Map.put(activity, :data, data)
95 refute %{content: "<script> alert('hecked :D:D:D:D:D:D:D') </script>"} ==
96 ReportView.render("show.json", %{report: activity})[:content]