2019-10-02 03:13:52 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 17:44:49 -05:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-10-02 03:13:52 -04:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|
|
|
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 09:24:16 -04:00
|
|
|
assert result = json_response_and_validate_schema(conn, 200)
|
2019-10-02 03:13:52 -04:00
|
|
|
|
|
|
|
email = Pleroma.Config.get([:instance, :email])
|
|
|
|
# Note: not checking for "max_toot_chars" since it's optional
|
|
|
|
assert %{
|
|
|
|
"uri" => _,
|
|
|
|
"title" => _,
|
|
|
|
"description" => _,
|
|
|
|
"version" => _,
|
|
|
|
"email" => from_config_email,
|
|
|
|
"urls" => %{
|
|
|
|
"streaming_api" => _
|
|
|
|
},
|
|
|
|
"stats" => _,
|
|
|
|
"thumbnail" => _,
|
|
|
|
"languages" => _,
|
|
|
|
"registrations" => _,
|
|
|
|
"poll_limits" => _,
|
|
|
|
"upload_limit" => _,
|
|
|
|
"avatar_upload_limit" => _,
|
|
|
|
"background_upload_limit" => _,
|
2020-05-18 07:28:50 -04:00
|
|
|
"banner_upload_limit" => _,
|
2020-07-06 05:12:37 -04:00
|
|
|
"background_image" => _,
|
|
|
|
"chat_limit" => _,
|
|
|
|
"description_limit" => _
|
2019-10-02 03:13:52 -04:00
|
|
|
} = result
|
|
|
|
|
2020-06-30 16:25:10 -04:00
|
|
|
assert result["pleroma"]["metadata"]["account_activation_required"] != nil
|
2020-04-27 08:28:08 -04:00
|
|
|
assert result["pleroma"]["metadata"]["features"]
|
|
|
|
assert result["pleroma"]["metadata"]["federation"]
|
2020-06-30 16:25:10 -04:00
|
|
|
assert result["pleroma"]["metadata"]["fields_limits"]
|
2020-04-27 08:28:08 -04:00
|
|
|
assert result["pleroma"]["vapid_public_key"]
|
|
|
|
|
2019-10-02 03:13:52 -04:00
|
|
|
assert email == from_config_email
|
|
|
|
end
|
|
|
|
|
|
|
|
test "get instance stats", %{conn: conn} do
|
|
|
|
user = insert(:user, %{local: true})
|
|
|
|
|
|
|
|
user2 = insert(:user, %{local: true})
|
2019-10-16 14:59:21 -04:00
|
|
|
{:ok, _user2} = User.deactivate(user2, !user2.deactivated)
|
2019-10-02 03:13:52 -04:00
|
|
|
|
|
|
|
insert(:user, %{local: false, nickname: "u@peer1.com"})
|
|
|
|
insert(:user, %{local: false, nickname: "u@peer2.com"})
|
|
|
|
|
2020-05-12 15:59:26 -04:00
|
|
|
{:ok, _} = Pleroma.Web.CommonAPI.post(user, %{status: "cofe"})
|
2019-10-02 03:13:52 -04:00
|
|
|
|
|
|
|
Pleroma.Stats.force_update()
|
|
|
|
|
|
|
|
conn = get(conn, "/api/v1/instance")
|
|
|
|
|
2020-05-05 09:24:16 -04:00
|
|
|
assert result = json_response_and_validate_schema(conn, 200)
|
2019-10-02 03:13:52 -04:00
|
|
|
|
|
|
|
stats = result["stats"]
|
|
|
|
|
|
|
|
assert stats
|
|
|
|
assert stats["user_count"] == 1
|
2019-12-21 06:41:19 -05:00
|
|
|
assert stats["status_count"] == 1
|
2019-10-02 03:13:52 -04: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 09:24:16 -04:00
|
|
|
assert result = json_response_and_validate_schema(conn, 200)
|
2019-10-02 03:13:52 -04:00
|
|
|
|
|
|
|
assert ["peer1.com", "peer2.com"] == Enum.sort(result)
|
|
|
|
end
|
|
|
|
end
|