From c1bae0137666505c16482fd22cb3a14bed7a4499 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 9 Oct 2019 16:03:45 +0200 Subject: [PATCH] Search: Add tests for unicode searches. --- test/activity_test.exs | 18 +++++++++++++++++- .../controllers/search_controller_test.exs | 15 +++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/test/activity_test.exs b/test/activity_test.exs index 95d9341c4..e7ea2bd5e 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -126,9 +126,25 @@ test "when association is not loaded" do } {:ok, local_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "find me!"}) + {:ok, japanese_activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "更新情報"}) {:ok, job} = Pleroma.Web.Federator.incoming_ap_doc(params) {:ok, remote_activity} = ObanHelpers.perform(job) - %{local_activity: local_activity, remote_activity: remote_activity, user: user} + + %{ + japanese_activity: japanese_activity, + local_activity: local_activity, + remote_activity: remote_activity, + user: user + } + end + + test "finds utf8 text in statuses", %{ + japanese_activity: japanese_activity, + user: user + } do + activities = Activity.search(user, "更新情報") + + assert [^japanese_activity] = activities end test "find local and remote statuses for authenticated users", %{ diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 49c79ff0a..0ca896e01 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -40,7 +40,7 @@ test "it returns empty result if user or status search return undefined error", test "search", %{conn: conn} do user = insert(:user) user_two = insert(:user, %{nickname: "shp@shitposter.club"}) - user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"}) + user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu 天子"}) {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private"}) @@ -52,9 +52,9 @@ test "search", %{conn: conn} do {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"}) - conn = get(conn, "/api/v2/search", %{"q" => "2hu #private"}) - - assert results = json_response(conn, 200) + results = + get(conn, "/api/v2/search", %{"q" => "2hu #private"}) + |> json_response(200) [account | _] = results["accounts"] assert account["id"] == to_string(user_three.id) @@ -65,6 +65,13 @@ test "search", %{conn: conn} do [status] = results["statuses"] assert status["id"] == to_string(activity.id) + + results = + get(conn, "/api/v2/search", %{"q" => "天子"}) + |> json_response(200) + + [account] == results["accounts"] + assert account["id"] == to_string(user_three.id) end end