summaryrefslogtreecommitdiff
path: root/test/pleroma/web/pleroma_api/controllers/report_controller_test.exs
blob: 7940564b734591fc55745a643a2048adb1d44b81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.PleromaAPI.ReportControllerTest do
  use Pleroma.Web.ConnCase, async: true

  import Pleroma.Factory

  alias Pleroma.Web.CommonAPI

  describe "GET /api/v0/pleroma/reports" do
    test "returns list of own reports" do
      %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
      %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
      activity = insert(:note_activity, user: reported)

      {:ok, %{id: report_id}} =
        CommonAPI.report(reporter, %{
          account_id: reported.id,
          comment: "You stole my sandwich!",
          status_ids: [activity.id]
        })

      assert reported_response =
               reported_conn
               |> get("/api/v0/pleroma/reports")
               |> json_response_and_validate_schema(:ok)

      assert reported_response == %{"reports" => [], "total" => 0}

      assert reporter_response =
               reporter_conn
               |> get("/api/v0/pleroma/reports")
               |> json_response_and_validate_schema(:ok)

      assert %{"reports" => [report], "total" => 1} = reporter_response
      assert report["id"] == report_id
      refute report["notes"]
    end
  end

  describe "GET /api/v0/pleroma/reports/:id" do
    test "returns report by its id" do
      %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
      %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
      activity = insert(:note_activity, user: reported)

      {:ok, %{id: report_id}} =
        CommonAPI.report(reporter, %{
          account_id: reported.id,
          comment: "You stole my sandwich!",
          status_ids: [activity.id]
        })

      assert reported_conn
             |> get("/api/v0/pleroma/reports/#{report_id}")
             |> json_response_and_validate_schema(:not_found)

      assert response =
               reporter_conn
               |> get("/api/v0/pleroma/reports/#{report_id}")
               |> json_response_and_validate_schema(:ok)

      assert response["id"] == report_id
      refute response["notes"]
    end

    test "returns 404 when report id is invalid" do
      %{conn: conn, user: _user} = oauth_access(["read:reports"])

      assert response =
               conn
               |> get("/api/v0/pleroma/reports/0")
               |> json_response_and_validate_schema(:not_found)

      assert response == %{"error" => "Record not found"}
    end
  end
end