Refactoring of Actors context
This commit is contained in:
@@ -6,6 +6,8 @@ defmodule MobilizonWeb.API.SearchTest do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Storage.Page
|
||||
|
||||
alias MobilizonWeb.API.Search
|
||||
|
||||
import Mock
|
||||
@@ -13,7 +15,7 @@ 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: 42}} end do
|
||||
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} ==
|
||||
assert {:ok, %Page{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"))
|
||||
@@ -23,7 +25,7 @@ defmodule MobilizonWeb.API.SearchTest do
|
||||
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
|
||||
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} ==
|
||||
assert {:ok, %Page{total: 1, elements: [%Actor{id: 42}]}} ==
|
||||
Search.search_actors("https://social.tcit.fr/users/tcit", 1, 10, :Person)
|
||||
|
||||
assert_called(ActivityPub.fetch_object_from_url("https://social.tcit.fr/users/tcit"))
|
||||
@@ -32,20 +34,20 @@ defmodule MobilizonWeb.API.SearchTest do
|
||||
|
||||
test "search actors" do
|
||||
with_mock Actors,
|
||||
find_and_count_actors_by_username_or_name: fn "toto", _type, 1, 10 ->
|
||||
%{total: 1, elements: [%Actor{id: 42}]}
|
||||
build_actors_by_username_or_name_page: fn "toto", _type, 1, 10 ->
|
||||
%Page{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))
|
||||
assert_called(Actors.build_actors_by_username_or_name_page("toto", [:Person], 1, 10))
|
||||
end
|
||||
end
|
||||
|
||||
test "search events" do
|
||||
with_mock Events,
|
||||
find_and_count_events_by_name: fn "toto", 1, 10 ->
|
||||
%{total: 1, elements: [%Event{title: "super toto event"}]}
|
||||
%Page{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)
|
||||
|
||||
@@ -177,7 +177,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
test "it returns the followers in a collection", %{conn: conn} do
|
||||
actor = insert(:actor, visibility: :public)
|
||||
actor2 = insert(:actor)
|
||||
Actor.follow(actor, actor2)
|
||||
Actors.follow(actor, actor2)
|
||||
|
||||
result =
|
||||
conn
|
||||
@@ -190,7 +190,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
test "it returns no followers for a private actor", %{conn: conn} do
|
||||
actor = insert(:actor, visibility: :private)
|
||||
actor2 = insert(:actor)
|
||||
Actor.follow(actor, actor2)
|
||||
Actors.follow(actor, actor2)
|
||||
|
||||
result =
|
||||
conn
|
||||
@@ -205,7 +205,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
|
||||
Enum.each(1..15, fn _ ->
|
||||
other_actor = insert(:actor)
|
||||
Actor.follow(actor, other_actor)
|
||||
Actors.follow(actor, other_actor)
|
||||
end)
|
||||
|
||||
result =
|
||||
@@ -229,7 +229,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
test "it returns the followings in a collection", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
actor2 = insert(:actor, visibility: :public)
|
||||
Actor.follow(actor, actor2)
|
||||
Actors.follow(actor, actor2)
|
||||
|
||||
result =
|
||||
conn
|
||||
@@ -242,7 +242,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
test "it returns no followings for a private actor", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
actor2 = insert(:actor, visibility: :private)
|
||||
Actor.follow(actor, actor2)
|
||||
Actors.follow(actor, actor2)
|
||||
|
||||
result =
|
||||
conn
|
||||
@@ -257,7 +257,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
|
||||
Enum.each(1..15, fn _ ->
|
||||
other_actor = insert(:actor)
|
||||
Actor.follow(other_actor, actor)
|
||||
Actors.follow(other_actor, actor)
|
||||
end)
|
||||
|
||||
result =
|
||||
@@ -322,7 +322,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# actor = Repo.get(Actor, actor.id)
|
||||
# other_actor = insert(:actor)
|
||||
# Actor.follow(actor, other_actor)
|
||||
# Actors.follow(actor, other_actor)
|
||||
# end)
|
||||
|
||||
# result =
|
||||
|
||||
Reference in New Issue
Block a user