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.AdminAPI.InstanceControllerTest do
6 use Pleroma.Web.ConnCase, async: false
7 use Oban.Testing, repo: Pleroma.Repo
12 alias Pleroma.Tests.ObanHelpers
13 alias Pleroma.Web.CommonAPI
16 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
22 admin = insert(:user, is_admin: true)
23 token = insert(:oauth_admin_token, user: admin)
27 |> assign(:user, admin)
28 |> assign(:token, token)
30 {:ok, %{admin: admin, token: token, conn: conn}}
33 test "GET /instances/:instance/statuses", %{conn: conn} do
34 clear_config([:instance, :admin_privileges], [:messages_read])
35 user = insert(:user, local: false, ap_id: "https://archae.me/users/archaeme")
36 user2 = insert(:user, local: false, ap_id: "https://test.com/users/test")
37 insert_pair(:note_activity, user: user)
38 activity = insert(:note_activity, user: user2)
40 %{"total" => 2, "activities" => activities} =
41 conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
43 assert length(activities) == 2
45 %{"total" => 1, "activities" => [_]} =
46 conn |> get("/api/pleroma/admin/instances/test.com/statuses") |> json_response(200)
48 %{"total" => 0, "activities" => []} =
49 conn |> get("/api/pleroma/admin/instances/nonexistent.com/statuses") |> json_response(200)
51 CommonAPI.repeat(activity.id, user)
53 %{"total" => 2, "activities" => activities} =
54 conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(200)
56 assert length(activities) == 2
58 %{"total" => 3, "activities" => activities} =
60 |> get("/api/pleroma/admin/instances/archae.me/statuses?with_reblogs=true")
63 assert length(activities) == 3
65 clear_config([:instance, :admin_privileges], [])
67 conn |> get("/api/pleroma/admin/instances/archae.me/statuses") |> json_response(:forbidden)
70 test "DELETE /instances/:instance", %{conn: conn} do
71 clear_config([:instance, :admin_privileges], [:instances_delete])
72 user = insert(:user, nickname: "lain@lain.com")
73 post = insert(:note_activity, user: user)
77 |> delete("/api/pleroma/admin/instances/lain.com")
80 [:ok] = ObanHelpers.perform_all()
82 assert response == "lain.com"
83 refute Repo.reload(user).is_active
84 refute Repo.reload(post)
86 clear_config([:instance, :admin_privileges], [])
89 |> delete("/api/pleroma/admin/instances/lain.com")
90 |> json_response(:forbidden)