Switch to a build of Majic that does not try to fix extensions by default
[akkoma] / test / pleroma / web / mastodon_api / controllers / instance_controller_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
6 # TODO: Should not need Cachex
7 use Pleroma.Web.ConnCase
8
9 alias Pleroma.User
10 import Pleroma.Factory
11
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)
15
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])
19
20 # Note: not checking for "max_toot_chars" since it's optional
21 assert %{
22 "uri" => _,
23 "title" => _,
24 "description" => _,
25 "version" => _,
26 "email" => from_config_email,
27 "urls" => %{
28 "streaming_api" => _
29 },
30 "stats" => _,
31 "thumbnail" => from_config_thumbnail,
32 "languages" => _,
33 "registrations" => _,
34 "approval_required" => _,
35 "poll_limits" => _,
36 "upload_limit" => _,
37 "avatar_upload_limit" => _,
38 "background_upload_limit" => _,
39 "banner_upload_limit" => _,
40 "background_image" => from_config_background,
41 "chat_limit" => _,
42 "description_limit" => _
43 } = result
44
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
51 assert email == from_config_email
52 assert thumbnail == from_config_thumbnail
53 assert background == from_config_background
54 end
55
56 test "get instance stats", %{conn: conn} do
57 user = insert(:user, %{local: true})
58
59 user2 = insert(:user, %{local: true})
60 {:ok, _user2} = User.set_activation(user2, false)
61
62 insert(:user, %{local: false, nickname: "u@peer1.com"})
63 insert(:user, %{local: false, nickname: "u@peer2.com"})
64
65 {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
66
67 Pleroma.Stats.force_update()
68
69 conn = get(conn, "/api/v1/instance")
70
71 assert result = json_response_and_validate_schema(conn, 200)
72
73 stats = result["stats"]
74
75 assert stats
76 assert stats["user_count"] == 1
77 assert stats["status_count"] == 1
78 assert stats["domain_count"] == 2
79 end
80
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"})
84
85 Pleroma.Stats.force_update()
86
87 conn = get(conn, "/api/v1/instance/peers")
88
89 assert result = json_response_and_validate_schema(conn, 200)
90
91 assert ["peer1.com", "peer2.com"] == Enum.sort(result)
92 end
93 end