remove `unread_conversation_count` from User
[akkoma] / test / pleroma / 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 |> put_req_header("content-type", "application/json")
26 |> post("/api/v1/reports", %{"account_id" => target_user.id})
27 |> json_response_and_validate_schema(200)
28 end
29
30 test "submit a report with statuses and comment", %{
31 conn: conn,
32 target_user: target_user,
33 activity: activity
34 } do
35 assert %{"action_taken" => false, "id" => _} =
36 conn
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!",
42 "forward" => "false"
43 })
44 |> json_response_and_validate_schema(200)
45 end
46
47 test "account_id is required", %{
48 conn: conn,
49 activity: activity
50 } do
51 assert %{"error" => "Missing field: account_id."} =
52 conn
53 |> put_req_header("content-type", "application/json")
54 |> post("/api/v1/reports", %{"status_ids" => [activity.id]})
55 |> json_response_and_validate_schema(400)
56 end
57
58 test "comment must be up to the size specified in the config", %{
59 conn: conn,
60 target_user: target_user
61 } do
62 max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
63 comment = String.pad_trailing("a", max_size + 1, "a")
64
65 error = %{"error" => "Comment must be up to #{max_size} characters"}
66
67 assert ^error =
68 conn
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)
72 end
73
74 test "returns error when account is not exist", %{
75 conn: conn,
76 activity: activity
77 } do
78 conn =
79 conn
80 |> put_req_header("content-type", "application/json")
81 |> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
82
83 assert json_response_and_validate_schema(conn, 400) == %{"error" => "Account not found"}
84 end
85
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})
88
89 assert %{"action_taken" => false, "id" => _} =
90 conn
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)
94 end
95 end