Merge branch 'develop' into 'remove-avatar-header'
[akkoma] / test / web / admin_api / views / report_view_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.AdminAPI.ReportViewTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 alias Pleroma.Web.AdminAPI.ReportView
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.MastodonAPI.AccountView
11 alias Pleroma.Web.MastodonAPI.StatusView
12
13 test "renders a report" do
14 user = insert(:user)
15 other_user = insert(:user)
16
17 {:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
18
19 expected = %{
20 content: nil,
21 actor: AccountView.render("account.json", %{user: user}),
22 account: AccountView.render("account.json", %{user: other_user}),
23 statuses: [],
24 state: "open",
25 id: activity.id
26 }
27
28 result =
29 ReportView.render("show.json", %{report: activity})
30 |> Map.delete(:created_at)
31
32 assert result == expected
33 end
34
35 test "includes reported statuses" do
36 user = insert(:user)
37 other_user = insert(:user)
38 {:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
39
40 {:ok, report_activity} =
41 CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
42
43 expected = %{
44 content: nil,
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})],
48 state: "open",
49 id: report_activity.id
50 }
51
52 result =
53 ReportView.render("show.json", %{report: report_activity})
54 |> Map.delete(:created_at)
55
56 assert result == expected
57 end
58
59 test "renders report's state" do
60 user = insert(:user)
61 other_user = insert(:user)
62
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})
66 end
67
68 test "renders report description" do
69 user = insert(:user)
70 other_user = insert(:user)
71
72 {:ok, activity} =
73 CommonAPI.report(user, %{
74 "account_id" => other_user.id,
75 "comment" => "posts are too good for this instance"
76 })
77
78 assert %{content: "posts are too good for this instance"} =
79 ReportView.render("show.json", %{report: activity})
80 end
81
82 test "sanitizes report description" do
83 user = insert(:user)
84 other_user = insert(:user)
85
86 {:ok, activity} =
87 CommonAPI.report(user, %{
88 "account_id" => other_user.id,
89 "comment" => ""
90 })
91
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)
94
95 refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
96 ReportView.render("show.json", %{report: activity})[:content]
97 end
98 end