mobilizon/test/graphql/api/search_test.exs

79 lines
2.4 KiB
Elixir
Raw Permalink Normal View History

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