1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
18 background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
20 # Note: not checking for "max_toot_chars" since it's optional
25 "short_description" => _,
27 "email" => from_config_email,
32 "thumbnail" => from_config_thumbnail,
35 "approval_required" => _,
38 "avatar_upload_limit" => _,
39 "background_upload_limit" => _,
40 "banner_upload_limit" => _,
41 "background_image" => from_config_background,
43 "description_limit" => _
46 assert result["pleroma"]["metadata"]["account_activation_required"] != nil
47 assert result["pleroma"]["metadata"]["features"]
48 assert result["pleroma"]["metadata"]["federation"]
49 assert result["pleroma"]["metadata"]["fields_limits"]
50 assert result["pleroma"]["vapid_public_key"]
51 assert result["pleroma"]["stats"]["mau"] == 0
53 assert email == from_config_email
54 assert thumbnail == from_config_thumbnail
55 assert background == from_config_background
58 test "get instance stats", %{conn: conn} do
59 user = insert(:user, %{local: true})
61 user2 = insert(:user, %{local: true})
62 {:ok, _user2} = User.set_activation(user2, false)
64 insert(:user, %{local: false, nickname: "u@peer1.com"})
65 insert(:user, %{local: false, nickname: "u@peer2.com"})
67 {:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
69 Pleroma.Stats.force_update()
71 conn = get(conn, "/api/v1/instance")
73 assert result = json_response_and_validate_schema(conn, 200)
75 stats = result["stats"]
78 assert stats["user_count"] == 1
79 assert stats["status_count"] == 1
80 assert stats["domain_count"] == 2
83 test "get peers", %{conn: conn} do
84 insert(:user, %{local: false, nickname: "u@peer1.com"})
85 insert(:user, %{local: false, nickname: "u@peer2.com"})
87 Pleroma.Stats.force_update()
89 conn = get(conn, "/api/v1/instance/peers")
91 assert result = json_response_and_validate_schema(conn, 200)
93 assert ["peer1.com", "peer2.com"] == Enum.sort(result)
96 test "instance languages", %{conn: conn} do
97 assert %{"languages" => ["en"]} =
99 |> get("/api/v1/instance")
100 |> json_response_and_validate_schema(200)
102 clear_config([:instance, :languages], ["aa", "bb"])
104 assert %{"languages" => ["aa", "bb"]} =
106 |> get("/api/v1/instance")
107 |> json_response_and_validate_schema(200)
110 test "get instance contact information", %{conn: conn} do
111 user = insert(:user, %{local: true})
113 clear_config([:instance, :contact_username], user.nickname)
115 conn = get(conn, "/api/v1/instance")
117 assert result = json_response_and_validate_schema(conn, 200)
119 assert result["contact_account"]["id"] == user.id
122 test "get instance information v2", %{conn: conn} do
123 clear_config([:auth, :oauth_consumer_strategies], [])
125 assert get(conn, "/api/v2/instance")
126 |> json_response_and_validate_schema(200)