1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
6 use Pleroma.Web.ConnCase, async: true
8 alias Pleroma.Web.CommonAPI
10 import Pleroma.Factory
12 setup do: oauth_access(["write:reports"])
15 target_user = insert(:user)
17 {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
19 [target_user: target_user, activity: activity]
22 test "submit a basic report", %{conn: conn, target_user: target_user} do
23 assert %{"action_taken" => false, "id" => _} =
25 |> put_req_header("content-type", "application/json")
26 |> post("/api/v1/reports", %{"account_id" => target_user.id})
27 |> json_response_and_validate_schema(200)
30 test "submit a report with statuses and comment", %{
32 target_user: target_user,
35 assert %{"action_taken" => false, "id" => _} =
37 |> put_req_header("content-type", "application/json")
38 |> post("/api/v1/reports", %{
39 "account_id" => target_user.id,
40 "status_ids" => [activity.id],
41 "comment" => "bad status!",
44 |> json_response_and_validate_schema(200)
47 test "account_id is required", %{
51 assert %{"error" => "Missing field: account_id."} =
53 |> put_req_header("content-type", "application/json")
54 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
55 |> json_response_and_validate_schema(400)
58 test "comment must be up to the size specified in the config", %{
60 target_user: target_user
62 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
63 comment = String.pad_trailing("a", max_size + 1, "a")
65 error = %{"error" => "Comment must be up to #{max_size} characters"}
69 |> put_req_header("content-type", "application/json")
70 |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
71 |> json_response_and_validate_schema(400)
74 test "returns error when account is not exist", %{
80 |> put_req_header("content-type", "application/json")
81 |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
83 assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
86 test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
87 insert(:user, %{is_admin: true, email: nil})
89 assert %{"action_taken" => false, "id" => _} =
91 |> put_req_header("content-type", "application/json")
92 |> post("/api/v1/reports", %{"account_id" => target_user.id})
93 |> json_response_and_validate_schema(200)