2019-10-02 01:13:52 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-10-02 01:13:52 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
2020-12-21 07:05:56 -07:00
|
|
|
# TODO: Should not need Cachex
|
2019-10-02 01:13:52 -06:00
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "get instance information", %{conn: conn} do
|
|
|
|
conn = get(conn, "/api/v1/instance")
|
2020-05-05 07:24:16 -06:00
|
|
|
assert result = json_response_and_validate_schema(conn, 200)
|
2019-10-02 01:13:52 -06:00
|
|
|
|
|
|
|
email = Pleroma.Config.get([:instance, :email])
|
2021-05-31 14:09:11 -06:00
|
|
|
thumbnail = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :instance_thumbnail])
|
|
|
|
background = Pleroma.Web.Endpoint.url() <> Pleroma.Config.get([:instance, :background_image])
|
2020-11-16 14:29:15 -07:00
|
|
|
|
2019-10-02 01:13:52 -06:00
|
|
|
# Note: not checking for "max_toot_chars" since it's optional
|
|
|
|
assert %{
|
|
|
|
"uri" => _,
|
|
|
|
"title" => _,
|
|
|
|
"description" => _,
|
2022-07-12 22:40:46 -06:00
|
|
|
"short_description" => _,
|
2019-10-02 01:13:52 -06:00
|
|
|
"version" => _,
|
|
|
|
"email" => from_config_email,
|
|
|
|
"urls" => %{
|
|
|
|
"streaming_api" => _
|
|
|
|
},
|
|
|
|
"stats" => _,
|
2020-11-16 14:29:15 -07:00
|
|
|
"thumbnail" => from_config_thumbnail,
|
2019-10-02 01:13:52 -06:00
|
|
|
"languages" => _,
|
|
|
|
"registrations" => _,
|
2020-07-15 16:04:30 -06:00
|
|
|
"approval_required" => _,
|
2019-10-02 01:13:52 -06:00
|
|
|
"poll_limits" => _,
|
|
|
|
"upload_limit" => _,
|
|
|
|
"avatar_upload_limit" => _,
|
|
|
|
"background_upload_limit" => _,
|
2020-05-18 05:28:50 -06:00
|
|
|
"banner_upload_limit" => _,
|
2020-11-16 14:29:15 -07:00
|
|
|
"background_image" => from_config_background,
|
2020-08-03 16:08:35 -06:00
|
|
|
"shout_limit" => _,
|
2020-07-06 03:12:37 -06:00
|
|
|
"description_limit" => _
|
2019-10-02 01:13:52 -06:00
|
|
|
} = result
|
|
|
|
|
2020-06-30 14:25:10 -06:00
|
|
|
assert result["pleroma"]["metadata"]["account_activation_required"] != nil
|
2020-04-27 06:28:08 -06:00
|
|
|
assert result["pleroma"]["metadata"]["features"]
|
|
|
|
assert result["pleroma"]["metadata"]["federation"]
|
2020-06-30 14:25:10 -06:00
|
|
|
assert result["pleroma"]["metadata"]["fields_limits"]
|
2020-04-27 06:28:08 -06:00
|
|
|
assert result["pleroma"]["vapid_public_key"]
|
2021-01-27 07:18:46 -07:00
|
|
|
assert result["pleroma"]["stats"]["mau"] == 0
|
2020-04-27 06:28:08 -06:00
|
|
|
|
2019-10-02 01:13:52 -06:00
|
|
|
assert email == from_config_email
|
2020-11-16 14:29:15 -07:00
|
|
|
assert thumbnail == from_config_thumbnail
|
|
|
|
assert background == from_config_background
|
2019-10-02 01:13:52 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "get instance stats", %{conn: conn} do
|
|
|
|
user = insert(:user, %{local: true})
|
|
|
|
|
|
|
|
user2 = insert(:user, %{local: true})
|
2020-10-13 16:16:03 -06:00
|
|
|
{:ok, _user2} = User.set_activation(user2, false)
|
2019-10-02 01:13:52 -06:00
|
|
|
|
|
|
|
insert(:user, %{local: false, nickname: "u@peer1.com"})
|
|
|
|
insert(:user, %{local: false, nickname: "u@peer2.com"})
|
|
|
|
|
2020-05-12 13:59:26 -06:00
|
|
|
{:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
|
2019-10-02 01:13:52 -06:00
|
|
|
|
|
|
|
Pleroma.Stats.force_update()
|
|
|
|
|
|
|
|
conn = get(conn, "/api/v1/instance")
|
|
|
|
|
2020-05-05 07:24:16 -06:00
|
|
|
assert result = json_response_and_validate_schema(conn, 200)
|
2019-10-02 01:13:52 -06:00
|
|
|
|
|
|
|
stats = result["stats"]
|
|
|
|
|
|
|
|
assert stats
|
|
|
|
assert stats["user_count"] == 1
|
2019-12-21 04:41:19 -07:00
|
|
|
assert stats["status_count"] == 1
|
2019-10-02 01:13:52 -06:00
|
|
|
assert stats["domain_count"] == 2
|
|
|
|
end
|
|
|
|
|
|
|
|
test "get peers", %{conn: conn} do
|
|
|
|
insert(:user, %{local: false, nickname: "u@peer1.com"})
|
|
|
|
insert(:user, %{local: false, nickname: "u@peer2.com"})
|
|
|
|
|
|
|
|
Pleroma.Stats.force_update()
|
|
|
|
|
|
|
|
conn = get(conn, "/api/v1/instance/peers")
|
|
|
|
|
2020-05-05 07:24:16 -06:00
|
|
|
assert result = json_response_and_validate_schema(conn, 200)
|
2019-10-02 01:13:52 -06:00
|
|
|
|
|
|
|
assert ["peer1.com", "peer2.com"] == Enum.sort(result)
|
|
|
|
end
|
2023-01-26 18:17:13 -07:00
|
|
|
|
|
|
|
test "instance languages", %{conn: conn} do
|
|
|
|
assert %{"languages" => ["en"]} =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/instance")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
|
|
|
|
clear_config([:instance, :languages], ["aa", "bb"])
|
|
|
|
|
|
|
|
assert %{"languages" => ["aa", "bb"]} =
|
|
|
|
conn
|
|
|
|
|> get("/api/v1/instance")
|
|
|
|
|> json_response_and_validate_schema(200)
|
|
|
|
end
|
2019-10-02 01:13:52 -06:00
|
|
|
end
|