1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.ReportControllerTest do
6 use Pleroma.Web.ConnCase, async: true
10 alias Pleroma.Web.CommonAPI
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)
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]
25 assert reported_response =
27 |> get("/api/v0/pleroma/reports")
28 |> json_response_and_validate_schema(:ok)
30 assert reported_response == %{"reports" => [], "total" => 0}
32 assert reporter_response =
34 |> get("/api/v0/pleroma/reports")
35 |> json_response_and_validate_schema(:ok)
37 assert %{"reports" => [report], "total" => 1} = reporter_response
38 assert report["id"] == report_id
39 refute report["notes"]
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)
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]
57 |> get("/api/v0/pleroma/reports/#{report_id}")
58 |> json_response_and_validate_schema(:not_found)
62 |> get("/api/v0/pleroma/reports/#{report_id}")
63 |> json_response_and_validate_schema(:ok)
65 assert response["id"] == report_id
66 refute response["notes"]
69 test "returns 404 when report id is invalid" do
70 %{conn: conn, user: _user} = oauth_access(["read:reports"])
74 |> get("/api/v0/pleroma/reports/0")
75 |> json_response_and_validate_schema(:not_found)
77 assert response == %{"error" => "Record not found"}