Add ability to search on Group, Person or Event

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Chocobozzz
2019-04-12 15:04:32 +02:00
committed by Thomas Citharel
parent 20a4f7244c
commit d66bbc5414
10 changed files with 385 additions and 173 deletions

View File

@@ -12,44 +12,45 @@ defmodule MobilizonWeb.API.SearchTest do
test "search an user by username" do
with_mock ActivityPub,
find_or_make_actor_from_nickname: fn "toto@domain.tld" -> {:ok, %Actor{id: 1}} end do
assert {:ok, %Actor{id: 1}} == Search.search("toto@domain.tld")
find_or_make_actor_from_nickname: fn "toto@domain.tld" -> {:ok, %Actor{id: 42}} end do
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} ==
Search.search_actors("toto@domain.tld", 1, 10, :Person)
assert_called(ActivityPub.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: 1}} end do
assert {:ok, %Actor{id: 1}} == Search.search("https://social.tcit.fr/users/tcit")
assert_called(ActivityPub.fetch_object_from_url("https://social.tcit.fr/users/tcit"))
end
end
fetch_object_from_url: fn "https://social.tcit.fr/users/tcit" -> {:ok, %Actor{id: 42}} end do
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} ==
Search.search_actors("https://social.tcit.fr/users/tcit", 1, 10, :Person)
test "search everything" do
with_mocks([
{Actors, [], [find_actors_by_username_or_name: fn "toto", 1, 10 -> [%Actor{}] end]},
{Events, [], [find_events_by_name: fn "toto", 1, 10 -> [%Event{}] end]}
]) do
assert {:ok, [%Event{}, %Actor{}]} = Search.search("toto")
assert_called(Actors.find_actors_by_username_or_name("toto", 1, 10))
assert_called(Events.find_events_by_name("toto", 1, 10))
assert_called(ActivityPub.fetch_object_from_url("https://social.tcit.fr/users/tcit"))
end
end
test "search actors" do
with_mock Actors,
find_actors_by_username_or_name: fn "toto", 1, 10 -> [%Actor{}] end do
assert {:ok, [%Actor{}]} = Search.search_actors("toto")
assert_called(Actors.find_actors_by_username_or_name("toto", 1, 10))
find_and_count_actors_by_username_or_name: fn "toto", _type, 1, 10 ->
%{total: 1, elements: [%Actor{id: 42}]}
end do
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} =
Search.search_actors("toto", 1, 10, :Person)
assert_called(Actors.find_and_count_actors_by_username_or_name("toto", [:Person], 1, 10))
end
end
test "search events" do
with_mock Events,
find_events_by_name: fn "toto", 1, 10 -> [%Event{}] end do
assert {:ok, [%Event{}]} = Search.search_events("toto")
assert_called(Events.find_events_by_name("toto", 1, 10))
find_and_count_events_by_name: fn "toto", 1, 10 ->
%{total: 1, elements: [%Event{title: "super toto event"}]}
end do
assert {:ok, %{total: 1, elements: [%Event{title: "super toto event"}]}} =
Search.search_events("toto", 1, 10)
assert_called(Events.find_and_count_events_by_name("toto", 1, 10))
end
end
end