logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

report_controller_test.exs (2629B)


  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. defmodule Pleroma.Web.PleromaAPI.ReportControllerTest do
  5. use Pleroma.Web.ConnCase, async: true
  6. import Pleroma.Factory
  7. alias Pleroma.Web.CommonAPI
  8. describe "GET /api/v0/pleroma/reports" do
  9. test "returns list of own reports" do
  10. %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
  11. %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
  12. activity = insert(:note_activity, user: reported)
  13. {:ok, %{id: report_id}} =
  14. CommonAPI.report(reporter, %{
  15. account_id: reported.id,
  16. comment: "You stole my sandwich!",
  17. status_ids: [activity.id]
  18. })
  19. assert reported_response =
  20. reported_conn
  21. |> get("/api/v0/pleroma/reports")
  22. |> json_response_and_validate_schema(:ok)
  23. assert reported_response == %{"reports" => [], "total" => 0}
  24. assert reporter_response =
  25. reporter_conn
  26. |> get("/api/v0/pleroma/reports")
  27. |> json_response_and_validate_schema(:ok)
  28. assert %{"reports" => [report], "total" => 1} = reporter_response
  29. assert report["id"] == report_id
  30. refute report["notes"]
  31. end
  32. end
  33. describe "GET /api/v0/pleroma/reports/:id" do
  34. test "returns report by its id" do
  35. %{conn: reporter_conn, user: reporter} = oauth_access(["read:reports"])
  36. %{conn: reported_conn, user: reported} = oauth_access(["read:reports"])
  37. activity = insert(:note_activity, user: reported)
  38. {:ok, %{id: report_id}} =
  39. CommonAPI.report(reporter, %{
  40. account_id: reported.id,
  41. comment: "You stole my sandwich!",
  42. status_ids: [activity.id]
  43. })
  44. assert reported_conn
  45. |> get("/api/v0/pleroma/reports/#{report_id}")
  46. |> json_response_and_validate_schema(:not_found)
  47. assert response =
  48. reporter_conn
  49. |> get("/api/v0/pleroma/reports/#{report_id}")
  50. |> json_response_and_validate_schema(:ok)
  51. assert response["id"] == report_id
  52. refute response["notes"]
  53. end
  54. test "returns 404 when report id is invalid" do
  55. %{conn: conn, user: _user} = oauth_access(["read:reports"])
  56. assert response =
  57. conn
  58. |> get("/api/v0/pleroma/reports/0")
  59. |> json_response_and_validate_schema(:not_found)
  60. assert response == %{"error" => "Record not found"}
  61. end
  62. end
  63. end