1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Search.DatabaseSearchTest do
6 alias Pleroma.Search.DatabaseSearch, as: Search
7 alias Pleroma.Web.CommonAPI
10 use Pleroma.DataCase, async: true
12 test "it finds something" do
14 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
16 [result] = Search.search(nil, "wednesday")
18 assert result.id == post.id
21 test "it finds local-only posts for authenticated users" do
23 reader = insert(:user)
24 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
26 [result] = Search.search(reader, "wednesday")
28 assert result.id == post.id
31 test "it does not find local-only posts for anonymous users" do
33 {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
35 assert [] = Search.search(nil, "wednesday")
38 test "using websearch_to_tsquery" do
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"})
43 assert [result] = Search.search(nil, "wednesday -dudes")
45 assert result.id == other_post.id