From e8d8c84f795152a0522e6848e75b47dcbce5aa89 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 16 Nov 2018 18:31:32 +0100 Subject: [PATCH] Add better test for user search functionlity. --- lib/pleroma/user.ex | 2 +- test/user_test.exs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index be634a8e1..6e1d5559d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -498,7 +498,7 @@ defmodule Pleroma.User do Repo.all(query) end - def search(query, resolve) do + def search(query, resolve \\ false) do # strip the beginning @ off if there is a query query = String.trim_leading(query, "@") diff --git a/test/user_test.exs b/test/user_test.exs index 7dec3462f..231f1d94d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -578,4 +578,16 @@ defmodule Pleroma.UserTest do assert cached_user != user end end + + describe "User.search" do + test "finds a user, ranking by similarity" do + user = insert(:user, %{name: "lain"}) + user_two = insert(:user, %{name: "ean"}) + user_three = insert(:user, %{name: "ebn", nickname: "lain@mastodon.social"}) + user_four = insert(:user, %{nickname: "lain@pleroma.soykaf.com"}) + + assert user_four == + User.search("lain@ple") |> List.first() |> Map.put(:search_distance, nil) + end + end end