MastoAPI: Add streaming for lists.
[akkoma] / test / list_test.exs
1 defmodule Pleroma.ListTest do
2 alias Pleroma.{User, Repo}
3 use Pleroma.DataCase
4
5 import Pleroma.Factory
6 import Ecto.Query
7
8 test "creating a list" do
9 user = insert(:user)
10 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
11 %Pleroma.List{title: title} = Pleroma.List.get(list.id, user)
12 assert title == "title"
13 end
14
15 test "getting a list not belonging to the user" do
16 user = insert(:user)
17 other_user = insert(:user)
18 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
19 ret = Pleroma.List.get(list.id, other_user)
20 assert is_nil(ret)
21 end
22
23 test "adding an user to a list" do
24 user = insert(:user)
25 other_user = insert(:user)
26 {:ok, list} = Pleroma.List.create("title", user)
27 {:ok, %{following: following}} = Pleroma.List.follow(list, other_user)
28 assert [other_user.follower_address] == following
29 end
30
31 test "removing an user from a list" do
32 user = insert(:user)
33 other_user = insert(:user)
34 {:ok, list} = Pleroma.List.create("title", user)
35 {:ok, %{following: following}} = Pleroma.List.follow(list, other_user)
36 {:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
37 assert [] == following
38 end
39
40 test "renaming a list" do
41 user = insert(:user)
42 {:ok, list} = Pleroma.List.create("title", user)
43 {:ok, %{title: title}} = Pleroma.List.rename(list, "new")
44 assert "new" == title
45 end
46
47 test "deleting a list" do
48 user = insert(:user)
49 {:ok, list} = Pleroma.List.create("title", user)
50 {:ok, list} = Pleroma.List.delete(list)
51 assert is_nil(Repo.get(Pleroma.List, list.id))
52 end
53
54 test "getting users in a list" do
55 user = insert(:user)
56 other_user = insert(:user)
57 third_user = insert(:user)
58 {:ok, list} = Pleroma.List.create("title", user)
59 {:ok, list} = Pleroma.List.follow(list, other_user)
60 {:ok, list} = Pleroma.List.follow(list, third_user)
61 {:ok, following} = Pleroma.List.get_following(list)
62 assert other_user in following
63 assert third_user in following
64 end
65
66 test "getting all lists by an user" do
67 user = insert(:user)
68 other_user = insert(:user)
69 {:ok, list_one} = Pleroma.List.create("title", user)
70 {:ok, list_two} = Pleroma.List.create("other title", user)
71 {:ok, list_three} = Pleroma.List.create("third title", other_user)
72 lists = Pleroma.List.for_user(user, %{})
73 assert list_one in lists
74 assert list_two in lists
75 refute list_three in lists
76 end
77
78 test "getting all lists the user is a member of" do
79 user = insert(:user)
80 other_user = insert(:user)
81 {:ok, list_one} = Pleroma.List.create("title", user)
82 {:ok, list_two} = Pleroma.List.create("other title", user)
83 {:ok, list_three} = Pleroma.List.create("third title", other_user)
84 {:ok, list_one} = Pleroma.List.follow(list_one, other_user)
85 {:ok, list_two} = Pleroma.List.follow(list_two, other_user)
86 {:ok, list_three} = Pleroma.List.follow(list_three, user)
87
88 lists = Pleroma.List.get_lists_from_activity(%Pleroma.Activity{actor: other_user.ap_id})
89 assert list_one in lists
90 assert list_two in lists
91 refute list_three in lists
92 end
93 end