X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fmastodon_api%2Fviews%2Faccount_view_test.exs;h=c9036d67d225165ddde7bc08572412c3be162b0d;hb=0cfd5b4e89b02688342345755577e58eece3db0f;hp=5373a17c38f84a0db34a20ef213e0812daadd7b3;hpb=8d2ea9540220178098762c103ab4fad7a8bd2edd;p=akkoma
diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs
index 5373a17c3..c9036d67d 100644
--- a/test/pleroma/web/mastodon_api/views/account_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: false
alias Pleroma.User
alias Pleroma.UserRelationship
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
import Pleroma.Factory
import Tesla.Mock
+ import Mock
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -25,6 +26,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,
@@ -35,9 +37,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
inserted_at: ~N[2017-08-15 15:47:06.597036],
emoji: %{"karjalanpiirakka" => "/file.png"},
raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"",
- also_known_as: ["https://shitposter.zone/users/shp"]
+ also_known_as: ["https://shitposter.zone/users/shp"],
+ status_ttl_days: 5
})
+ insert(:instance, %{host: "example.com", nodeinfo: %{version: "2.1"}})
+
expected = %{
id: to_string(user.id),
username: "shp",
@@ -50,6 +55,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
statuses_count: 5,
note: "valid html. a
b
c
d
f '&<>"",
url: user.ap_id,
+ akkoma: %{
+ instance: %{
+ name: "example.com",
+ nodeinfo: %{
+ "version" => "2.1"
+ },
+ favicon: nil
+ },
+ status_ttl_days: 5
+ },
avatar: "http://localhost:4001/images/avi.png",
avatar_static: "http://localhost:4001/images/avi.png",
header: "http://localhost:4001/images/banner.png",
@@ -74,6 +89,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
fields: []
},
fqn: "shp@shitposter.club",
+ last_status_at: nil,
pleroma: %{
ap_id: user.ap_id,
also_known_as: ["https://shitposter.zone/users/shp"],
@@ -83,23 +99,71 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
tags: [],
is_admin: false,
is_moderator: false,
+ is_suggested: false,
hide_favorites: true,
hide_followers: false,
hide_follows: false,
hide_followers_count: false,
hide_follows_count: false,
relationship: %{},
- skip_thread_containment: false,
- accepts_chat_messages: nil
+ skip_thread_containment: false
}
}
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
end
+ describe "nodeinfo" do
+ setup do
+ [
+ user: insert(:user, ap_id: "https://somewhere.example.com/users/chikichikibanban"),
+ instance:
+ insert(:instance, %{
+ host: "somewhere.example.com",
+ favicon: "https://example.com/favicon.ico"
+ })
+ ]
+ end
+
+ test "is embedded in the account view", %{user: user} do
+ assert %{
+ akkoma: %{
+ instance: %{
+ name: "somewhere.example.com",
+ nodeinfo: %{
+ "version" => "2.0"
+ },
+ favicon: "https://example.com/favicon.ico"
+ }
+ }
+ } = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+ end
+
+ test "uses local nodeinfo for local users" do
+ user = insert(:user)
+
+ assert %{
+ akkoma: %{
+ instance: %{
+ name: "localhost",
+ nodeinfo: %{
+ software: %{
+ name: "akkoma"
+ }
+ }
+ }
+ }
+ } = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+ end
+ end
+
describe "favicon" do
setup do
- [user: insert(:user)]
+ [
+ user: insert(:user, ap_id: "https://example.com/users/chikichikibanban"),
+ instance:
+ insert(:instance, %{host: "example.com", favicon: "https://example.com/favicon.ico"})
+ ]
end
test "is parsed when :instance_favicons is enabled", %{user: user} do
@@ -107,13 +171,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
assert %{
pleroma: %{
- favicon:
- "https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png"
+ favicon: "https://example.com/favicon.ico"
}
} = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
end
- test "is nil when :instances_favicons is disabled", %{user: user} do
+ test "is nil when we have no instance", %{user: user} do
+ user = %{user | ap_id: "https://wowee.example.com/users/2"}
+
assert %{pleroma: %{favicon: nil}} =
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
end
@@ -174,27 +239,42 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
fields: []
},
fqn: "shp@shitposter.club",
+ last_status_at: nil,
+ akkoma: %{
+ instance: %{
+ name: "localhost",
+ favicon: "http://localhost:4001/favicon.png",
+ nodeinfo: %{version: "2.0"}
+ },
+ status_ttl_days: nil
+ },
pleroma: %{
ap_id: user.ap_id,
also_known_as: [],
background_image: nil,
- favicon: nil,
+ favicon: "http://localhost:4001/favicon.png",
is_confirmed: true,
tags: [],
is_admin: false,
is_moderator: false,
+ is_suggested: false,
hide_favorites: true,
hide_followers: false,
hide_follows: false,
hide_followers_count: false,
hide_follows_count: false,
relationship: %{},
- skip_thread_containment: false,
- accepts_chat_messages: nil
+ skip_thread_containment: false
}
}
- assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+ with_mock(
+ Pleroma.Web.Nodeinfo.NodeinfoController,
+ raw_nodeinfo: fn -> %{version: "2.0"} end
+ ) do
+ assert expected ==
+ AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+ end
end
test "Represent a Funkwhale channel" do
@@ -268,10 +348,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
muting: false,
muting_notifications: false,
subscribing: false,
+ notifying: false,
requested: false,
+ requested_by: false,
domain_blocking: false,
showing_reblogs: true,
- endorsed: false
+ endorsed: false,
+ note: ""
}
test "represent a relationship for the following and followed user" do
@@ -293,6 +376,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
muting: true,
muting_notifications: true,
subscribing: true,
+ notifying: true,
showing_reblogs: false,
id: to_string(other_user.id)
}
@@ -352,6 +436,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
end
end
+ test "represent a relationship for a user with an inbound pending follow request" do
+ follower = insert(:user)
+ followed = insert(:user, is_locked: true)
+
+ {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
+
+ follower = User.get_cached_by_id(follower.id)
+ followed = User.get_cached_by_id(followed.id)
+
+ expected =
+ Map.merge(
+ @blank_response,
+ %{requested_by: true, followed_by: false, id: to_string(follower.id)}
+ )
+
+ test_relationship_rendering(followed, follower, expected)
+ end
+
test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
user = insert(:user, pleroma_settings_store: %{fe: "test"})
@@ -468,6 +570,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
%{user: user, for: user}
)[:pleroma][:unread_notifications_count] == 7
end
+
+ test "shows email only to the account owner" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert AccountView.render(
+ "show.json",
+ %{user: user, for: other_user}
+ )[:pleroma][:email] == nil
+
+ assert AccountView.render(
+ "show.json",
+ %{user: user, for: user}
+ )[:pleroma][:email] == user.email
+ end
end
describe "follow requests counter" do
@@ -556,18 +675,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
emoji: %{"joker_smile" => "https://evil.website/society.png"}
)
+ insert(:instance, %{host: "localhost", favicon: "https://evil.website/favicon.png"})
+
with media_preview_enabled <- [false, true] do
clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|> Enum.all?(fn
{key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
- String.starts_with?(url, Pleroma.Web.base_url())
+ String.starts_with?(url, Pleroma.Web.Endpoint.url())
+
+ {:akkoma, %{instance: %{favicon: favicon_url}}} ->
+ String.starts_with?(favicon_url, Pleroma.Web.Endpoint.url())
{:emojis, emojis} ->
Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
- String.starts_with?(url, Pleroma.Web.base_url()) &&
- String.starts_with?(static_url, Pleroma.Web.base_url())
+ String.starts_with?(url, Pleroma.Web.Endpoint.url()) &&
+ String.starts_with?(static_url, Pleroma.Web.Endpoint.url())
end)
_ ->
@@ -576,4 +700,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, ap_id: "https://example.com/users/1")
+ view = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+ assert view[:akkoma][:instance] == nil
+ end
end