Add tests for fetch_follow_information_for_user and check object type

when fetching the page
This commit is contained in:
rinpatch 2019-07-14 00:56:02 +03:00
parent d06d1b751d
commit 183da33e00
2 changed files with 83 additions and 1 deletions

View File

@ -1063,7 +1063,8 @@ defp collection_private(data) do
data["first"]["type"] in ["CollectionPage", "OrderedCollectionPage"] do
{:ok, false}
else
with {:ok, _data} <- Fetcher.fetch_and_contain_remote_object_from_id(data["first"]) do
with {:ok, %{"type" => type}} when type in ["CollectionPage", "OrderedCollectionPage"] <-
Fetcher.fetch_and_contain_remote_object_from_id(data["first"]) do
{:ok, false}
else
{:error, {:ok, %{status: code}}} when code in [401, 403] ->

View File

@ -1222,4 +1222,85 @@ test "fetches only public posts for other users" do
assert result.id == activity.id
end
end
describe "fetch_follow_information_for_user" do
test "syncronizes following/followers counters" do
user =
insert(:user,
local: false,
follower_address: "http://localhost:4001/users/fuser2/followers",
following_address: "http://localhost:4001/users/fuser2/following"
)
{:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
assert user.info.follower_count == 527
assert user.info.following_count == 267
end
test "detects hidden followers" do
mock(fn env ->
case env.url do
"http://localhost:4001/users/masto_closed/followers?page=1" ->
%Tesla.Env{status: 403, body: ""}
"http://localhost:4001/users/masto_closed/following?page=1" ->
%Tesla.Env{
status: 200,
body:
Jason.encode!(%{
"id" => "http://localhost:4001/users/masto_closed/following?page=1",
"type" => "OrderedCollectionPage"
})
}
_ ->
apply(HttpRequestMock, :request, [env])
end
end)
user =
insert(:user,
local: false,
follower_address: "http://localhost:4001/users/masto_closed/followers",
following_address: "http://localhost:4001/users/masto_closed/following"
)
{:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
assert user.info.hide_followers == true
assert user.info.hide_follows == false
end
test "detects hidden follows" do
mock(fn env ->
case env.url do
"http://localhost:4001/users/masto_closed/following?page=1" ->
%Tesla.Env{status: 403, body: ""}
"http://localhost:4001/users/masto_closed/followers?page=1" ->
%Tesla.Env{
status: 200,
body:
Jason.encode!(%{
"id" => "http://localhost:4001/users/masto_closed/followers?page=1",
"type" => "OrderedCollectionPage"
})
}
_ ->
apply(HttpRequestMock, :request, [env])
end
end)
user =
insert(:user,
local: false,
follower_address: "http://localhost:4001/users/masto_closed/followers",
following_address: "http://localhost:4001/users/masto_closed/following"
)
{:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
assert user.info.hide_followers == false
assert user.info.hide_follows == true
end
end
end