move to 2.5.5
[anni] / test / pleroma / web / pleroma_api / controllers / report_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.ReportControllerTest do
6   use Pleroma.Web.ConnCase, async: true
7
8   import Pleroma.Factory
9
10   alias Pleroma.Web.CommonAPI
11
12   describe "GET /api/v0/pleroma/reports" do
13     test "returns list of own reports" do
14       %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
15       %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
16       activity = insert(:note_activity, user: reported)
17
18       {:ok, %{id: report_id}} =
19         CommonAPI.report(reporter, %{
20           account_id: reported.id,
21           comment: "You stole my sandwich!",
22           status_ids: [activity.id]
23         })
24
25       assert reported_response =
26                reported_conn
27                |> get("/api/v0/pleroma/reports")
28                |> json_response_and_validate_schema(:ok)
29
30       assert reported_response == %{"reports" => [], "total" => 0}
31
32       assert reporter_response =
33                reporter_conn
34                |> get("/api/v0/pleroma/reports")
35                |> json_response_and_validate_schema(:ok)
36
37       assert %{"reports" => [report], "total" => 1} = reporter_response
38       assert report["id"] == report_id
39       refute report["notes"]
40     end
41   end
42
43   describe "GET /api/v0/pleroma/reports/:id" do
44     test "returns report by its id" do
45       %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
46       %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
47       activity = insert(:note_activity, user: reported)
48
49       {:ok, %{id: report_id}} =
50         CommonAPI.report(reporter, %{
51           account_id: reported.id,
52           comment: "You stole my sandwich!",
53           status_ids: [activity.id]
54         })
55
56       assert reported_conn
57              |> get("/api/v0/pleroma/reports/#{report_id}")
58              |> json_response_and_validate_schema(:not_found)
59
60       assert response =
61                reporter_conn
62                |> get("/api/v0/pleroma/reports/#{report_id}")
63                |> json_response_and_validate_schema(:ok)
64
65       assert response["id"] == report_id
66       refute response["notes"]
67     end
68
69     test "returns 404 when report id is invalid" do
70       %{conn: conn, user: _user} = oauth_access(["read:reports"])
71
72       assert response =
73                conn
74                |> get("/api/v0/pleroma/reports/0")
75                |> json_response_and_validate_schema(:not_found)
76
77       assert response == %{"error" => "Record not found"}
78     end
79   end
80 end