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 "actor" => "http://mastodon.example.org/users/admin",
44 "followed_back" => false
47 log_entry = Repo.one(ModerationLog)
49 assert ModerationLog.get_log_entry_message(log_entry) ==
50 "@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
53 test "GET /relay", %{conn: conn} do
54 relay_user = Pleroma.Web.ActivityPub.Relay.get_actor()
56 ["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
57 |> Enum.each(fn ap_id ->
58 {:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
59 User.follow(relay_user, user)
62 conn = get(conn, "/api/pleroma/admin/relay")
64 assert json_response_and_validate_schema(conn, 200)["relays"] == [
66 "actor" => "http://mastodon.example.org/users/admin",
67 "followed_back" => true
69 %{"actor" => "https://mstdn.io/users/mayuutann", "followed_back" => true}
73 test "DELETE /relay", %{conn: conn, admin: admin} do
75 |> put_req_header("content-type", "application/json")
76 |> post("/api/pleroma/admin/relay", %{
77 relay_url: "http://mastodon.example.org/users/admin"
82 |> put_req_header("content-type", "application/json")
83 |> delete("/api/pleroma/admin/relay", %{
84 relay_url: "http://mastodon.example.org/users/admin"
87 assert json_response_and_validate_schema(conn, 200) ==
88 "http://mastodon.example.org/users/admin"
90 [log_entry_one, log_entry_two] = Repo.all(ModerationLog)
92 assert ModerationLog.get_log_entry_message(log_entry_one) ==
93 "@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
95 assert ModerationLog.get_log_entry_message(log_entry_two) ==
96 "@#{admin.nickname} unfollowed relay: http://mastodon.example.org/users/admin"