1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.RelayControllerTest do
6 use Pleroma.Web.ConnCase
11 alias Pleroma.ModerationLog
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}}
34 test "POST /relay", %{conn: conn, admin: admin} do
37 |> put_req_header("content-type", "application/json")
38 |> post("/api/pleroma/admin/relay", %{
39 relay_url: "http://mastodon.example.org/users/admin"
42 assert json_response_and_validate_schema(conn, 200) ==
43 "http://mastodon.example.org/users/admin"
45 log_entry = Repo.one(ModerationLog)
47 assert ModerationLog.get_log_entry_message(log_entry) ==
48 "@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
51 test "GET /relay", %{conn: conn} do
52 relay_user = Pleroma.Web.ActivityPub.Relay.get_actor()
54 ["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
55 |> Enum.each(fn ap_id ->
56 {:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
57 User.follow(relay_user, user)
60 conn = get(conn, "/api/pleroma/admin/relay")
62 assert json_response_and_validate_schema(conn, 200)["relays"] --
63 ["mastodon.example.org", "mstdn.io"] == []
66 test "DELETE /relay", %{conn: conn, admin: admin} do
68 |> put_req_header("content-type", "application/json")
69 |> post("/api/pleroma/admin/relay", %{
70 relay_url: "http://mastodon.example.org/users/admin"
75 |> put_req_header("content-type", "application/json")
76 |> delete("/api/pleroma/admin/relay", %{
77 relay_url: "http://mastodon.example.org/users/admin"
80 assert json_response_and_validate_schema(conn, 200) ==
81 "http://mastodon.example.org/users/admin"
83 [log_entry_one, log_entry_two] = Repo.all(ModerationLog)
85 assert ModerationLog.get_log_entry_message(log_entry_one) ==
86 "@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
88 assert ModerationLog.get_log_entry_message(log_entry_two) ==
89 "@#{admin.nickname} unfollowed relay: http://mastodon.example.org/users/admin"