1 defmodule Pleroma.ListTest do
7 test "creating a list" do
9 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
10 %Pleroma.List{title: title} = Pleroma.List.get(list.id, user)
11 assert title == "title"
14 test "getting a list not belonging to the user" do
16 other_user = insert(:user)
17 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
18 ret = Pleroma.List.get(list.id, other_user)
22 test "adding an user to a list" do
24 other_user = insert(:user)
25 {:ok, list} = Pleroma.List.create("title", user)
26 {:ok, %{following: following}} = Pleroma.List.follow(list, other_user)
27 assert [other_user.follower_address] == following
30 test "removing an user from a list" do
32 other_user = insert(:user)
33 {:ok, list} = Pleroma.List.create("title", user)
34 {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
35 {:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
36 assert [] == following
39 test "renaming a list" do
41 {:ok, list} = Pleroma.List.create("title", user)
42 {:ok, %{title: title}} = Pleroma.List.rename(list, "new")
46 test "deleting a list" do
48 {:ok, list} = Pleroma.List.create("title", user)
49 {:ok, list} = Pleroma.List.delete(list)
50 assert is_nil(Repo.get(Pleroma.List, list.id))
53 test "getting users in a list" do
55 other_user = insert(:user)
56 third_user = insert(:user)
57 {:ok, list} = Pleroma.List.create("title", user)
58 {:ok, list} = Pleroma.List.follow(list, other_user)
59 {:ok, list} = Pleroma.List.follow(list, third_user)
60 {:ok, following} = Pleroma.List.get_following(list)
61 assert other_user in following
62 assert third_user in following
65 test "getting all lists by an user" do
67 other_user = insert(:user)
68 {:ok, list_one} = Pleroma.List.create("title", user)
69 {:ok, list_two} = Pleroma.List.create("other title", user)
70 {:ok, list_three} = Pleroma.List.create("third title", other_user)
71 lists = Pleroma.List.for_user(user, %{})
72 assert list_one in lists
73 assert list_two in lists
74 refute list_three in lists
77 test "getting all lists the user is a member of" do
79 other_user = insert(:user)
80 {:ok, list_one} = Pleroma.List.create("title", user)
81 {:ok, list_two} = Pleroma.List.create("other title", user)
82 {:ok, list_three} = Pleroma.List.create("third title", other_user)
83 {:ok, list_one} = Pleroma.List.follow(list_one, other_user)
84 {:ok, list_two} = Pleroma.List.follow(list_two, other_user)
85 {:ok, list_three} = Pleroma.List.follow(list_three, user)
87 lists = Pleroma.List.get_lists_from_activity(%Pleroma.Activity{actor: other_user.ap_id})
88 assert list_one in lists
89 assert list_two in lists
90 refute list_three in lists
93 test "getting own lists a given user belongs to" do
95 not_owner = insert(:user)
96 member_1 = insert(:user)
97 member_2 = insert(:user)
98 {:ok, owned_list} = Pleroma.List.create("owned", owner)
99 {:ok, not_owned_list} = Pleroma.List.create("not owned", not_owner)
100 {:ok, owned_list} = Pleroma.List.follow(owned_list, member_1)
101 {:ok, owned_list} = Pleroma.List.follow(owned_list, member_2)
102 {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_1)
103 {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_2)
105 lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1.id)
106 assert owned_list in lists_1
107 refute not_owned_list in lists_1
108 lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2.id)
109 assert owned_list in lists_2
110 refute not_owned_list in lists_2