2020-01-26 20:11:16 +00:00
|
|
|
defmodule Mobilizon.GraphQL.API.SearchTest do
|
2019-02-21 17:11:49 +00:00
|
|
|
use ExUnit.Case, async: false
|
|
|
|
|
2019-09-22 14:26:23 +00:00
|
|
|
import Mock
|
|
|
|
|
2019-02-21 17:11:49 +00:00
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-22 14:26:23 +00:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Events.Event
|
2019-09-08 22:52:49 +00:00
|
|
|
alias Mobilizon.Storage.Page
|
|
|
|
|
2020-01-26 20:11:16 +00:00
|
|
|
alias Mobilizon.GraphQL.API.Search
|
2020-01-22 01:14:42 +00:00
|
|
|
|
2020-01-26 20:11:16 +00:00
|
|
|
alias Mobilizon.Federation.ActivityPub
|
2021-04-22 10:17:56 +00:00
|
|
|
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
2019-02-21 17:11:49 +00:00
|
|
|
|
|
|
|
test "search an user by username" do
|
2021-04-22 10:17:56 +00:00
|
|
|
with_mock ActivityPubActor,
|
2021-08-23 08:34:33 +00:00
|
|
|
find_or_make_actor_from_nickname: fn "toto@domain.tld" ->
|
|
|
|
{:ok, %Actor{id: 42, type: :Group}}
|
|
|
|
end do
|
|
|
|
assert {:ok, %Page{total: 1, elements: [%Actor{id: 42, type: :Group}]}} ==
|
|
|
|
Search.search_actors(%{term: "toto@domain.tld"}, 1, 10, :Group)
|
2019-04-12 13:04:32 +00:00
|
|
|
|
2021-04-22 10:17:56 +00:00
|
|
|
assert_called(ActivityPubActor.find_or_make_actor_from_nickname("toto@domain.tld"))
|
2019-02-21 17:11:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search something by URL" do
|
|
|
|
with_mock ActivityPub,
|
2019-04-12 13:04:32 +00:00
|
|
|
fetch_object_from_url: fn "https://social.tcit.fr/users/tcit" -> {:ok, %Actor{id: 42}} end do
|
2019-09-08 22:52:49 +00:00
|
|
|
assert {:ok, %Page{total: 1, elements: [%Actor{id: 42}]}} ==
|
2020-08-05 14:44:08 +00:00
|
|
|
Search.search_actors(%{term: "https://social.tcit.fr/users/tcit"}, 1, 10, :Person)
|
2019-02-21 17:11:49 +00:00
|
|
|
|
2019-04-12 13:04:32 +00:00
|
|
|
assert_called(ActivityPub.fetch_object_from_url("https://social.tcit.fr/users/tcit"))
|
2019-02-21 17:11:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search actors" do
|
|
|
|
with_mock Actors,
|
2021-11-06 09:09:54 +00:00
|
|
|
search_actors: fn "toto", _options, 1, 10 ->
|
2019-09-08 22:52:49 +00:00
|
|
|
%Page{total: 1, elements: [%Actor{id: 42}]}
|
2019-04-12 13:04:32 +00:00
|
|
|
end do
|
|
|
|
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} =
|
2020-08-05 14:44:08 +00:00
|
|
|
Search.search_actors(%{term: "toto"}, 1, 10, :Person)
|
2019-04-12 13:04:32 +00:00
|
|
|
|
2020-08-05 14:44:08 +00:00
|
|
|
assert_called(
|
2021-11-06 09:09:54 +00:00
|
|
|
Actors.search_actors(
|
2020-12-17 14:25:58 +00:00
|
|
|
"toto",
|
2021-11-06 09:09:54 +00:00
|
|
|
[
|
|
|
|
actor_type: :Person,
|
|
|
|
radius: nil,
|
|
|
|
location: nil,
|
2022-09-21 06:32:42 +00:00
|
|
|
bbox: nil,
|
2021-11-06 09:09:54 +00:00
|
|
|
minimum_visibility: :public,
|
|
|
|
current_actor_id: nil,
|
2022-04-01 14:48:46 +00:00
|
|
|
exclude_my_groups: false,
|
|
|
|
exclude_stale_actors: true
|
2021-11-06 09:09:54 +00:00
|
|
|
],
|
2020-12-17 14:25:58 +00:00
|
|
|
1,
|
|
|
|
10
|
|
|
|
)
|
2020-08-05 14:44:08 +00:00
|
|
|
)
|
2019-02-21 17:11:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search events" do
|
|
|
|
with_mock Events,
|
2020-08-05 10:08:52 +00:00
|
|
|
build_events_for_search: fn %{term: "toto"}, 1, 10 ->
|
2019-09-08 22:52:49 +00:00
|
|
|
%Page{total: 1, elements: [%Event{title: "super toto event"}]}
|
2019-04-12 13:04:32 +00:00
|
|
|
end do
|
|
|
|
assert {:ok, %{total: 1, elements: [%Event{title: "super toto event"}]}} =
|
2020-08-05 10:08:52 +00:00
|
|
|
Search.search_events(%{term: "toto"}, 1, 10)
|
2019-04-12 13:04:32 +00:00
|
|
|
|
2020-08-05 10:08:52 +00:00
|
|
|
assert_called(Events.build_events_for_search(%{term: "toto"}, 1, 10))
|
2019-02-21 17:11:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|