logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

search_test.exs (2045B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Activity.SearchTest do
  5. alias Pleroma.Activity.Search
  6. alias Pleroma.Web.CommonAPI
  7. import Pleroma.Factory
  8. use Pleroma.DataCase, async: true
  9. test "it finds something" do
  10. user = insert(:user)
  11. {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
  12. [result] = Search.search(nil, "wednesday")
  13. assert result.id == post.id
  14. end
  15. test "it finds local-only posts for authenticated users" do
  16. user = insert(:user)
  17. reader = insert(:user)
  18. {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
  19. [result] = Search.search(reader, "wednesday")
  20. assert result.id == post.id
  21. end
  22. test "it does not find local-only posts for anonymous users" do
  23. user = insert(:user)
  24. {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
  25. assert [] = Search.search(nil, "wednesday")
  26. end
  27. test "using plainto_tsquery on postgres < 11" do
  28. old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
  29. :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
  30. on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
  31. user = insert(:user)
  32. {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
  33. {:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
  34. # plainto doesn't understand complex queries
  35. assert [result] = Search.search(nil, "wednesday -dudes")
  36. assert result.id == post.id
  37. end
  38. test "using websearch_to_tsquery" do
  39. user = insert(:user)
  40. {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
  41. {:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
  42. assert [result] = Search.search(nil, "wednesday -dudes")
  43. assert result.id == other_post.id
  44. end
  45. end