[#1260] Merge remote-tracking branch 'remotes/upstream/develop' into 1260-rate-limite...
[akkoma] / test / web / mastodon_api / controllers / report_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
6 use Pleroma.Web.ConnCase
7
8 alias Pleroma.Web.CommonAPI
9
10 import Pleroma.Factory
11
12 setup do
13 reporter = insert(:user)
14 target_user = insert(:user)
15
16 {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
17
18 [reporter: reporter, target_user: target_user, activity: activity]
19 end
20
21 test "submit a basic report", %{conn: conn, reporter: reporter, target_user: target_user} do
22 assert %{"action_taken" => false, "id" => _} =
23 conn
24 |> assign(:user, reporter)
25 |> post("/api/v1/reports", %{"account_id" => target_user.id})
26 |> json_response(200)
27 end
28
29 test "submit a report with statuses and comment", %{
30 conn: conn,
31 reporter: reporter,
32 target_user: target_user,
33 activity: activity
34 } do
35 assert %{"action_taken" => false, "id" => _} =
36 conn
37 |> assign(:user, reporter)
38 |> post("/api/v1/reports", %{
39 "account_id" => target_user.id,
40 "status_ids" => [activity.id],
41 "comment" => "bad status!",
42 "forward" => "false"
43 })
44 |> json_response(200)
45 end
46
47 test "account_id is required", %{
48 conn: conn,
49 reporter: reporter,
50 activity: activity
51 } do
52 assert %{"error" => "Valid `account_id` required"} =
53 conn
54 |> assign(:user, reporter)
55 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
56 |> json_response(400)
57 end
58
59 test "comment must be up to the size specified in the config", %{
60 conn: conn,
61 reporter: reporter,
62 target_user: target_user
63 } do
64 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
65 comment = String.pad_trailing("a", max_size + 1, "a")
66
67 error = %{"error" => "Comment must be up to #{max_size} characters"}
68
69 assert ^error =
70 conn
71 |> assign(:user, reporter)
72 |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
73 |> json_response(400)
74 end
75
76 test "returns error when account is not exist", %{
77 conn: conn,
78 reporter: reporter,
79 activity: activity
80 } do
81 conn =
82 conn
83 |> assign(:user, reporter)
84 |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
85
86 assert json_response(conn, 400) == %{"error" => "Account not found"}
87 end
88 end