logo

pleroma

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

search_test.exs (4741B)


  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.Web.AdminAPI.SearchTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.Web.AdminAPI.Search
  7. import Pleroma.Factory
  8. describe "search for admin" do
  9. test "it ignores case" do
  10. insert(:user, nickname: "papercoach")
  11. insert(:user, nickname: "CanadaPaperCoach")
  12. {:ok, _results, count} =
  13. Search.user(%{
  14. query: "paper",
  15. local: false,
  16. page: 1,
  17. page_size: 50
  18. })
  19. assert count == 2
  20. end
  21. test "it returns local/external users" do
  22. insert(:user, local: true)
  23. insert(:user, local: false)
  24. insert(:user, local: false)
  25. {:ok, _results, local_count} =
  26. Search.user(%{
  27. query: "",
  28. local: true
  29. })
  30. {:ok, _results, external_count} =
  31. Search.user(%{
  32. query: "",
  33. external: true
  34. })
  35. assert local_count == 1
  36. assert external_count == 2
  37. end
  38. test "it returns active/deactivated users" do
  39. insert(:user, deactivated: true)
  40. insert(:user, deactivated: true)
  41. insert(:user, deactivated: false)
  42. {:ok, _results, active_count} =
  43. Search.user(%{
  44. query: "",
  45. active: true
  46. })
  47. {:ok, _results, deactivated_count} =
  48. Search.user(%{
  49. query: "",
  50. deactivated: true
  51. })
  52. assert active_count == 1
  53. assert deactivated_count == 2
  54. end
  55. test "it returns specific user" do
  56. insert(:user)
  57. insert(:user)
  58. user = insert(:user, nickname: "bob", local: true, deactivated: false)
  59. {:ok, _results, total_count} = Search.user(%{query: ""})
  60. {:ok, [^user], count} =
  61. Search.user(%{
  62. query: "Bo",
  63. active: true,
  64. local: true
  65. })
  66. assert total_count == 3
  67. assert count == 1
  68. end
  69. test "it returns user by domain" do
  70. insert(:user)
  71. insert(:user)
  72. user = insert(:user, nickname: "some@domain.com")
  73. {:ok, _results, total} = Search.user()
  74. {:ok, [^user], count} = Search.user(%{query: "domain.com"})
  75. assert total == 3
  76. assert count == 1
  77. end
  78. test "it return user by full nickname" do
  79. insert(:user)
  80. insert(:user)
  81. user = insert(:user, nickname: "some@domain.com")
  82. {:ok, _results, total} = Search.user()
  83. {:ok, [^user], count} = Search.user(%{query: "some@domain.com"})
  84. assert total == 3
  85. assert count == 1
  86. end
  87. test "it returns admin user" do
  88. admin = insert(:user, is_admin: true)
  89. insert(:user)
  90. insert(:user)
  91. {:ok, _results, total} = Search.user()
  92. {:ok, [^admin], count} = Search.user(%{is_admin: true})
  93. assert total == 3
  94. assert count == 1
  95. end
  96. test "it returns moderator user" do
  97. moderator = insert(:user, is_moderator: true)
  98. insert(:user)
  99. insert(:user)
  100. {:ok, _results, total} = Search.user()
  101. {:ok, [^moderator], count} = Search.user(%{is_moderator: true})
  102. assert total == 3
  103. assert count == 1
  104. end
  105. test "it returns users with tags" do
  106. user1 = insert(:user, tags: ["first"])
  107. user2 = insert(:user, tags: ["second"])
  108. insert(:user)
  109. insert(:user)
  110. {:ok, _results, total} = Search.user()
  111. {:ok, users, count} = Search.user(%{tags: ["first", "second"]})
  112. assert total == 4
  113. assert count == 2
  114. assert user1 in users
  115. assert user2 in users
  116. end
  117. test "it returns user by display name" do
  118. user = insert(:user, name: "Display name")
  119. insert(:user)
  120. insert(:user)
  121. {:ok, _results, total} = Search.user()
  122. {:ok, [^user], count} = Search.user(%{name: "display"})
  123. assert total == 3
  124. assert count == 1
  125. end
  126. test "it returns user by email" do
  127. user = insert(:user, email: "some@example.com")
  128. insert(:user)
  129. insert(:user)
  130. {:ok, _results, total} = Search.user()
  131. {:ok, [^user], count} = Search.user(%{email: "some@example.com"})
  132. assert total == 3
  133. assert count == 1
  134. end
  135. test "it returns unapproved user" do
  136. unapproved = insert(:user, approval_pending: true)
  137. insert(:user)
  138. insert(:user)
  139. {:ok, _results, total} = Search.user()
  140. {:ok, [^unapproved], count} = Search.user(%{need_approval: true})
  141. assert total == 3
  142. assert count == 1
  143. end
  144. test "it returns non-discoverable users" do
  145. insert(:user)
  146. insert(:user, discoverable: false)
  147. {:ok, _results, total} = Search.user()
  148. assert total == 2
  149. end
  150. end
  151. end