2019-02-21 18:11:49 +01:00
|
|
|
defmodule MobilizonWeb.API.SearchTest do
|
|
|
|
use ExUnit.Case, async: false
|
|
|
|
|
2019-09-22 16:26:23 +02:00
|
|
|
import Mock
|
|
|
|
|
2019-02-21 18:11:49 +01:00
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-22 16:26:23 +02:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Events.Event
|
2019-02-21 18:11:49 +01:00
|
|
|
alias Mobilizon.Service.ActivityPub
|
2019-09-09 00:52:49 +02:00
|
|
|
alias Mobilizon.Storage.Page
|
|
|
|
|
2019-02-21 18:11:49 +01:00
|
|
|
alias MobilizonWeb.API.Search
|
|
|
|
|
|
|
|
test "search an user by username" do
|
|
|
|
with_mock ActivityPub,
|
2019-04-12 15:04:32 +02:00
|
|
|
find_or_make_actor_from_nickname: fn "toto@domain.tld" -> {:ok, %Actor{id: 42}} end do
|
2019-09-09 00:52:49 +02:00
|
|
|
assert {:ok, %Page{total: 1, elements: [%Actor{id: 42}]}} ==
|
2019-04-12 15:04:32 +02:00
|
|
|
Search.search_actors("toto@domain.tld", 1, 10, :Person)
|
|
|
|
|
2019-02-21 18:11:49 +01:00
|
|
|
assert_called(ActivityPub.find_or_make_actor_from_nickname("toto@domain.tld"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search something by URL" do
|
|
|
|
with_mock ActivityPub,
|
2019-04-12 15:04:32 +02:00
|
|
|
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}]}} ==
|
2019-04-12 15:04:32 +02:00
|
|
|
Search.search_actors("https://social.tcit.fr/users/tcit", 1, 10, :Person)
|
2019-02-21 18:11:49 +01:00
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert_called(ActivityPub.fetch_object_from_url("https://social.tcit.fr/users/tcit"))
|
2019-02-21 18:11:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search actors" do
|
|
|
|
with_mock Actors,
|
2019-09-09 00:52:49 +02:00
|
|
|
build_actors_by_username_or_name_page: fn "toto", _type, 1, 10 ->
|
|
|
|
%Page{total: 1, elements: [%Actor{id: 42}]}
|
2019-04-12 15:04:32 +02:00
|
|
|
end do
|
|
|
|
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} =
|
|
|
|
Search.search_actors("toto", 1, 10, :Person)
|
|
|
|
|
2019-09-09 00:52:49 +02:00
|
|
|
assert_called(Actors.build_actors_by_username_or_name_page("toto", [:Person], 1, 10))
|
2019-02-21 18:11:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search events" do
|
|
|
|
with_mock Events,
|
2019-10-22 10:25:28 +02:00
|
|
|
build_events_for_search: fn "toto", 1, 10 ->
|
2019-09-09 00:52:49 +02:00
|
|
|
%Page{total: 1, elements: [%Event{title: "super toto event"}]}
|
2019-04-12 15:04:32 +02:00
|
|
|
end do
|
|
|
|
assert {:ok, %{total: 1, elements: [%Event{title: "super toto event"}]}} =
|
|
|
|
Search.search_events("toto", 1, 10)
|
|
|
|
|
2019-10-22 10:25:28 +02:00
|
|
|
assert_called(Events.build_events_for_search("toto", 1, 10))
|
2019-02-21 18:11:49 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|