InstanceView: removing unneeded doubling of attributes in tests

This commit is contained in:
Phantasm 2026-06-25 23:21:09 +02:00
commit 6393fe0a9e
No known key found for this signature in database
GPG key ID: 2669E588BCC634C8

View file

@ -13,74 +13,71 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
import Mox import Mox
@atom_common_information_keys [ @common_information_keys [
:languages, :languages,
:rules, :rules,
:title, :title,
:version :version
] ]
@common_information_keys Enum.map(@atom_common_information_keys, &to_string/1) @configuration_keys [
@atom_configuration_keys [
:accounts, :accounts,
:statuses, :statuses,
:media_attachments, :media_attachments,
:polls :polls
] ]
@atom_configuration2_keys @atom_configuration_keys ++ [ @configuration2_keys @configuration_keys ++ [
:urls, :urls,
:vapid, :vapid,
:translation, :translation,
:timelines_access :timelines_access
] ]
@atom_pleroma_configuration_keys [ @pleroma_configuration_keys [
:metadata, :metadata,
:stats, :stats,
:vapid_public_key :vapid_public_key
] ]
# TODO: Simplify this, so ideally only atoms are macroed
@show_keys @common_information_keys ++ [ @show_keys @common_information_keys ++ [
"uri", :uri,
"description", :description,
"short_description", :short_description,
"email", :email,
"urls", :urls,
"stats", :stats,
"thumbnail", :thumbnail,
"registrations", :registrations,
"approval_required", :approval_required,
"contact_account", :contact_account,
"configuration", :configuration,
# Extra (not present in Mastodon)" # Extra (not present in Mastodon)
"max_toot_chars", :max_toot_chars,
"max_media_attachments", :max_media_attachments,
"poll_limits", :poll_limits,
"upload_limit", :upload_limit,
"avatar_upload_limit", :avatar_upload_limit,
"background_upload_limit", :background_upload_limit,
"banner_upload_limit", :banner_upload_limit,
"background_image", :background_image,
"shout_limit", :shout_limit,
"description_limit", :description_limit,
"chat_limit", :chat_limit,
"pleroma" :pleroma
] ]
@show2_keys @common_information_keys ++ [ @show2_keys @common_information_keys ++ [
"domain", :domain,
"source_url", :source_url,
"description", :description,
"usage", :usage,
"thumbnail", :thumbnail,
"configuration", :configuration,
"registrations", :registrations,
"contact", :contact,
# Extra (not present in Mastodon): # Extra (not present in Mastodon)
"pleroma" :pleroma
] ]
@features [ @features [
@ -106,7 +103,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
"pleroma:block_expiration" "pleroma:block_expiration"
] ]
@configureable_features [ @configurable_features [
"blockers_visible", "blockers_visible",
"media_proxy", "media_proxy",
"gopher", "gopher",
@ -130,7 +127,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
] ]
defp check_common_information(info) do defp check_common_information(info) do
filtered_info = Map.reject(info, fn {key, _value} -> key not in @atom_common_information_keys end) filtered_info = Map.reject(info, fn {key, _value} -> key not in @common_information_keys end)
expected = %{ expected = %{
languages: ["en", "cs"], languages: ["en", "cs"],
@ -172,7 +169,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
defp check_configuration(info) do defp check_configuration(info) do
configuration = info[:configuration] configuration = info[:configuration]
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @atom_configuration_keys end) filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @configuration_keys end)
expected = %{ expected = %{
accounts: %{ accounts: %{
@ -200,7 +197,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
defp check_configuration2(info) do defp check_configuration2(info) do
configuration = info[:configuration] configuration = info[:configuration]
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @atom_configuration2_keys end) filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @configuration2_keys end)
# configuration2 also includes parts from configuration # configuration2 also includes parts from configuration
expected = %{ expected = %{
@ -264,7 +261,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
defp check_pleroma_configuration(info) do defp check_pleroma_configuration(info) do
configuration = info[:pleroma] configuration = info[:pleroma]
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @atom_pleroma_configuration_keys end) filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @pleroma_configuration_keys end)
metadata = Map.fetch!(filtered_configuration, :metadata) metadata = Map.fetch!(filtered_configuration, :metadata)
# Tested elsewhere already # Tested elsewhere already
filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end) filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
@ -306,7 +303,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
defp check_pleroma_configuration2(info) do defp check_pleroma_configuration2(info) do
configuration = info[:pleroma] configuration = info[:pleroma]
filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @atom_pleroma_configuration_keys end) filtered_configuration = Map.reject(configuration, fn {key, _value} -> key not in @pleroma_configuration_keys end)
metadata = Map.fetch!(filtered_configuration, :metadata) metadata = Map.fetch!(filtered_configuration, :metadata)
# Tested elsewhere already # Tested elsewhere already
filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end) filtered_metadata = Map.reject(metadata, fn {key, _value} -> key in [:features, :federation] end)
@ -385,7 +382,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
end end
test "returns all features including configurable ones" do test "returns all features including configurable ones" do
features = @features ++ @configureable_features features = @features ++ @configurable_features
assert Enum.sort(InstanceView.features()) == Enum.sort(features) assert Enum.sort(InstanceView.features()) == Enum.sort(features)
end end
@ -529,7 +526,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
assert check_contact_name(output, user) assert check_contact_name(output, user)
assert check_configuration(output) assert check_configuration(output)
assert check_pleroma_configuration(output) assert check_pleroma_configuration(output)
assert expected_keys == Enum.sort(Enum.map(Map.keys(output), &to_string/1)) assert expected_keys == Enum.sort(Map.keys(output))
end end
test "renders show2.json properly", %{user: user} do test "renders show2.json properly", %{user: user} do
@ -542,7 +539,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceViewTest do
assert check_registrations(output) assert check_registrations(output)
assert check_contact(output, user) assert check_contact(output, user)
assert check_pleroma_configuration2(output) assert check_pleroma_configuration2(output)
assert expected_keys == Enum.sort(Enum.map(Map.keys(output), &to_string/1)) assert expected_keys == Enum.sort(Map.keys(output))
end end
end end