1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
6 # TODO: Should not need Cachex
7 use Pleroma.Web.ConnCase
10 import Pleroma.Factory
12 test "get instance information", %{conn: conn} do
13 conn = get(conn, "/api/v1/instance")
14 assert result = json_response_and_validate_schema(conn, 200)
16 email = Pleroma.Config.get([:instance, :email])
17 thumbnail = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
18 background = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :background_image])
20 # Note: not checking for "max_toot_chars" since it's optional
26 "email" => from_config_email,
31 "thumbnail" => from_config_thumbnail,
34 "approval_required" => _,
37 "avatar_upload_limit" => _,
38 "background_upload_limit" => _,
39 "banner_upload_limit" => _,
40 "background_image" => from_config_background,
42 "description_limit" => _
45 assert result["pleroma"]["metadata"]["account_activation_required"] != nil
46 assert result["pleroma"]["metadata"]["features"]
47 assert result["pleroma"]["metadata"]["federation"]
48 assert result["pleroma"]["metadata"]["fields_limits"]
49 assert result["pleroma"]["vapid_public_key"]
51 assert email == from_config_email
52 assert thumbnail == from_config_thumbnail
53 assert background == from_config_background
56 test "get instance stats", %{conn: conn} do
57 user = insert(:user, %{local: true})
59 user2 = insert(:user, %{local: true})
60 {:ok, _user2} = User.set_activation(user2, false)
62 insert(:user, %{local: false, nickname: "u@peer1.com"})
63 insert(:user, %{local: false, nickname: "u@peer2.com"})
65 {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
67 Pleroma.Stats.force_update()
69 conn = get(conn, "/api/v1/instance")
71 assert result = json_response_and_validate_schema(conn, 200)
73 stats = result["stats"]
76 assert stats["user_count"] == 1
77 assert stats["status_count"] == 1
78 assert stats["domain_count"] == 2
81 test "get peers", %{conn: conn} do
82 insert(:user, %{local: false, nickname: "u@peer1.com"})
83 insert(:user, %{local: false, nickname: "u@peer2.com"})
85 Pleroma.Stats.force_update()
87 conn = get(conn, "/api/v1/instance/peers")
89 assert result = json_response_and_validate_schema(conn, 200)
91 assert ["peer1.com", "peer2.com"] == Enum.sort(result)