logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

list_test.exs (5067B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.ListTest do
  5. alias Pleroma.Repo
  6. use Pleroma.DataCase
  7. import Pleroma.Factory
  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. test "validates title" do
  15. user = insert(:user)
  16. assert {:error, changeset} = Pleroma.List.create("", user)
  17. assert changeset.errors == [title: {"can't be blank", [validation: :required]}]
  18. end
  19. test "getting a list not belonging to the user" do
  20. user = insert(:user)
  21. other_user = insert(:user)
  22. {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
  23. ret = Pleroma.List.get(list.id, other_user)
  24. assert is_nil(ret)
  25. end
  26. test "adding an user to a list" do
  27. user = insert(:user)
  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
  32. end
  33. test "removing an user from a list" do
  34. user = insert(:user)
  35. other_user = insert(:user)
  36. {:ok, list} = Pleroma.List.create("title", user)
  37. {:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
  38. {:ok, %{following: following}} = Pleroma.List.unfollow(list, other_user)
  39. assert [] == following
  40. end
  41. test "renaming a list" do
  42. user = insert(:user)
  43. {:ok, list} = Pleroma.List.create("title", user)
  44. {:ok, %{title: title}} = Pleroma.List.rename(list, "new")
  45. assert "new" == title
  46. end
  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. test "getting users in a list" do
  54. user = insert(:user)
  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
  63. end
  64. test "getting all lists by an user" do
  65. user = insert(:user)
  66. other_user = insert(:user)
  67. {:ok, list_one} = Pleroma.List.create("title", user)
  68. {:ok, list_two} = Pleroma.List.create("other title", user)
  69. {:ok, list_three} = Pleroma.List.create("third title", other_user)
  70. lists = Pleroma.List.for_user(user, %{})
  71. assert list_one in lists
  72. assert list_two in lists
  73. refute list_three in lists
  74. end
  75. test "getting all lists the user is a member of" do
  76. user = insert(:user)
  77. other_user = insert(:user)
  78. {:ok, list_one} = Pleroma.List.create("title", user)
  79. {:ok, list_two} = Pleroma.List.create("other title", user)
  80. {:ok, list_three} = Pleroma.List.create("third title", other_user)
  81. {:ok, list_one} = Pleroma.List.follow(list_one, other_user)
  82. {:ok, list_two} = Pleroma.List.follow(list_two, other_user)
  83. {:ok, list_three} = Pleroma.List.follow(list_three, user)
  84. lists = Pleroma.List.get_lists_from_activity(%Pleroma.Activity{actor: other_user.ap_id})
  85. assert list_one in lists
  86. assert list_two in lists
  87. refute list_three in lists
  88. end
  89. test "getting own lists a given user belongs to" do
  90. owner = insert(:user)
  91. not_owner = insert(:user)
  92. member_1 = insert(:user)
  93. member_2 = insert(:user)
  94. {:ok, owned_list} = Pleroma.List.create("owned", owner)
  95. {:ok, not_owned_list} = Pleroma.List.create("not owned", not_owner)
  96. {:ok, owned_list} = Pleroma.List.follow(owned_list, member_1)
  97. {:ok, owned_list} = Pleroma.List.follow(owned_list, member_2)
  98. {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_1)
  99. {:ok, not_owned_list} = Pleroma.List.follow(not_owned_list, member_2)
  100. lists_1 = Pleroma.List.get_lists_account_belongs(owner, member_1)
  101. assert owned_list in lists_1
  102. refute not_owned_list in lists_1
  103. lists_2 = Pleroma.List.get_lists_account_belongs(owner, member_2)
  104. assert owned_list in lists_2
  105. refute not_owned_list in lists_2
  106. end
  107. test "get by ap_id" do
  108. user = insert(:user)
  109. {:ok, list} = Pleroma.List.create("foo", user)
  110. assert Pleroma.List.get_by_ap_id(list.ap_id) == list
  111. end
  112. test "memberships" do
  113. user = insert(:user)
  114. member = insert(:user)
  115. {:ok, list} = Pleroma.List.create("foo", user)
  116. {:ok, list} = Pleroma.List.follow(list, member)
  117. assert Pleroma.List.memberships(member) == [list.ap_id]
  118. end
  119. test "member?" do
  120. user = insert(:user)
  121. member = insert(:user)
  122. {:ok, list} = Pleroma.List.create("foo", user)
  123. {:ok, list} = Pleroma.List.follow(list, member)
  124. assert Pleroma.List.member?(list, member)
  125. refute Pleroma.List.member?(list, user)
  126. end
  127. end