1
0
Fork 1
mirror of https://akkoma.dev/AkkomaGang/akkoma.git synced 2024-12-25 04:53:06 +00:00

Add a test for List.get_lists_account_belongs

This commit is contained in:
AkiraFukushima 2018-10-19 21:24:15 +09:00
parent e8c698af41
commit a249cbf187
2 changed files with 29 additions and 1 deletions

View file

@ -72,11 +72,19 @@ def get_lists_from_activity(%Activity{actor: ap_id}) do
# Get lists to which the account belongs.
def get_lists_account_belongs(%User{} = owner, account_id) do
user = Repo.get(User, account_id)
query =
from(
l in Pleroma.List,
where: l.user_id == ^owner.id and fragment("? = ANY(?)", ^user.follower_address, l.following)
where:
l.user_id == ^owner.id and
fragment(
"? = ANY(?)",
^user.follower_address,
l.following
)
)
Repo.all(query)
end

View file

@ -90,4 +90,24 @@ test "getting all lists the user is a member of" do
assert list_two in lists
refute list_three in lists
end
test "getting onwered lists the user belongs" do
owner = insert(:user)
not_owner = insert(:user)
member_1 = insert(:user)
member_2 = insert(:user)
{:ok, ownered_list} = Pleroma.List.create("ownered", owner)
{:ok, not_ownered_list} = Pleroma.List.create("not ownered", not_owner)
{:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_1)
{:ok, ownered_list} = Pleroma.List.follow(ownered_list, member_2)
{:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_1)
{:ok, not_ownered_list} = Pleroma.List.follow(not_ownered_list, member_2)
lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id)
assert ownered_list in lists_1
refute not_ownered_list in lists_1
lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id)
assert ownered_list in lists_2
refute not_ownered_list in lists_2
end
end