X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fadmin_api%2Fsearch_test.exs;h=b974cedd5a2dd7ce11566bef41b76a0534c2036e;hb=7ac5f210ea386b9c0e75626a71fd01c6ef9d4408;hp=3950996edf6cc629a772122d109c58ef66aacf84;hpb=5d871173d189a0019fda0ee76f8a324d90a163ee;p=akkoma
diff --git a/test/web/admin_api/search_test.exs b/test/web/admin_api/search_test.exs
index 3950996ed..b974cedd5 100644
--- a/test/web/admin_api/search_test.exs
+++ b/test/web/admin_api/search_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.SearchTest do
@@ -47,9 +47,9 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
end
test "it returns active/deactivated users" do
- insert(:user, info: %{deactivated: true})
- insert(:user, info: %{deactivated: true})
- insert(:user, info: %{deactivated: false})
+ insert(:user, deactivated: true)
+ insert(:user, deactivated: true)
+ insert(:user, deactivated: false)
{:ok, _results, active_count} =
Search.user(%{
@@ -70,11 +70,11 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
test "it returns specific user" do
insert(:user)
insert(:user)
- insert(:user, nickname: "bob", local: true, info: %{deactivated: false})
+ user = insert(:user, nickname: "bob", local: true, deactivated: false)
{:ok, _results, total_count} = Search.user(%{query: ""})
- {:ok, _results, count} =
+ {:ok, [^user], count} =
Search.user(%{
query: "Bo",
active: true,
@@ -84,5 +84,98 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
assert total_count == 3
assert count == 1
end
+
+ 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
+ admin = insert(:user, is_admin: true)
+ 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
+ moderator = insert(:user, is_moderator: true)
+ 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
+
+ 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
+
+ test "it returns unapproved user" do
+ unapproved = insert(:user, approval_pending: true)
+ insert(:user)
+ insert(:user)
+
+ {:ok, _results, total} = Search.user()
+ {:ok, [^unapproved], count} = Search.user(%{need_approval: true})
+ assert total == 3
+ assert count == 1
+ end
end
end