logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

report_controller_test.exs (3173B)


  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. |> put_req_header("content-type", "application/json")
  18. |> post("/api/v1/reports", %{"account_id" => target_user.id})
  19. |> json_response_and_validate_schema(200)
  20. end
  21. test "submit a report with statuses and comment", %{
  22. conn: conn,
  23. target_user: target_user,
  24. activity: activity
  25. } do
  26. assert %{"action_taken" => false, "id" => _} =
  27. conn
  28. |> put_req_header("content-type", "application/json")
  29. |> post("/api/v1/reports", %{
  30. "account_id" => target_user.id,
  31. "status_ids" => [activity.id],
  32. "comment" => "bad status!",
  33. "forward" => "false"
  34. })
  35. |> json_response_and_validate_schema(200)
  36. end
  37. test "account_id is required", %{
  38. conn: conn,
  39. activity: activity
  40. } do
  41. assert %{"error" => "Missing field: account_id."} =
  42. conn
  43. |> put_req_header("content-type", "application/json")
  44. |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
  45. |> json_response_and_validate_schema(400)
  46. end
  47. test "comment must be up to the size specified in the config", %{
  48. conn: conn,
  49. target_user: target_user
  50. } do
  51. max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
  52. comment = String.pad_trailing("a", max_size + 1, "a")
  53. error = %{"error" => "Comment must be up to #{max_size} characters"}
  54. assert ^error =
  55. conn
  56. |> put_req_header("content-type", "application/json")
  57. |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
  58. |> json_response_and_validate_schema(400)
  59. end
  60. test "returns error when account is not exist", %{
  61. conn: conn,
  62. activity: activity
  63. } do
  64. conn =
  65. conn
  66. |> put_req_header("content-type", "application/json")
  67. |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
  68. assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
  69. end
  70. test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
  71. insert(:user, %{is_admin: true, email: nil})
  72. assert %{"action_taken" => false, "id" => _} =
  73. conn
  74. |> put_req_header("content-type", "application/json")
  75. |> post("/api/v1/reports", %{"account_id" => target_user.id})
  76. |> json_response_and_validate_schema(200)
  77. end
  78. end