2019-03-26 16:51:59 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-03-26 16:51:59 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.AdminAPI.SearchTest do
|
2020-12-21 04:21:40 -07:00
|
|
|
use Pleroma.Web.ConnCase, async: true
|
2019-03-26 16:51:59 -06:00
|
|
|
|
|
|
|
alias Pleroma.Web.AdminAPI.Search
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
describe "search for admin" do
|
|
|
|
test "it ignores case" do
|
|
|
|
insert(:user, nickname: "papercoach")
|
|
|
|
insert(:user, nickname: "CanadaPaperCoach")
|
|
|
|
|
|
|
|
{:ok, _results, count} =
|
|
|
|
Search.user(%{
|
|
|
|
query: "paper",
|
|
|
|
local: false,
|
|
|
|
page: 1,
|
|
|
|
page_size: 50
|
|
|
|
})
|
|
|
|
|
|
|
|
assert count == 2
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns local/external users" do
|
|
|
|
insert(:user, local: true)
|
|
|
|
insert(:user, local: false)
|
|
|
|
insert(:user, local: false)
|
|
|
|
|
|
|
|
{:ok, _results, local_count} =
|
|
|
|
Search.user(%{
|
|
|
|
query: "",
|
|
|
|
local: true
|
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, _results, external_count} =
|
|
|
|
Search.user(%{
|
|
|
|
query: "",
|
|
|
|
external: true
|
|
|
|
})
|
|
|
|
|
|
|
|
assert local_count == 1
|
|
|
|
assert external_count == 2
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns active/deactivated users" do
|
2020-10-12 16:42:27 -06:00
|
|
|
insert(:user, is_active: false)
|
|
|
|
insert(:user, is_active: false)
|
|
|
|
insert(:user, is_active: true)
|
2019-03-26 16:51:59 -06:00
|
|
|
|
|
|
|
{:ok, _results, active_count} =
|
|
|
|
Search.user(%{
|
|
|
|
query: "",
|
|
|
|
active: true
|
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, _results, deactivated_count} =
|
|
|
|
Search.user(%{
|
|
|
|
query: "",
|
|
|
|
deactivated: true
|
|
|
|
})
|
|
|
|
|
|
|
|
assert active_count == 1
|
|
|
|
assert deactivated_count == 2
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns specific user" do
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
2020-10-12 16:42:27 -06:00
|
|
|
user = insert(:user, nickname: "bob", local: true, is_active: true)
|
2019-03-26 16:51:59 -06:00
|
|
|
|
|
|
|
{:ok, _results, total_count} = Search.user(%{query: ""})
|
|
|
|
|
2019-05-08 08:34:36 -06:00
|
|
|
{:ok, [^user], count} =
|
2019-03-26 16:51:59 -06:00
|
|
|
Search.user(%{
|
|
|
|
query: "Bo",
|
|
|
|
active: true,
|
|
|
|
local: true
|
|
|
|
})
|
|
|
|
|
|
|
|
assert total_count == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
2019-05-08 08:34:36 -06:00
|
|
|
|
|
|
|
test "it returns user by domain" do
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
user = insert(:user, nickname: "some@domain.com")
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^user], count} = Search.user(%{query: "domain.com"})
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it return user by full nickname" do
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
user = insert(:user, nickname: "some@domain.com")
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^user], count} = Search.user(%{query: "some@domain.com"})
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns admin user" do
|
2019-10-16 12:59:21 -06:00
|
|
|
admin = insert(:user, is_admin: true)
|
2019-05-08 08:34:36 -06:00
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^admin], count} = Search.user(%{is_admin: true})
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns moderator user" do
|
2019-10-16 12:59:21 -06:00
|
|
|
moderator = insert(:user, is_moderator: true)
|
2019-05-08 08:34:36 -06:00
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^moderator], count} = Search.user(%{is_moderator: true})
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns users with tags" do
|
|
|
|
user1 = insert(:user, tags: ["first"])
|
|
|
|
user2 = insert(:user, tags: ["second"])
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, users, count} = Search.user(%{tags: ["first", "second"]})
|
|
|
|
assert total == 4
|
|
|
|
assert count == 2
|
|
|
|
assert user1 in users
|
|
|
|
assert user2 in users
|
|
|
|
end
|
|
|
|
|
2020-09-25 07:04:01 -06:00
|
|
|
test "it returns users by actor_types" do
|
|
|
|
user_service = insert(:user, actor_type: "Service")
|
|
|
|
user_application = insert(:user, actor_type: "Application")
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
|
|
|
|
|
|
|
{:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
|
|
|
|
{:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
|
2021-07-13 20:37:25 -06:00
|
|
|
{:ok, [^user2, ^user1], 2} = Search.user(%{actor_types: ["Person"]})
|
2020-09-25 07:04:01 -06:00
|
|
|
|
2021-07-13 20:37:25 -06:00
|
|
|
{:ok, [^user2, ^user1, ^user_service], 3} =
|
2020-09-25 07:04:01 -06:00
|
|
|
Search.user(%{actor_types: ["Person", "Service"]})
|
|
|
|
end
|
|
|
|
|
2019-05-08 08:34:36 -06:00
|
|
|
test "it returns user by display name" do
|
|
|
|
user = insert(:user, name: "Display name")
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^user], count} = Search.user(%{name: "display"})
|
|
|
|
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it returns user by email" do
|
|
|
|
user = insert(:user, email: "some@example.com")
|
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^user], count} = Search.user(%{email: "some@example.com"})
|
|
|
|
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
2020-07-14 13:14:43 -06:00
|
|
|
|
|
|
|
test "it returns unapproved user" do
|
2020-10-16 15:44:25 -06:00
|
|
|
unapproved = insert(:user, is_approved: false)
|
2020-07-14 13:14:43 -06:00
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
{:ok, [^unapproved], count} = Search.user(%{need_approval: true})
|
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
2020-09-14 09:40:52 -06:00
|
|
|
|
2020-09-21 00:33:51 -06:00
|
|
|
test "it returns unconfirmed user" do
|
2020-10-13 13:29:34 -06:00
|
|
|
unconfirmed = insert(:user, is_confirmed: false)
|
2020-09-21 00:33:51 -06:00
|
|
|
insert(:user)
|
|
|
|
insert(:user)
|
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
2020-09-25 00:39:49 -06:00
|
|
|
{:ok, [^unconfirmed], count} = Search.user(%{unconfirmed: true})
|
2020-09-21 00:33:51 -06:00
|
|
|
assert total == 3
|
|
|
|
assert count == 1
|
|
|
|
end
|
|
|
|
|
2020-11-19 09:30:02 -07:00
|
|
|
# Note: as in Mastodon, `is_discoverable` doesn't anyhow relate to user searchability
|
2020-09-14 09:40:52 -06:00
|
|
|
test "it returns non-discoverable users" do
|
|
|
|
insert(:user)
|
2020-10-13 08:45:08 -06:00
|
|
|
insert(:user, is_discoverable: false)
|
2020-09-14 09:40:52 -06:00
|
|
|
|
|
|
|
{:ok, _results, total} = Search.user()
|
|
|
|
|
|
|
|
assert total == 2
|
|
|
|
end
|
2019-03-26 16:51:59 -06:00
|
|
|
end
|
|
|
|
end
|