Refactor Mobilizon.Federation.ActivityPub and add typespecs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -16,7 +16,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
alias Mobilizon.Todos.{Todo, TodoList}
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.Utils
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Utils}
|
||||
alias Mobilizon.Federation.HTTPSignatures.Signature
|
||||
alias Mobilizon.Service.HTTP.ActivityPub.Mock
|
||||
|
||||
@@ -117,7 +117,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
test "it creates a delete activity and deletes the original event" do
|
||||
event = insert(:event)
|
||||
event = Events.get_public_event_by_url_with_preload!(event.url)
|
||||
{:ok, delete, _} = ActivityPub.delete(event, event.organizer_actor)
|
||||
{:ok, delete, _} = Actions.Delete.delete(event, event.organizer_actor)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == event.organizer_actor.url
|
||||
@@ -133,7 +133,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
lazy_put_activity_defaults: fn args -> args end do
|
||||
event = insert(:event)
|
||||
event = Events.get_public_event_by_url_with_preload!(event.url)
|
||||
{:ok, delete, _} = ActivityPub.delete(event, event.organizer_actor, false)
|
||||
{:ok, delete, _} = Actions.Delete.delete(event, event.organizer_actor, false)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == event.organizer_actor.url
|
||||
@@ -151,7 +151,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
comment = insert(:comment)
|
||||
comment = Discussions.get_comment_from_url_with_preload!(comment.url)
|
||||
assert is_nil(Discussions.get_comment_from_url(comment.url).deleted_at)
|
||||
{:ok, delete, _} = ActivityPub.delete(comment, comment.actor)
|
||||
{:ok, delete, _} = Actions.Delete.delete(comment, comment.actor)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == comment.actor.url
|
||||
@@ -169,7 +169,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
actor = insert(:actor)
|
||||
actor_data = %{summary: @updated_actor_summary}
|
||||
|
||||
{:ok, update, _} = ActivityPub.update(actor, actor_data, false)
|
||||
{:ok, update, _} = Actions.Update.update(actor, actor_data, false)
|
||||
|
||||
assert update.data["actor"] == actor.url
|
||||
assert update.data["to"] == [@activity_pub_public_audience]
|
||||
@@ -185,7 +185,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
event_data = %{begins_on: @updated_start_time}
|
||||
|
||||
{:ok, update, _} = ActivityPub.update(event, event_data)
|
||||
{:ok, update, _} = Actions.Update.update(event, event_data)
|
||||
|
||||
assert update.data["actor"] == actor.url
|
||||
assert update.data["to"] == [@activity_pub_public_audience]
|
||||
@@ -200,7 +200,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
group = insert(:group)
|
||||
member = insert(:member, parent: group)
|
||||
moderator = insert(:actor)
|
||||
{:ok, activity, _member} = ActivityPub.remove(member, group, moderator, true)
|
||||
{:ok, activity, _member} = Actions.Remove.remove(member, group, moderator, true)
|
||||
assert activity.data["type"] == "Remove"
|
||||
assert activity.data["actor"] == moderator.url
|
||||
assert activity.data["to"] == [group.members_url]
|
||||
@@ -217,9 +217,14 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
group = insert(:group)
|
||||
|
||||
{:ok, create_data, %TodoList{url: todo_list_url}} =
|
||||
ActivityPub.create(:todo_list, %{title: @todo_list_title, actor_id: group.id}, true, %{
|
||||
"actor" => actor.url
|
||||
})
|
||||
Actions.Create.create(
|
||||
:todo_list,
|
||||
%{title: @todo_list_title, actor_id: group.id},
|
||||
true,
|
||||
%{
|
||||
"actor" => actor.url
|
||||
}
|
||||
)
|
||||
|
||||
assert create_data.local
|
||||
assert create_data.data["object"]["id"] == todo_list_url
|
||||
@@ -242,7 +247,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
todo_list = insert(:todo_list)
|
||||
|
||||
{:ok, create_data, %Todo{url: todo_url}} =
|
||||
ActivityPub.create(
|
||||
Actions.Create.create(
|
||||
:todo,
|
||||
%{title: @todo_title, todo_list_id: todo_list.id, creator_id: actor.id},
|
||||
true,
|
||||
@@ -272,7 +277,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
group = insert(:group)
|
||||
|
||||
{:ok, create_data, %Resource{url: url}} =
|
||||
ActivityPub.create(
|
||||
Actions.Create.create(
|
||||
:resource,
|
||||
%{
|
||||
title: @resource_title,
|
||||
@@ -307,7 +312,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
group = insert(:group)
|
||||
|
||||
{:ok, create_data, %Resource{url: url}} =
|
||||
ActivityPub.create(
|
||||
Actions.Create.create(
|
||||
:resource,
|
||||
%{
|
||||
title: @folder_title,
|
||||
@@ -341,7 +346,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
insert(:resource, type: :folder, resource_url: nil, actor: group)
|
||||
|
||||
{:ok, create_data, %Resource{url: url}} =
|
||||
ActivityPub.create(
|
||||
Actions.Create.create(
|
||||
:resource,
|
||||
%{
|
||||
title: @resource_title,
|
||||
@@ -388,7 +393,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
)
|
||||
|
||||
{:ok, update_data, %Resource{url: url}} =
|
||||
ActivityPub.update(
|
||||
Actions.Update.update(
|
||||
resource,
|
||||
%{
|
||||
title: @updated_resource_title
|
||||
@@ -430,7 +435,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
insert(:resource, type: :folder, resource_url: nil, actor: group)
|
||||
|
||||
{:ok, update_data, %Resource{url: url}} =
|
||||
ActivityPub.move(
|
||||
Actions.Move.move(
|
||||
:resource,
|
||||
resource,
|
||||
%{
|
||||
@@ -473,7 +478,7 @@ defmodule Mobilizon.Federation.ActivityPubTest do
|
||||
)
|
||||
|
||||
{:ok, update_data, %Resource{url: url}} =
|
||||
ActivityPub.delete(
|
||||
Actions.Delete.delete(
|
||||
resource,
|
||||
actor,
|
||||
true
|
||||
|
||||
@@ -6,7 +6,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Follower
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier}
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Activity, Transmogrifier}
|
||||
|
||||
describe "handle incoming follow requests" do
|
||||
test "it works only for groups" do
|
||||
@@ -80,7 +80,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
|
||||
refute Actors.is_following(follower, followed)
|
||||
|
||||
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
||||
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
|
||||
assert Actors.is_following(follower, followed)
|
||||
|
||||
follow_object_id = follow_activity.data["id"]
|
||||
@@ -112,7 +112,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
|
||||
refute Actors.is_following(follower, followed)
|
||||
|
||||
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
||||
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
|
||||
assert Actors.is_following(follower, followed)
|
||||
|
||||
follow_object_id = follow_activity.data["id"]
|
||||
@@ -145,7 +145,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
follower = insert(:actor)
|
||||
followed = insert(:group, manually_approves_followers: true)
|
||||
|
||||
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
||||
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
@@ -207,7 +207,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
|
||||
follower = insert(:actor)
|
||||
followed = insert(:group)
|
||||
|
||||
{:ok, follow_activity, _} = ActivityPub.follow(follower, followed)
|
||||
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
|
||||
|
||||
assert Actors.is_following(follower, followed)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.JoinTest do
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.Transmogrifier
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Transmogrifier}
|
||||
|
||||
describe "handle incoming join activities" do
|
||||
@join_message "I want to get in!"
|
||||
@@ -48,7 +48,9 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.JoinTest do
|
||||
%Event{} = event = insert(:event, organizer_actor: organizer, join_options: :restricted)
|
||||
|
||||
{:ok, join_activity, participation} =
|
||||
ActivityPub.join(event, participant_actor, false, %{metadata: %{role: :not_approved}})
|
||||
Actions.Join.join(event, participant_actor, false, %{
|
||||
metadata: %{role: :not_approved}
|
||||
})
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
@@ -113,7 +115,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.JoinTest do
|
||||
|
||||
%Event{} = event = insert(:event, organizer_actor: organizer, join_options: :restricted)
|
||||
|
||||
{:ok, join_activity, participation} = ActivityPub.join(event, participant_actor)
|
||||
{:ok, join_activity, participation} = Actions.Join.join(event, participant_actor)
|
||||
|
||||
reject_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|
||||
@@ -5,8 +5,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.LeaveTest do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Federation.ActivityPub
|
||||
alias Mobilizon.Federation.ActivityPub.Transmogrifier
|
||||
alias Mobilizon.Federation.ActivityPub.{Actions, Transmogrifier}
|
||||
|
||||
describe "handle incoming leave activities on events" do
|
||||
test "it accepts Leave activities" do
|
||||
@@ -19,7 +18,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.LeaveTest do
|
||||
organizer_participation =
|
||||
%Participant{} = insert(:participant, event: event, actor: organizer, role: :creator)
|
||||
|
||||
{:ok, _join_activity, _participation} = ActivityPub.join(event, participant_actor)
|
||||
{:ok, _join_activity, _participation} = Actions.Join.join(event, participant_actor)
|
||||
|
||||
join_data =
|
||||
File.read!("test/fixtures/mobilizon-leave-activity.json")
|
||||
|
||||
@@ -57,7 +57,7 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"A group with this name already exists"
|
||||
"A profile or group with that name already exists"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -598,7 +598,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ResourceTest do
|
||||
}
|
||||
)
|
||||
|
||||
assert is_nil(res["errors"])
|
||||
assert res["errors"] == nil
|
||||
|
||||
assert res["data"]["updateResource"]["path"] ==
|
||||
"#{root_folder.path}/#{@updated_resource_title}"
|
||||
|
||||
Reference in New Issue
Block a user