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
8 use Pleroma.DataCase, async: true
9 use Oban.Testing, repo: Pleroma.Repo
11 import Pleroma.Factory
15 alias Pleroma.Search.Meilisearch
16 alias Pleroma.UnstubbedConfigMock, as: Config
17 alias Pleroma.Web.CommonAPI
18 alias Pleroma.Workers.SearchIndexingWorker
20 describe "meilisearch" do
21 test "indexes a local post on creation" do
27 url: "http://127.0.0.1:7700/indexes/objects/documents",
31 [%{"content" => "guys i just don't wanna leave the swamp"}],
35 # To make sure that the worker is called
36 send(self(), "posted_to_meilisearch")
39 "enqueuedAt" => "2023-11-12T12:36:46.927517Z",
40 "indexUid" => "objects",
41 "status" => "enqueued",
43 "type" => "documentAdditionOrUpdate"
50 [Pleroma.Search, :module], nil ->
53 [Pleroma.Search.Meilisearch, :url], nil ->
54 "http://127.0.0.1:7700"
56 [Pleroma.Search.Meilisearch, :private_key], nil ->
61 CommonAPI.post(user, %{
62 status: "guys i just don't wanna leave the swamp",
66 args = %{"op" => "add_to_index", "activity" => activity.id}
69 worker: SearchIndexingWorker,
73 assert :ok = perform_job(SearchIndexingWorker, args)
74 assert_received("posted_to_meilisearch")
77 test "doesn't index posts that are not public" do
80 Enum.each(["private", "direct"], fn visibility ->
82 CommonAPI.post(user, %{
83 status: "guys i just don't wanna leave the swamp",
84 visibility: visibility
87 args = %{"op" => "add_to_index", "activity" => activity.id}
91 [Pleroma.Search, :module], nil ->
95 assert_enqueued(worker: SearchIndexingWorker, args: args)
96 assert :ok = perform_job(SearchIndexingWorker, args)
100 test "deletes posts from index when deleted locally" do
106 url: "http://127.0.0.1:7700/indexes/objects/documents",
110 [%{"content" => "guys i just don't wanna leave the swamp"}],
115 "enqueuedAt" => "2023-11-12T12:36:46.927517Z",
116 "indexUid" => "objects",
117 "status" => "enqueued",
119 "type" => "documentAdditionOrUpdate"
123 %{method: :delete, url: "http://127.0.0.1:7700/indexes/objects/documents/" <> id} ->
124 send(self(), "called_delete")
125 assert String.length(id) > 1
130 |> expect(:get, 6, fn
131 [Pleroma.Search, :module], nil ->
134 [Pleroma.Search.Meilisearch, :url], nil ->
135 "http://127.0.0.1:7700"
137 [Pleroma.Search.Meilisearch, :private_key], nil ->
142 CommonAPI.post(user, %{
143 status: "guys i just don't wanna leave the swamp",
147 args = %{"op" => "add_to_index", "activity" => activity.id}
148 assert_enqueued(worker: SearchIndexingWorker, args: args)
149 assert :ok = perform_job(SearchIndexingWorker, args)
151 {:ok, _} = CommonAPI.delete(activity.id, user)
153 delete_args = %{"op" => "remove_from_index", "object" => activity.object.id}
154 assert_enqueued(worker: SearchIndexingWorker, args: delete_args)
155 assert :ok = perform_job(SearchIndexingWorker, delete_args)
157 assert_received("called_delete")