Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Web.CommonAPI
  7. import Pleroma.Factory
  8. setup do: oauth_access(["write:reports"])
  9. setup do
  10. target_user = insert(:user)
  11. {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
  12. [target_user: target_user, activity: activity]
  13. end
  14. test "submit a basic report", %{conn: conn, target_user: target_user} do
  15. assert %{"action_taken" => false, "id" => _} =
  16. conn
  17. |> post("/api/v1/reports", %{"account_id" => target_user.id})
  18. |> json_response(200)
  19. end
  20. test "submit a report with statuses and comment", %{
  21. conn: conn,
  22. target_user: target_user,
  23. activity: activity
  24. } do
  25. assert %{"action_taken" => false, "id" => _} =
  26. conn
  27. |> post("/api/v1/reports", %{
  28. "account_id" => target_user.id,
  29. "status_ids" => [activity.id],
  30. "comment" => "bad status!",
  31. "forward" => "false"
  32. })
  33. |> json_response(200)
  34. end
  35. test "account_id is required", %{
  36. conn: conn,
  37. activity: activity
  38. } do
  39. assert %{"error" => "Valid `account_id` required"} =
  40. conn
  41. |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
  42. |> json_response(400)
  43. end
  44. test "comment must be up to the size specified in the config", %{
  45. conn: conn,
  46. target_user: target_user
  47. } do
  48. max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
  49. comment = String.pad_trailing("a", max_size + 1, "a")
  50. error = %{"error" => "Comment must be up to #{max_size} characters"}
  51. assert ^error =
  52. conn
  53. |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
  54. |> json_response(400)
  55. end
  56. test "returns error when account is not exist", %{
  57. conn: conn,
  58. activity: activity
  59. } do
  60. conn = post(conn, "/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
  61. assert json_response(conn, 400) == %{"error" => "Account not found"}
  62. end
  63. test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
  64. insert(:user, %{is_admin: true, email: nil})
  65. assert %{"action_taken" => false, "id" => _} =
  66. conn
  67. |> post("/api/v1/reports", %{"account_id" => target_user.id})
  68. |> json_response(200)
  69. end
  70. end