1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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
8 alias Pleroma.Web.CommonAPI
10 import Pleroma.Factory
13 reporter = insert(:user)
14 target_user = insert(:user)
16 {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
18 [reporter: reporter, target_user: target_user, activity: activity]
21 test "submit a basic report", %{conn: conn, reporter: reporter, target_user: target_user} do
22 assert %{"action_taken" => false, "id" => _} =
24 |> assign(:user, reporter)
25 |> post("/api/v1/reports", %{"account_id" => target_user.id})
29 test "submit a report with statuses and comment", %{
32 target_user: target_user,
35 assert %{"action_taken" => false, "id" => _} =
37 |> assign(:user, reporter)
38 |> post("/api/v1/reports", %{
39 "account_id" => target_user.id,
40 "status_ids" => [activity.id],
41 "comment" => "bad status!",
47 test "account_id is required", %{
52 assert %{"error" => "Valid `account_id` required"} =
54 |> assign(:user, reporter)
55 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
59 test "comment must be up to the size specified in the config", %{
62 target_user: target_user
64 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
65 comment = String.pad_trailing("a", max_size + 1, "a")
67 error = %{"error" => "Comment must be up to #{max_size} characters"}
71 |> assign(:user, reporter)
72 |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
76 test "returns error when account is not exist", %{
83 |> assign(:user, reporter)
84 |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
86 assert json_response(conn, 400) == %{"error" => "Account not found"}