add instance rendering test

This commit is contained in:
FloatingGhost 2022-11-04 04:35:02 +00:00
parent 3d52295727
commit c7cdc00af8
2 changed files with 27 additions and 7 deletions

View File

@ -25,6 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user =
insert(:user, %{
ap_id: "https://example.com/users/chikichikibanban",
follower_count: 3,
note_count: 5,
background: background_image,
@ -38,6 +39,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
also_known_as: ["https://shitposter.zone/users/shp"]
})
insert(:instance, %{host: "example.com", nodeinfo: %{version: "2.1"}})
expected = %{
id: to_string(user.id),
username: "shp",
@ -50,6 +53,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
statuses_count: 5,
note: "<span>valid html</span>. a<br/>b<br/>c<br/>d<br/>f &#39;&amp;&lt;&gt;&quot;",
url: user.ap_id,
akkoma: %{
instance: %{
name: "example.com",
nodeinfo: %{
"version" => "2.1"
},
favicon: nil
}
},
avatar: "http://localhost:4001/images/avi.png",
avatar_static: "http://localhost:4001/images/avi.png",
header: "http://localhost:4001/images/banner.png",
@ -598,4 +610,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|> assert()
end
end
test "returns nil in the instance field when no instance is held locally" do
user = insert(:user)
view = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
assert view[:akkoma][:instance] == nil
end
end

View File

@ -36,6 +36,15 @@ defmodule Pleroma.Factory do
}
end
def instance_factory(attrs \\ %{}) do
%Pleroma.Instances.Instance{
host: attrs[:domain] || "example.com",
nodeinfo: %{version: "2.0", openRegistrations: true},
unreachable_since: nil
}
|> Map.merge(attrs)
end
def user_factory(attrs \\ %{}) do
pem = Enum.random(@rsa_keys)
@ -522,13 +531,6 @@ defmodule Pleroma.Factory do
}
end
def instance_factory do
%Pleroma.Instances.Instance{
host: "domain.com",
unreachable_since: nil
}
end
def oauth_token_factory(attrs \\ %{}) do
scopes = Map.get(attrs, :scopes, ["read"])
oauth_app = Map.get_lazy(attrs, :app, fn -> insert(:oauth_app, scopes: scopes) end)