1 defmodule Pleroma.ListTest do
2 alias Pleroma.{User, Repo}
8 test "creating a list" do
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"
15 test "getting a list not belonging to the user" do
17 other_user = insert(:user)
18 {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
19 ret = Pleroma.List.get(list.id, other_user)
23 test "adding an user to a list" do
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
31 test "removing an user from a list" do
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
40 test "renaming a list" do
42 {:ok, list} = Pleroma.List.create("title", user)
43 {:ok, %{title: title}} = Pleroma.List.rename(list, "new")
47 test "deleting a list" do
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))
54 test "getting users in a list" do
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
66 test "getting all lists by an user" do
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