InstanceView: Add show.json render test
This commit is contained in:
parent
e45dad2104
commit
c290f022de
2 changed files with 196 additions and 0 deletions
|
|
@ -5,12 +5,63 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Language.LanguageDetectorMock
|
||||
alias Pleroma.StaticStubbedConfigMock
|
||||
alias Pleroma.Web.MastodonAPI.InstanceView
|
||||
|
||||
import Mox
|
||||
|
||||
@atom_common_information_keys [
|
||||
:languages,
|
||||
:rules,
|
||||
:title,
|
||||
:version
|
||||
]
|
||||
|
||||
@common_information_keys Enum.map(@atom_common_information_keys, &to_string/1)
|
||||
|
||||
@atom_configuration_keys [
|
||||
:accounts,
|
||||
:statuses,
|
||||
:media_attachments,
|
||||
:polls
|
||||
]
|
||||
|
||||
@atom_pleroma_configuration_keys [
|
||||
:metadata,
|
||||
:stats,
|
||||
:vapid_public_key
|
||||
]
|
||||
|
||||
@show_keys @common_information_keys ++ [
|
||||
"uri",
|
||||
"description",
|
||||
"short_description",
|
||||
"email",
|
||||
"urls",
|
||||
"stats",
|
||||
"thumbnail",
|
||||
"registrations",
|
||||
"approval_required",
|
||||
"contact_account",
|
||||
"configuration",
|
||||
# Extra (not present in Mastodon)"
|
||||
"max_toot_chars",
|
||||
"max_media_attachments",
|
||||
"poll_limits",
|
||||
"upload_limit",
|
||||
"avatar_upload_limit",
|
||||
"background_upload_limit",
|
||||
"banner_upload_limit",
|
||||
"background_image",
|
||||
"shout_limit",
|
||||
"description_limit",
|
||||
"chat_limit",
|
||||
"pleroma"
|
||||
]
|
||||
|
||||
@features [
|
||||
"pleroma_api",
|
||||
"mastodon_api",
|
||||
|
|
@ -57,6 +108,96 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
|||
[:instance, :profile_directory]
|
||||
]
|
||||
|
||||
defp check_common_information(info) do
|
||||
filtered_info = Map.reject(info, fn {key, _value} -> key not in @atom_common_information_keys end)
|
||||
|
||||
expected = %{
|
||||
languages: ["en", "cs"],
|
||||
rules: InstanceView.render("rules.json", %{}),
|
||||
title: "test title",
|
||||
version: InstanceView.mastodon_api_level() <> " (compatible; #{Pleroma.Application.named_version()})"
|
||||
}
|
||||
|
||||
Map.equal?(expected, filtered_info)
|
||||
end
|
||||
|
||||
defp check_contact_name(info, user) do
|
||||
contact = info[:contact_account]
|
||||
view = Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user, for: nil})
|
||||
|
||||
contact == view
|
||||
end
|
||||
|
||||
defp check_configuration(info) do
|
||||
configuration = info[:configuration]
|
||||
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @atom_configuration_keys end)
|
||||
|
||||
expected = %{
|
||||
accounts: %{
|
||||
max_featured_tags: 0
|
||||
},
|
||||
statuses: %{
|
||||
max_characters: 4096,
|
||||
max_media_attachments: 1
|
||||
},
|
||||
media_attachments: %{
|
||||
image_size_limit: 1024,
|
||||
video_size_limit: 1024,
|
||||
supported_mime_types: ["application/octet-stream"]
|
||||
},
|
||||
polls: %{
|
||||
max_options: 4,
|
||||
max_characters_per_option: 120,
|
||||
min_expiration: 1,
|
||||
max_expiration: 2
|
||||
}
|
||||
}
|
||||
|
||||
Map.equal?(expected, filtered_configuration)
|
||||
end
|
||||
|
||||
defp check_pleroma_configuration(info) do
|
||||
configuration = info[:pleroma]
|
||||
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @atom_pleroma_configuration_keys end)
|
||||
metadata = Map.fetch!(filtered_configuration, :metadata)
|
||||
# Tested elsewhere already
|
||||
filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
|
||||
filtered_configuration = %{filtered_configuration | metadata: filtered_metadata}
|
||||
|
||||
expected = %{
|
||||
metadata: %{
|
||||
account_activation_required: true,
|
||||
fields_limits: %{
|
||||
max_fields: 1,
|
||||
max_remote_fields: 1,
|
||||
name_length: 1,
|
||||
value_length: 1
|
||||
},
|
||||
post_formats: ["text/plain"],
|
||||
birthday_required: true,
|
||||
birthday_min_age: 1,
|
||||
translation:
|
||||
%{
|
||||
source_languages: ["en", "pl"],
|
||||
target_languages: ["en", "pl"]
|
||||
},
|
||||
base_urls: %{
|
||||
media_proxy: "https://mediaproxy.example.com",
|
||||
upload: "https://upload.example.com"
|
||||
},
|
||||
markup: %{
|
||||
allow_inline_images: true,
|
||||
allow_headings: true,
|
||||
allow_tables: true
|
||||
}
|
||||
},
|
||||
stats: %{mau: Pleroma.User.active_user_count()},
|
||||
vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
|
||||
}
|
||||
|
||||
Map.equal?(expected, filtered_configuration)
|
||||
end
|
||||
|
||||
# When this fails, a new feature flag was probably added. Add it to the macros above.
|
||||
describe "uncofigurable features" do
|
||||
setup do: Enum.each(@configurable_features_flags, &clear_config(&1, false))
|
||||
|
|
@ -162,6 +303,59 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "render show.json" do
|
||||
setup do
|
||||
Pleroma.Rule.create(%{text: "rule 1"})
|
||||
Pleroma.Rule.create(%{text: "rule 2"})
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
# Wall of configs for testing whether they are rendered properly
|
||||
clear_config([Pleroma.Language.Translation, :provider], TranslationMock)
|
||||
|
||||
clear_config([:instance, :languages], ["en", "cs"])
|
||||
clear_config([:instance, :name], "test title")
|
||||
clear_config([:instance, :contact_username], user.nickname)
|
||||
clear_config([:instance, :limit], 4096)
|
||||
clear_config([:instance, :max_media_attachments], 1)
|
||||
clear_config([:instance, :upload_limit], 1024)
|
||||
clear_config([:instance, :poll_limits, :max_options], 4)
|
||||
clear_config([:instance, :poll_limits, :max_option_chars], 120)
|
||||
clear_config([:instance, :poll_limits, :min_expiration], 1)
|
||||
clear_config([:instance, :poll_limits, :max_expiration], 2)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :max_account_fields], 1)
|
||||
clear_config([:instance, :max_remote_account_fields], 1)
|
||||
clear_config([:instance, :account_field_name_length], 1)
|
||||
clear_config([:instance, :account_field_value_length], 1)
|
||||
clear_config([:instance, :allowed_post_formats], ["text/plain"])
|
||||
clear_config([:instance, :birthday_required], true)
|
||||
clear_config([:instance, :birthday_min_age], 1)
|
||||
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([:media_proxy, :base_url], "https://mediaproxy.example.com")
|
||||
|
||||
clear_config([Pleroma.Upload, :base_url], "https://upload.example.com")
|
||||
|
||||
clear_config([:markup, :allow_inline_images], true)
|
||||
clear_config([:markup, :allow_headings], true)
|
||||
clear_config([:markup, :allow_tables], true)
|
||||
|
||||
%{user: user}
|
||||
end
|
||||
|
||||
test "renders properly", %{user: user} do
|
||||
output = InstanceView.render("show.json", %{})
|
||||
expected_keys = Enum.sort(@show_keys)
|
||||
|
||||
assert check_common_information(output)
|
||||
assert check_contact_name(output, user)
|
||||
assert check_configuration(output)
|
||||
assert check_pleroma_configuration(output)
|
||||
assert expected_keys == Enum.sort(Enum.map(Map.keys(output), &to_string/1))
|
||||
end
|
||||
end
|
||||
|
||||
describe "render rule.json" do
|
||||
setup do
|
||||
rule = Pleroma.Rule.create(%{text: "hambaga"})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue