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, async: true
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 users by actor_types" do
147 user_service = insert(:user, actor_type: "Service")
148 user_application = insert(:user, actor_type: "Application")
149 user1 = insert(:user)
150 user2 = insert(:user)
152 {:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
153 {:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
154 {:ok, [^user1, ^user2], 2} = Search.user(%{actor_types: ["Person"]})
156 {:ok, [^user_service, ^user1, ^user2], 3} =
157 Search.user(%{actor_types: ["Person", "Service"]})
160 test "it returns user by display name" do
161 user = insert(:user, name: "Display name")
165 {:ok, _results, total} = Search.user()
166 {:ok, [^user], count} = Search.user(%{name: "display"})
172 test "it returns user by email" do
173 user = insert(:user, email: "some@example.com")
177 {:ok, _results, total} = Search.user()
178 {:ok, [^user], count} = Search.user(%{email: "some@example.com"})
184 test "it returns unapproved user" do
185 unapproved = insert(:user, approval_pending: true)
189 {:ok, _results, total} = Search.user()
190 {:ok, [^unapproved], count} = Search.user(%{need_approval: true})
195 test "it returns unconfirmed user" do
196 unconfirmed = insert(:user, confirmation_pending: true)
200 {:ok, _results, total} = Search.user()
201 {:ok, [^unconfirmed], count} = Search.user(%{unconfirmed: true})
206 # Note: as in Mastodon, `is_discoverable` doesn't anyhow relate to user searchability
207 test "it returns non-discoverable users" do
209 insert(:user, is_discoverable: false)
211 {:ok, _results, total} = Search.user()