Add more events tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-07-30 17:30:38 +02:00
parent 630de6fee9
commit 25789f8f6d
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -5,7 +5,8 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do
alias Mobilizon.Actors.Actor alias Mobilizon.Actors.Actor
alias Mobilizon.Events alias Mobilizon.Events
alias Mobilizon.Events.Event alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Federation.ActivityPub.Activity
alias Mobilizon.Federation.ActivityPub.Types.Events alias Mobilizon.Federation.ActivityPub.Types.Events
@ap_public "https://www.w3.org/ns/activitystreams#Public" @ap_public "https://www.w3.org/ns/activitystreams#Public"
@ -266,5 +267,174 @@ defmodule Mobilizon.Federation.ActivityPub.Types.EventsTest do
data data
) )
end end
test "from a remote group member" do
%Actor{id: organizer_actor_1_id, url: actor_1_url} = actor_1 = insert(:actor)
%Actor{} = actor_2 = insert(:actor)
%Actor{
url: group_url,
followers_url: followers_url,
members_url: members_url
} = group = insert(:group, domain: "somewhere.else", url: "https://somewhere.else/@someone")
insert(:member, parent: group, actor: actor_1, role: :moderator)
insert(:member, parent: group, actor: actor_2, role: :moderator)
{:ok, begins_on, _} = DateTime.from_iso8601(@event_begins_on)
%Event{} =
event =
insert(:event, organizer_actor: actor_2, begins_on: begins_on, attributed_to: group)
assert {:ok, %Event{}, data} =
Events.update(
event,
Map.merge(@event_update_data, %{
organizer_actor_id: organizer_actor_1_id
}),
%{}
)
assert match?(
%{
"actor" => ^actor_1_url,
"attributedTo" => ^group_url,
"cc" => [^members_url, ^followers_url],
"object" => %{
"actor" => ^actor_1_url,
"anonymousParticipationEnabled" => false,
"attributedTo" => ^group_url,
"cc" => [],
"commentsEnabled" => false,
"draft" => false,
"ical:status" => "CONFIRMED",
"joinMode" => "free",
"maximumAttendeeCapacity" => nil,
"mediaType" => "text/html",
"name" => @event_updated_title,
"repliesModerationOption" => nil,
"startTime" => @event_begins_on,
"tag" => [],
"to" => [@ap_public],
"type" => "Event"
},
"to" => [@ap_public],
"type" => "Update"
},
data
)
end
end
describe "join an event" do
test "simple and remote" do
%Actor{url: organizer_actor_url} =
organizer_actor = insert(:actor, domain: "somewhere.else")
%Actor{url: participant_actor_url} = actor = insert(:actor, domain: nil)
%Event{url: event_url} =
event = insert(:event, organizer_actor: organizer_actor, local: false)
assert {:ok, data, %Participant{}} = Events.join(event, actor, true, %{})
assert match?(
%{
"actor" => ^participant_actor_url,
"cc" => [],
"object" => ^event_url,
"participationMessage" => nil,
"to" => [^participant_actor_url, ^organizer_actor_url],
"type" => "Join"
},
data
)
end
test "simple and local" do
%Actor{url: organizer_actor_url} = organizer_actor = insert(:actor, domain: nil)
%Actor{url: participant_actor_url} = actor = insert(:actor, domain: nil)
%Event{url: event_url} = event = insert(:event, organizer_actor: organizer_actor)
assert {:accept, {:ok, %Activity{data: data, local: true}, %Participant{}}} =
Events.join(event, actor, true, %{})
assert match?(
%{
"actor" => ^organizer_actor_url,
"cc" => [],
"object" => %{
"actor" => ^participant_actor_url,
"object" => ^event_url,
"participationMessage" => nil,
"type" => "Join"
},
"to" => [^participant_actor_url, ^organizer_actor_url],
"type" => "Accept"
},
data
)
end
test "group event local" do
%Actor{url: organizer_group_url, members_url: members_url, followers_url: followers_url} =
organizer_group = insert(:group, domain: nil)
%Actor{url: participant_actor_url} = actor = insert(:actor, domain: nil)
%Event{url: event_url} = event = insert(:event, attributed_to: organizer_group)
assert {:ok, data, %Participant{}} = Events.join(event, actor, true, %{})
assert match?(
%{
"actor" => ^participant_actor_url,
"cc" => [^followers_url, ^members_url],
"object" => ^event_url,
"participationMessage" => nil,
"to" => [^participant_actor_url, ^organizer_group_url],
"type" => "Join"
},
data
)
end
test "group event with organizer remote" do
%Actor{url: organizer_group_url, members_url: members_url, followers_url: followers_url} =
organizer_group = insert(:group, domain: nil)
%Actor{url: organizer_actor_url} =
organizer_actor =
insert(:actor, domain: "somewhere.else", url: "https://somewhere.else/@someone")
insert(:member, parent: organizer_group, actor: organizer_actor, role: :moderator)
%Actor{url: participant_actor_url} = actor = insert(:actor, domain: nil)
%Event{url: event_url} =
event =
insert(:event,
attributed_to: organizer_group,
organizer_actor: organizer_actor,
local: true
)
assert {:ok, data, %Participant{}} = Events.join(event, actor, true, %{})
assert match?(
%{
"actor" => ^participant_actor_url,
"cc" => [^followers_url, ^members_url],
"object" => ^event_url,
"participationMessage" => nil,
"to" => [^participant_actor_url, ^organizer_group_url],
"type" => "Join"
},
data
)
end
end end
end end