Merge remote-tracking branch 'remotes/origin/develop' into 1560-non-federating-instan...
[akkoma] / test / web / mastodon_api / controllers / report_controller_test.exs
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
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: oauth_access(["write:reports"])
13
14 setup do
15 target_user = insert(:user)
16
17 {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
18
19 [target_user: target_user, activity: activity]
20 end
21
22 test "submit a basic report", %{conn: conn, target_user: target_user} do
23 assert %{"action_taken" => false, "id" => _} =
24 conn
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 target_user: target_user,
32 activity: activity
33 } do
34 assert %{"action_taken" => false, "id" => _} =
35 conn
36 |> post("/api/v1/reports", %{
37 "account_id" => target_user.id,
38 "status_ids" => [activity.id],
39 "comment" => "bad status!",
40 "forward" => "false"
41 })
42 |> json_response(200)
43 end
44
45 test "account_id is required", %{
46 conn: conn,
47 activity: activity
48 } do
49 assert %{"error" => "Valid `account_id` required"} =
50 conn
51 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
52 |> json_response(400)
53 end
54
55 test "comment must be up to the size specified in the config", %{
56 conn: conn,
57 target_user: target_user
58 } do
59 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
60 comment = String.pad_trailing("a", max_size + 1, "a")
61
62 error = %{"error" => "Comment must be up to #{max_size} characters"}
63
64 assert ^error =
65 conn
66 |> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
67 |> json_response(400)
68 end
69
70 test "returns error when account is not exist", %{
71 conn: conn,
72 activity: activity
73 } do
74 conn = post(conn, "/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
75
76 assert json_response(conn, 400) == %{"error" => "Account not found"}
77 end
78
79 test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
80 insert(:user, %{is_admin: true, email: nil})
81
82 assert %{"action_taken" => false, "id" => _} =
83 conn
84 |> post("/api/v1/reports", %{"account_id" => target_user.id})
85 |> json_response(200)
86 end
87 end