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
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 |> post("/api/v1/reports", %{"account_id" => target_user.id})
29 test "submit a report with statuses and comment", %{
31 target_user: target_user,
34 assert %{"action_taken" => false, "id" => _} =
36 |> post("/api/v1/reports", %{
37 "account_id" => target_user.id,
38 "status_ids" => [activity.id],
39 "comment" => "bad status!",
45 test "account_id is required", %{
49 assert %{"error" => "Valid `account_id` required"} =
51 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
55 test "comment must be up to the size specified in the config", %{
57 target_user: target_user
59 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
60 comment = String.pad_trailing("a", max_size + 1, "a")
62 error = %{"error" => "Comment must be up to #{max_size} characters"}
66 |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
70 test "returns error when account is not exist", %{
74 conn = post(conn, "/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
76 assert json_response(conn, 400) == %{"error" => "Account not found"}