Add GET /api/pleroma/admin/relay endpoint - lists all followed relays
This commit is contained in:
parent
44afe4c887
commit
cc6875b582
8 changed files with 112 additions and 8 deletions
|
|
@ -17,6 +17,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
alias Pleroma.Web.MediaProxy
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/users" do
|
||||
test "Delete" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
|
@ -2486,6 +2492,74 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert User.get_by_id(user.id).info.password_reset_pending == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "relays" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
end
|
||||
|
||||
test "POST /relay", %{admin: admin} do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> post("/api/pleroma/admin/relay", %{
|
||||
relay_url: "http://mastodon.example.org/users/admin"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == "http://mastodon.example.org/users/admin"
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
|
||||
end
|
||||
|
||||
test "GET /relay", %{admin: admin} do
|
||||
Pleroma.Web.ActivityPub.Relay.get_actor()
|
||||
|> Ecto.Changeset.change(
|
||||
following: [
|
||||
"http://test-app.com/user/test1",
|
||||
"http://test-app.com/user/test1",
|
||||
"http://test-app-42.com/user/test1"
|
||||
]
|
||||
)
|
||||
|> Pleroma.User.update_and_set_cache()
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> get("/api/pleroma/admin/relay")
|
||||
|
||||
assert json_response(conn, 200)["relays"] -- ["test-app.com", "test-app-42.com"] == []
|
||||
end
|
||||
|
||||
test "DELETE /relay", %{admin: admin} do
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> post("/api/pleroma/admin/relay", %{
|
||||
relay_url: "http://mastodon.example.org/users/admin"
|
||||
})
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> delete("/api/pleroma/admin/relay", %{
|
||||
relay_url: "http://mastodon.example.org/users/admin"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == "http://mastodon.example.org/users/admin"
|
||||
|
||||
[log_entry_one, log_entry_two] = Repo.all(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry_one) ==
|
||||
"@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry_two) ==
|
||||
"@#{admin.nickname} unfollowed relay: http://mastodon.example.org/users/admin"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Needed for testing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue