1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Search.MeilisearchTest do
6 require Pleroma.Constants
10 import Pleroma.Factory
14 alias Pleroma.Search.Meilisearch
15 alias Pleroma.Web.CommonAPI
18 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
22 describe "meilisearch" do
23 setup do: clear_config([Pleroma.Search, :module], Meilisearch)
27 {Meilisearch, [:passthrough],
29 add_to_index: fn a -> passthrough([a]) end,
30 remove_from_index: fn a -> passthrough([a]) end
37 test "indexes a local post on creation" do
41 %{method: :post, url: "http://127.0.0.1:7700/indexes/objects/documents", body: body} ->
43 [%{"content" => "guys i just don't wanna leave the swamp"}],
51 CommonAPI.post(user, %{
52 status: "guys i just don't wanna leave the swamp",
56 assert_called(Meilisearch.add_to_index(activity))
59 test "doesn't index posts that are not public" do
62 Enum.each(["unlisted", "private", "direct"], fn visiblity ->
64 CommonAPI.post(user, %{
65 status: "guys i just don't wanna leave the swamp",
70 history = call_history(Meilisearch)
71 assert Enum.count(history) == 3
73 Enum.each(history, fn {_, _, return} ->
78 test "deletes posts from index when deleted locally" do
82 %{method: :post, url: "http://127.0.0.1:7700/indexes/objects/documents", body: body} ->
84 [%{"content" => "guys i just don't wanna leave the swamp"}],
90 %{method: :delete, url: "http://127.0.0.1:7700/indexes/objects/documents/" <> id} ->
91 assert String.length(id) > 1
96 CommonAPI.post(user, %{
97 status: "guys i just don't wanna leave the swamp",
101 assert_called(Meilisearch.add_to_index(activity))
103 {:ok, _} = CommonAPI.delete(activity.id, user)
105 assert_called(Meilisearch.remove_from_index(:_))