Merge branch 'develop' into a1batross-develop-patch-62810
[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 assert result["pleroma"]["stats"]["mau"] == 0
51
52 assert email == from_config_email
53 assert thumbnail == from_config_thumbnail
54 assert background == from_config_background
55 end
56
57 test "get instance stats", %{conn: conn} do
58 user = insert(:user, %{local: true})
59
60 user2 = insert(:user, %{local: true})
61 {:ok, _user2} = User.set_activation(user2, false)
62
63 insert(:user, %{local: false, nickname: "u@peer1.com"})
64 insert(:user, %{local: false, nickname: "u@peer2.com"})
65
66 {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
67
68 Pleroma.Stats.force_update()
69
70 conn = get(conn, "/api/v1/instance")
71
72 assert result = json_response_and_validate_schema(conn, 200)
73
74 stats = result["stats"]
75
76 assert stats
77 assert stats["user_count"] == 1
78 assert stats["status_count"] == 1
79 assert stats["domain_count"] == 2
80 end
81
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"})
85
86 Pleroma.Stats.force_update()
87
88 conn = get(conn, "/api/v1/instance/peers")
89
90 assert result = json_response_and_validate_schema(conn, 200)
91
92 assert ["peer1.com", "peer2.com"] == Enum.sort(result)
93 end
94 end