1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.SearchTest do
6 use Pleroma.Web.ConnCase
8 alias Pleroma.Web.AdminAPI.Search
10 import Pleroma.Factory
12 describe "search for admin" do
13 test "it ignores case" do
14 insert(:user, nickname: "papercoach")
15 insert(:user, nickname: "CanadaPaperCoach")
17 {:ok, _results, count} =
28 test "it returns local/external users" do
29 insert(:user, local: true)
30 insert(:user, local: false)
31 insert(:user, local: false)
33 {:ok, _results, local_count} =
39 {:ok, _results, external_count} =
45 assert local_count == 1
46 assert external_count == 2
49 test "it returns active/deactivated users" do
50 insert(:user, deactivated: true)
51 insert(:user, deactivated: true)
52 insert(:user, deactivated: false)
54 {:ok, _results, active_count} =
60 {:ok, _results, deactivated_count} =
66 assert active_count == 1
67 assert deactivated_count == 2
70 test "it returns specific user" do
73 user = insert(:user, nickname: "bob", local: true, deactivated: false)
75 {:ok, _results, total_count} = Search.user(%{query: ""})
77 {:ok, [^user], count} =
84 assert total_count == 3
88 test "it returns user by domain" do
91 user = insert(:user, nickname: "some@domain.com")
93 {:ok, _results, total} = Search.user()
94 {:ok, [^user], count} = Search.user(%{query: "domain.com"})
99 test "it return user by full nickname" do
102 user = insert(:user, nickname: "some@domain.com")
104 {:ok, _results, total} = Search.user()
105 {:ok, [^user], count} = Search.user(%{query: "some@domain.com"})
110 test "it returns admin user" do
111 admin = insert(:user, is_admin: true)
115 {:ok, _results, total} = Search.user()
116 {:ok, [^admin], count} = Search.user(%{is_admin: true})
121 test "it returns moderator user" do
122 moderator = insert(:user, is_moderator: true)
126 {:ok, _results, total} = Search.user()
127 {:ok, [^moderator], count} = Search.user(%{is_moderator: true})
132 test "it returns users with tags" do
133 user1 = insert(:user, tags: ["first"])
134 user2 = insert(:user, tags: ["second"])
138 {:ok, _results, total} = Search.user()
139 {:ok, users, count} = Search.user(%{tags: ["first", "second"]})
142 assert user1 in users
143 assert user2 in users
146 test "it returns user by display name" do
147 user = insert(:user, name: "Display name")
151 {:ok, _results, total} = Search.user()
152 {:ok, [^user], count} = Search.user(%{name: "display"})
158 test "it returns user by email" do
159 user = insert(:user, email: "some@example.com")
163 {:ok, _results, total} = Search.user()
164 {:ok, [^user], count} = Search.user(%{email: "some@example.com"})
170 test "it returns unapproved user" do
171 unapproved = insert(:user, approval_pending: true)
175 {:ok, _results, total} = Search.user()
176 {:ok, [^unapproved], count} = Search.user(%{need_approval: true})
181 test "it returns non-discoverable users" do
183 insert(:user, discoverable: false)
185 {:ok, _results, total} = Search.user()