mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Add tests for report view
This commit is contained in:
parent
135c196769
commit
e943905bd7
1 changed files with 98 additions and 0 deletions
98
test/web/admin_api/views/report_view_test.exs
Normal file
98
test/web/admin_api/views/report_view_test.exs
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
import Pleroma.Factory
|
||||||
|
alias Pleroma.Web.AdminAPI.ReportView
|
||||||
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
|
alias Pleroma.Web.CommonAPI
|
||||||
|
|
||||||
|
test "renders a report" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
content: "",
|
||||||
|
actor: AccountView.render("account.json", %{user: user}),
|
||||||
|
account: AccountView.render("account.json", %{user: other_user}),
|
||||||
|
statuses: [],
|
||||||
|
state: "open",
|
||||||
|
id: activity.id
|
||||||
|
}
|
||||||
|
|
||||||
|
result =
|
||||||
|
ReportView.render("show.json", %{report: activity})
|
||||||
|
|> Map.delete(:created_at)
|
||||||
|
|
||||||
|
assert result == expected
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes reported statuses" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "toot"})
|
||||||
|
|
||||||
|
{:ok, report_activity} =
|
||||||
|
CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
|
||||||
|
|
||||||
|
expected = %{
|
||||||
|
content: "",
|
||||||
|
actor: AccountView.render("account.json", %{user: user}),
|
||||||
|
account: AccountView.render("account.json", %{user: other_user}),
|
||||||
|
statuses: [StatusView.render("status.json", %{activity: activity})],
|
||||||
|
state: "open",
|
||||||
|
id: report_activity.id
|
||||||
|
}
|
||||||
|
|
||||||
|
result =
|
||||||
|
ReportView.render("show.json", %{report: report_activity})
|
||||||
|
|> Map.delete(:created_at)
|
||||||
|
|
||||||
|
assert result == expected
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders report's state" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||||
|
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
|
||||||
|
assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders report description" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.report(user, %{
|
||||||
|
"account_id" => other_user.id,
|
||||||
|
"comment" => "posts are too good for this instance"
|
||||||
|
})
|
||||||
|
|
||||||
|
assert %{content: "posts are too good for this instance"} =
|
||||||
|
ReportView.render("show.json", %{report: activity})
|
||||||
|
end
|
||||||
|
|
||||||
|
test "sanitizes report description" do
|
||||||
|
user = insert(:user)
|
||||||
|
other_user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.report(user, %{
|
||||||
|
"account_id" => other_user.id,
|
||||||
|
"comment" => ""
|
||||||
|
})
|
||||||
|
|
||||||
|
data = Map.put(activity.data, "content", "<script> alert('hecked :D:D:D:D:D:D:D') </script>")
|
||||||
|
activity = Map.put(activity, :data, data)
|
||||||
|
|
||||||
|
refute %{content: "<script> alert('hecked :D:D:D:D:D:D:D') </script>"} ==
|
||||||
|
ReportView.render("show.json", %{report: activity})[:content]
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue