diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/web/admin_api/admin_api_controller_test.exs | 158 | ||||
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 29 | 
2 files changed, 170 insertions, 17 deletions
| diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index b5c355e66..daa0631db 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1224,7 +1224,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end    end -  describe "PUT /api/pleroma/admin/reports/:id" do +  describe "PATCH /api/pleroma/admin/reports" do      setup %{conn: conn} do        admin = insert(:user, info: %{is_admin: true})        [reporter, target_user] = insert_pair(:user) @@ -1237,16 +1237,32 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do            "status_ids" => [activity.id]          }) -      %{conn: assign(conn, :user, admin), id: report_id, admin: admin} +      {:ok, %{id: second_report_id}} = +        CommonAPI.report(reporter, %{ +          "account_id" => target_user.id, +          "comment" => "I feel very offended", +          "status_ids" => [activity.id] +        }) + +      %{ +        conn: assign(conn, :user, admin), +        id: report_id, +        admin: admin, +        second_report_id: second_report_id +      }      end      test "mark report as resolved", %{conn: conn, id: id, admin: admin} do -      response = -        conn -        |> put("/api/pleroma/admin/reports/#{id}", %{"state" => "resolved"}) -        |> json_response(:ok) +      conn +      |> patch("/api/pleroma/admin/reports", %{ +        "reports" => [ +          %{"state" => "resolved", "id" => id} +        ] +      }) +      |> json_response(:no_content) -      assert response["state"] == "resolved" +      activity = Activity.get_by_id(id) +      assert activity.data["state"] == "resolved"        log_entry = Repo.one(ModerationLog) @@ -1255,12 +1271,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end      test "closes report", %{conn: conn, id: id, admin: admin} do -      response = -        conn -        |> put("/api/pleroma/admin/reports/#{id}", %{"state" => "closed"}) -        |> json_response(:ok) +      conn +      |> patch("/api/pleroma/admin/reports", %{ +        "reports" => [ +          %{"state" => "closed", "id" => id} +        ] +      }) +      |> json_response(:no_content) -      assert response["state"] == "closed" +      activity = Activity.get_by_id(id) +      assert activity.data["state"] == "closed"        log_entry = Repo.one(ModerationLog) @@ -1271,17 +1291,54 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      test "returns 400 when state is unknown", %{conn: conn, id: id} do        conn =          conn -        |> put("/api/pleroma/admin/reports/#{id}", %{"state" => "test"}) +        |> patch("/api/pleroma/admin/reports", %{ +          "reports" => [ +            %{"state" => "test", "id" => id} +          ] +        }) -      assert json_response(conn, :bad_request) == "Unsupported state" +      assert hd(json_response(conn, :bad_request))["error"] == "Unsupported state"      end      test "returns 404 when report is not exist", %{conn: conn} do        conn =          conn -        |> put("/api/pleroma/admin/reports/test", %{"state" => "closed"}) +        |> patch("/api/pleroma/admin/reports", %{ +          "reports" => [ +            %{"state" => "closed", "id" => "test"} +          ] +        }) -      assert json_response(conn, :not_found) == "Not found" +      assert hd(json_response(conn, :bad_request))["error"] == "not_found" +    end + +    test "updates state of multiple reports", %{ +      conn: conn, +      id: id, +      admin: admin, +      second_report_id: second_report_id +    } do +      conn +      |> patch("/api/pleroma/admin/reports", %{ +        "reports" => [ +          %{"state" => "resolved", "id" => id}, +          %{"state" => "closed", "id" => second_report_id} +        ] +      }) +      |> json_response(:no_content) + +      activity = Activity.get_by_id(id) +      second_activity = Activity.get_by_id(second_report_id) +      assert activity.data["state"] == "resolved" +      assert second_activity.data["state"] == "closed" + +      [first_log_entry, second_log_entry] = Repo.all(ModerationLog) + +      assert ModerationLog.get_log_entry_message(first_log_entry) == +               "@#{admin.nickname} updated report ##{id} with 'resolved' state" + +      assert ModerationLog.get_log_entry_message(second_log_entry) == +               "@#{admin.nickname} updated report ##{second_report_id} with 'closed' state"      end    end @@ -1404,7 +1461,74 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end    end -  # +  describe "GET /api/pleroma/admin/grouped_reports" do +    setup %{conn: conn} do +      admin = insert(:user, info: %{is_admin: true}) +      [reporter, target_user] = insert_pair(:user) + +      date1 = (DateTime.to_unix(DateTime.utc_now()) + 1000) |> DateTime.from_unix!() +      date2 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!() +      date3 = (DateTime.to_unix(DateTime.utc_now()) + 3000) |> DateTime.from_unix!() + +      first_status = +        insert(:note_activity, user: target_user, data_attrs: %{"published" => date1}) + +      second_status = +        insert(:note_activity, user: target_user, data_attrs: %{"published" => date2}) + +      third_status = +        insert(:note_activity, user: target_user, data_attrs: %{"published" => date3}) + +      %{ +        conn: assign(conn, :user, admin), +        reporter: reporter, +        target_user: target_user, +        first_status: first_status, +        second_status: second_status, +        third_status: third_status +      } +    end + +    test "returns reports grouped by status", %{ +      conn: conn, +      reporter: reporter, +      target_user: target_user, +      first_status: first_status, +      second_status: second_status, +      third_status: third_status +    } do +      {:ok, %{id: _}} = +        CommonAPI.report(reporter, %{ +          "account_id" => target_user.id, +          "status_ids" => [first_status.id, second_status.id, third_status.id] +        }) + +      {:ok, %{id: _}} = +        CommonAPI.report(reporter, %{ +          "account_id" => target_user.id, +          "status_ids" => [first_status.id, second_status.id] +        }) + +      {:ok, %{id: _}} = +        CommonAPI.report(reporter, %{ +          "account_id" => target_user.id, +          "status_ids" => [first_status.id] +        }) + +      response = +        conn +        |> get("/api/pleroma/admin/grouped_reports") +        |> json_response(:ok) + +      assert length(response["reports"]) == 3 +      [third_group, second_group, first_group] = response["reports"] + +      assert length(third_group["reports"]) == 3 +      assert length(second_group["reports"]) == 2 +      assert length(first_group["reports"]) == 1 +    end +  end +    describe "POST /api/pleroma/admin/reports/:id/respond" do      setup %{conn: conn} do        admin = insert(:user, info: %{is_admin: true}) diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 83df44c36..2b34f1d1e 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -427,6 +427,35 @@ defmodule Pleroma.Web.CommonAPITest do        assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}      end + +    test "updates state of multiple reports" do +      [reporter, target_user] = insert_pair(:user) +      activity = insert(:note_activity, user: target_user) + +      {:ok, %Activity{id: first_report_id}} = +        CommonAPI.report(reporter, %{ +          "account_id" => target_user.id, +          "comment" => "I feel offended", +          "status_ids" => [activity.id] +        }) + +      {:ok, %Activity{id: second_report_id}} = +        CommonAPI.report(reporter, %{ +          "account_id" => target_user.id, +          "comment" => "I feel very offended!", +          "status_ids" => [activity.id] +        }) + +      {:ok, report_ids} = +        CommonAPI.update_report_state([first_report_id, second_report_id], "resolved") + +      first_report = Activity.get_by_id(first_report_id) +      second_report = Activity.get_by_id(second_report_id) + +      assert report_ids -- [first_report_id, second_report_id] == [] +      assert first_report.data["state"] == "resolved" +      assert second_report.data["state"] == "resolved" +    end    end    describe "reblog muting" do | 
