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