Strip status data from Flag (when federating or closing/resolving report)
[akkoma] / test / user_search_test.exs
index 8f8472aaef2aa853c7031c42678705c4dc2e836c..f7ab312872c0c820a8919dd318513e227c47d6db 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.UserSearchTest do
@@ -193,7 +193,14 @@ defmodule Pleroma.UserSearchTest do
       user = User.get_cached_by_ap_id("http://mastodon.example.org/users/admin")
 
       assert length(results) == 1
-      assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+
+      expected =
+        result
+        |> Map.put(:search_rank, nil)
+        |> Map.put(:search_type, nil)
+        |> Map.put(:last_digest_emailed_at, nil)
+
+      assert user == expected
     end
 
     test "excludes a blocked users from search result" do
@@ -217,5 +224,88 @@ defmodule Pleroma.UserSearchTest do
       refute Enum.member?(account_ids, blocked_user2.id)
       assert length(account_ids) == 3
     end
+
+    test "local user has the same search_rank as for users with the same nickname, but another domain" do
+      user = insert(:user)
+      insert(:user, nickname: "lain@mastodon.social")
+      insert(:user, nickname: "lain")
+      insert(:user, nickname: "lain@pleroma.social")
+
+      assert User.search("lain@localhost", resolve: true, for_user: user)
+             |> Enum.each(fn u -> u.search_rank == 0.5 end)
+    end
+
+    test "localhost is the part of the domain" do
+      user = insert(:user)
+      insert(:user, nickname: "another@somedomain")
+      insert(:user, nickname: "lain")
+      insert(:user, nickname: "lain@examplelocalhost")
+
+      result = User.search("lain@examplelocalhost", resolve: true, for_user: user)
+      assert Enum.each(result, fn u -> u.search_rank == 0.5 end)
+      assert length(result) == 2
+    end
+
+    test "local user search with users" do
+      user = insert(:user)
+      local_user = insert(:user, nickname: "lain")
+      insert(:user, nickname: "another@localhost.com")
+      insert(:user, nickname: "localhost@localhost.com")
+
+      [result] = User.search("lain@localhost", resolve: true, for_user: user)
+      assert Map.put(result, :search_rank, nil) |> Map.put(:search_type, nil) == local_user
+    end
+
+    test "works with idna domains" do
+      user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+      results = User.search("lain@zetsubou.みんな", resolve: false, for_user: user)
+
+      result = List.first(results)
+
+      assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+    end
+
+    test "works with idna domains converted input" do
+      user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+      results =
+        User.search("lain@zetsubou." <> to_string(:idna.encode("zetsubou.みんな")),
+          resolve: false,
+          for_user: user
+        )
+
+      result = List.first(results)
+
+      assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+    end
+
+    test "works with idna domains and bad chars in domain" do
+      user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+      results =
+        User.search("lain@zetsubou!@#$%^&*()+,-/:;<=>?[]'_{}|~`.みんな",
+          resolve: false,
+          for_user: user
+        )
+
+      result = List.first(results)
+
+      assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+    end
+
+    test "works with idna domains and query as link" do
+      user = insert(:user, nickname: "lain@" <> to_string(:idna.encode("zetsubou.みんな")))
+
+      results =
+        User.search("https://zetsubou.みんな/users/lain",
+          resolve: false,
+          for_user: user
+        )
+
+      result = List.first(results)
+
+      assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+    end
   end
 end