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"]
50 assert result["pleroma"]["stats"]["mau"] == 0
52 assert email == from_config_email
53 assert thumbnail == from_config_thumbnail
54 assert background == from_config_background
57 test "get instance stats", %{conn: conn} do
58 user = insert(:user, %{local: true})
60 user2 = insert(:user, %{local: true})
61 {:ok, _user2} = User.set_activation(user2, false)
63 insert(:user, %{local: false, nickname: "u@peer1.com"})
64 insert(:user, %{local: false, nickname: "u@peer2.com"})
66 {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
68 Pleroma.Stats.force_update()
70 conn = get(conn, "/api/v1/instance")
72 assert result = json_response_and_validate_schema(conn, 200)
74 stats = result["stats"]
77 assert stats["user_count"] == 1
78 assert stats["status_count"] == 1
79 assert stats["domain_count"] == 2
82 test "get peers", %{conn: conn} do
83 insert(:user, %{local: false, nickname: "u@peer1.com"})
84 insert(:user, %{local: false, nickname: "u@peer2.com"})
86 Pleroma.Stats.force_update()
88 conn = get(conn, "/api/v1/instance/peers")
90 assert result = json_response_and_validate_schema(conn, 200)
92 assert ["peer1.com", "peer2.com"] == Enum.sort(result)