Merge remote-tracking branch 'remotes/upstream/develop' into 1335-user-api-id-fields-relations
# Conflicts: # lib/pleroma/user/search.ex # test/user_test.exs
This commit is contained in:
commit
cad9b325e5
11 changed files with 185 additions and 58 deletions
47
test/following_relationship_test.exs
Normal file
47
test/following_relationship_test.exs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FollowingRelationshipTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.FollowingRelationship
|
||||
alias Pleroma.Web.ActivityPub.InternalFetchActor
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "following/1" do
|
||||
test "returns following addresses without internal.fetch" do
|
||||
user = insert(:user)
|
||||
fetch_actor = InternalFetchActor.get_actor()
|
||||
FollowingRelationship.follow(fetch_actor, user, "accept")
|
||||
assert FollowingRelationship.following(fetch_actor) == [user.follower_address]
|
||||
end
|
||||
|
||||
test "returns following addresses without relay" do
|
||||
user = insert(:user)
|
||||
relay_actor = Relay.get_actor()
|
||||
FollowingRelationship.follow(relay_actor, user, "accept")
|
||||
assert FollowingRelationship.following(relay_actor) == [user.follower_address]
|
||||
end
|
||||
|
||||
test "returns following addresses without remote user" do
|
||||
user = insert(:user)
|
||||
actor = insert(:user, local: false)
|
||||
FollowingRelationship.follow(actor, user, "accept")
|
||||
assert FollowingRelationship.following(actor) == [user.follower_address]
|
||||
end
|
||||
|
||||
test "returns following addresses with local user" do
|
||||
user = insert(:user)
|
||||
actor = insert(:user, local: true)
|
||||
FollowingRelationship.follow(actor, user, "accept")
|
||||
|
||||
assert FollowingRelationship.following(actor) == [
|
||||
actor.follower_address,
|
||||
user.follower_address
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -15,6 +15,14 @@ defmodule Pleroma.UserSearchTest do
|
|||
end
|
||||
|
||||
describe "User.search" do
|
||||
test "excluded invisible users from results" do
|
||||
user = insert(:user, %{nickname: "john t1000"})
|
||||
insert(:user, %{invisible: true, nickname: "john t800"})
|
||||
|
||||
[found_user] = User.search("john")
|
||||
assert found_user.id == user.id
|
||||
end
|
||||
|
||||
test "accepts limit parameter" do
|
||||
Enum.each(0..4, &insert(:user, %{nickname: "john#{&1}"}))
|
||||
assert length(User.search("john", limit: 3)) == 3
|
||||
|
|
|
|||
|
|
@ -25,6 +25,25 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
clear_config([:instance, :account_activation_required])
|
||||
|
||||
describe "service actors" do
|
||||
test "returns invisible actor" do
|
||||
uri = "#{Pleroma.Web.Endpoint.url()}/internal/fetch-test"
|
||||
followers_uri = "#{uri}/followers"
|
||||
user = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
|
||||
|
||||
assert %User{
|
||||
nickname: "internal.fetch-test",
|
||||
invisible: true,
|
||||
local: true,
|
||||
ap_id: ^uri,
|
||||
follower_address: ^followers_uri
|
||||
} = user
|
||||
|
||||
user2 = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
|
||||
assert user.id == user2.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "AP ID user relationships" do
|
||||
setup do
|
||||
{:ok, user: insert(:user)}
|
||||
|
|
@ -198,9 +217,10 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, user} = User.follow(user, followed)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
followed = User.get_cached_by_ap_id(followed.ap_id)
|
||||
|
||||
assert followed.follower_count == 1
|
||||
assert user.following_count == 1
|
||||
|
||||
assert User.ap_followers(followed) in User.following(user)
|
||||
end
|
||||
|
|
@ -1002,12 +1022,14 @@ defmodule Pleroma.UserTest do
|
|||
user2 = insert(:user)
|
||||
|
||||
{:ok, user2} = User.follow(user2, user)
|
||||
assert user2.following_count == 1
|
||||
assert User.following_count(user2) == 1
|
||||
|
||||
{:ok, _user} = User.deactivate(user)
|
||||
|
||||
info = User.get_cached_user_info(user2)
|
||||
|
||||
assert refresh_record(user2).following_count == 0
|
||||
assert info.following_count == 0
|
||||
assert User.following_count(user2) == 0
|
||||
assert [] = User.get_friends(user2)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.InternalFetchActor
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
||||
|
|
@ -118,6 +119,28 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
refute acc_one == acc_two
|
||||
assert acc_two == acc_three
|
||||
end
|
||||
|
||||
test "returns 404 when user is invisible", %{conn: conn} do
|
||||
user = insert(:user, %{invisible: true})
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|> json_response(404)
|
||||
|
||||
assert %{"error" => "Can't find user"} = resp
|
||||
end
|
||||
|
||||
test "returns 404 for internal.fetch actor", %{conn: conn} do
|
||||
%User{nickname: "internal.fetch"} = InternalFetchActor.get_actor()
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> get("/api/v1/accounts/internal.fetch")
|
||||
|> json_response(404)
|
||||
|
||||
assert %{"error" => "Can't find user"} = resp
|
||||
end
|
||||
end
|
||||
|
||||
describe "user timelines" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue