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.MastodonAPI.InstanceControllerTest do
6 use Pleroma.Web.ConnCase
11 test "get instance information", %{conn: conn} do
12 conn = get(conn, "/api/v1/instance")
13 assert result = json_response_and_validate_schema(conn, 200)
15 email = Pleroma.Config.get([:instance, :email])
16 thumbnail = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
17 background = Pleroma.Web.base_url() <> Pleroma.Config.get([:instance, :background_image])
19 # Note: not checking for "max_toot_chars" since it's optional
25 "email" => from_config_email,
30 "thumbnail" => from_config_thumbnail,
33 "approval_required" => _,
36 "avatar_upload_limit" => _,
37 "background_upload_limit" => _,
38 "banner_upload_limit" => _,
39 "background_image" => from_config_background,
41 "description_limit" => _
44 assert result["pleroma"]["metadata"]["account_activation_required"] != nil
45 assert result["pleroma"]["metadata"]["features"]
46 assert result["pleroma"]["metadata"]["federation"]
47 assert result["pleroma"]["metadata"]["fields_limits"]
48 assert result["pleroma"]["vapid_public_key"]
50 assert email == from_config_email
51 assert thumbnail == from_config_thumbnail
52 assert background == from_config_background
55 test "get instance stats", %{conn: conn} do
56 user = insert(:user, %{local: true})
58 user2 = insert(:user, %{local: true})
59 {:ok, _user2} = User.deactivate(user2, !user2.deactivated)
61 insert(:user, %{local: false, nickname: "u@peer1.com"})
62 insert(:user, %{local: false, nickname: "u@peer2.com"})
64 {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
66 Pleroma.Stats.force_update()
68 conn = get(conn, "/api/v1/instance")
70 assert result = json_response_and_validate_schema(conn, 200)
72 stats = result["stats"]
75 assert stats["user_count"] == 1
76 assert stats["status_count"] == 1
77 assert stats["domain_count"] == 2
80 test "get peers", %{conn: conn} do
81 insert(:user, %{local: false, nickname: "u@peer1.com"})
82 insert(:user, %{local: false, nickname: "u@peer2.com"})
84 Pleroma.Stats.force_update()
86 conn = get(conn, "/api/v1/instance/peers")
88 assert result = json_response_and_validate_schema(conn, 200)
90 assert ["peer1.com", "peer2.com"] == Enum.sort(result)