AdminAPI.InstanceController: clean up tests, rename actions
authorAlex Gleason <alex@alexgleason.me>
Sat, 17 Jul 2021 20:00:15 +0000 (15:00 -0500)
committerAlex Gleason <alex@alexgleason.me>
Sat, 17 Jul 2021 20:00:15 +0000 (15:00 -0500)
lib/pleroma/web/admin_api/controllers/instance_controller.ex
lib/pleroma/web/router.ex
test/pleroma/web/admin_api/controllers/instance_controller_test.exs

index 2fc2fb442038209c3c876d18a10a892e55afb572..00857983fbc73d14a77cec08d32a8ad6c2b4cb0e 100644 (file)
@@ -19,18 +19,18 @@ defmodule Pleroma.Web.AdminAPI.InstanceController do
   plug(
     OAuthScopesPlug,
     %{scopes: ["admin:read:statuses"]}
-    when action in [:list_instance_statuses]
+    when action in [:list_statuses]
   )
 
   plug(
     OAuthScopesPlug,
     %{scopes: ["admin:write:accounts", "admin:write:statuses"]}
-    when action in [:delete_instance]
+    when action in [:delete]
   )
 
   action_fallback(AdminAPI.FallbackController)
 
-  def list_instance_statuses(conn, %{"instance" => instance} = params) do
+  def list_statuses(conn, %{"instance" => instance} = params) do
     with_reblogs = params["with_reblogs"] == "true" || params["with_reblogs"] == true
     {page, page_size} = page_params(params)
 
@@ -48,7 +48,7 @@ defmodule Pleroma.Web.AdminAPI.InstanceController do
     |> render("index.json", %{total: result[:total], activities: result[:items], as: :activity})
   end
 
-  def delete_instance(conn, %{"instance" => instance}) do
+  def delete(conn, %{"instance" => instance}) do
     with {:ok, _job} <- Instance.delete_users_and_activities(instance) do
       json(conn, instance)
     end
index 1f465b697df8a790de277397b6e467166a03fcec..3e2ecc2c0628aec111730ecc4ae2a84423e58ce2 100644 (file)
@@ -209,8 +209,8 @@ defmodule Pleroma.Web.Router do
     get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
     get("/users/:nickname/chats", AdminAPIController, :list_user_chats)
 
-    get("/instances/:instance/statuses", InstanceController, :list_instance_statuses)
-    delete("/instances/:instance", InstanceController, :delete_instance)
+    get("/instances/:instance/statuses", InstanceController, :list_statuses)
+    delete("/instances/:instance", InstanceController, :delete)
 
     get("/instance_document/:name", InstanceDocumentController, :show)
     patch("/instance_document/:name", InstanceDocumentController, :update)
index 42248c6bd56401dcf57928ef1570b436f09c1897..c78307fc8426e021005f86e548f12238c612b5fd 100644 (file)
@@ -30,38 +30,36 @@ defmodule Pleroma.Web.AdminAPI.InstanceControllerTest do
     {:ok, %{admin: admin, token: token, conn: conn}}
   end
 
-  describe "instances" do
-    test "GET /instances/:instance/statuses", %{conn: conn} do
-      user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
-      user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
-      insert_pair(:note_activity, user: user)
-      activity = insert(:note_activity, user: user2)
+  test "GET /instances/:instance/statuses", %{conn: conn} do
+    user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
+    user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
+    insert_pair(:note_activity, user: user)
+    activity = insert(:note_activity, user: user2)
 
-      %{"total" => 2, "activities" => activities} =
-        conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
+    %{"total" => 2, "activities" => activities} =
+      conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
 
-      assert length(activities) == 2
+    assert length(activities) == 2
 
-      %{"total" => 1, "activities" => [_]} =
-        conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
+    %{"total" => 1, "activities" => [_]} =
+      conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
 
-      %{"total" => 0, "activities" => []} =
-        conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
+    %{"total" => 0, "activities" => []} =
+      conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
 
-      CommonAPI.repeat(activity.id, user)
+    CommonAPI.repeat(activity.id, user)
 
-      %{"total" => 2, "activities" => activities} =
-        conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
+    %{"total" => 2, "activities" => activities} =
+      conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
 
-      assert length(activities) == 2
+    assert length(activities) == 2
 
-      %{"total" => 3, "activities" => activities} =
-        conn
-        |> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
-        |> json_response(200)
+    %{"total" => 3, "activities" => activities} =
+      conn
+      |> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
+      |> json_response(200)
 
-      assert length(activities) == 3
-    end
+    assert length(activities) == 3
   end
 
   test "DELETE /instances/:instance", %{conn: conn} do