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