1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ListTest do
11 test "creating a list" do
13 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
14 %Pleroma.List{title: title} = Pleroma.List.get(list.id, user)
15 assert title == "title"
18 test "getting a list not belonging to the user" do
20 other_user = insert(:user)
21 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
22 ret = Pleroma.List.get(list.id, other_user)
26 test "adding an user to a list" do
28 other_user = insert(:user)
29 {:ok, list} = Pleroma.List.create("title", user)
30 {:ok, %{following: following}} = Pleroma.List.follow(list, other_user)
31 assert [other_user.follower_address] == following
34 test "removing an user from a list" do
36 other_user = insert(:user)
37 {:ok, list} = Pleroma.List.create("title", user)
38 {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
39 {:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
40 assert [] == following
43 test "renaming a list" do
45 {:ok, list} = Pleroma.List.create("title", user)
46 {:ok, %{title: title}} = Pleroma.List.rename(list, "new")
50 test "deleting a list" do
52 {:ok, list} = Pleroma.List.create("title", user)
53 {:ok, list} = Pleroma.List.delete(list)
54 assert is_nil(Repo.get(Pleroma.List, list.id))
57 test "getting users in a list" do
59 other_user = insert(:user)
60 third_user = insert(:user)
61 {:ok, list} = Pleroma.List.create("title", user)
62 {:ok, list} = Pleroma.List.follow(list, other_user)
63 {:ok, list} = Pleroma.List.follow(list, third_user)
64 {:ok, following} = Pleroma.List.get_following(list)
65 assert other_user in following
66 assert third_user in following
69 test "getting all lists by an user" do
71 other_user = insert(:user)
72 {:ok, list_one} = Pleroma.List.create("title", user)
73 {:ok, list_two} = Pleroma.List.create("other title", user)
74 {:ok, list_three} = Pleroma.List.create("third title", other_user)
75 lists = Pleroma.List.for_user(user, %{})
76 assert list_one in lists
77 assert list_two in lists
78 refute list_three in lists
81 test "getting all lists the user is a member of" do
83 other_user = insert(:user)
84 {:ok, list_one} = Pleroma.List.create("title", user)
85 {:ok, list_two} = Pleroma.List.create("other title", user)
86 {:ok, list_three} = Pleroma.List.create("third title", other_user)
87 {:ok, list_one} = Pleroma.List.follow(list_one, other_user)
88 {:ok, list_two} = Pleroma.List.follow(list_two, other_user)
89 {:ok, list_three} = Pleroma.List.follow(list_three, user)
91 lists = Pleroma.List.get_lists_from_activity(%Pleroma.Activity{actor: other_user.ap_id})
92 assert list_one in lists
93 assert list_two in lists
94 refute list_three in lists
97 test "getting own lists a given user belongs to" do
99 not_owner = insert(:user)
100 member_1 = insert(:user)
101 member_2 = insert(:user)
102 {:ok, owned_list} = Pleroma.List.create("owned", owner)
103 {:ok, not_owned_list} = Pleroma.List.create("not owned", not_owner)
104 {:ok, owned_list} = Pleroma.List.follow(owned_list, member_1)
105 {:ok, owned_list} = Pleroma.List.follow(owned_list, member_2)
106 {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_1)
107 {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_2)
109 lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id)
110 assert owned_list in lists_1
111 refute not_owned_list in lists_1
112 lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id)
113 assert owned_list in lists_2
114 refute not_owned_list in lists_2
117 test "get ap_id by user nickname and list id" do
121 expected = Pleroma.Web.Endpoint.url() <> "/users/#{nickname}/lists/#{list_id}"
123 assert Pleroma.List.ap_id(%Pleroma.User{nickname: nickname}, list_id) == expected
124 assert Pleroma.List.ap_id({nickname, list_id}) == expected
127 test "get by ap_id" do
129 {:ok, list} = Pleroma.List.create("foo", user)
130 ap_id = Pleroma.List.ap_id(user, list.id)
132 assert Pleroma.List.get_by_ap_id(ap_id) == list
135 test "memberships" do
137 member = insert(:user)
138 {:ok, list} = Pleroma.List.create("foo", user)
139 {:ok, list} = Pleroma.List.follow(list, member)
141 list_ap_id = Pleroma.List.ap_id(user, list.id)
143 assert Pleroma.List.memberships(member) == [list_ap_id]