More tests?
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
8221504ecb
commit
7ea96a1f56
4 changed files with 234 additions and 1 deletions
80
test/fixtures/tesla_mock/mobilizon-event-join-accept.json
vendored
Normal file
80
test/fixtures/tesla_mock/mobilizon-event-join-accept.json
vendored
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
%{
|
||||||
|
"@context" => [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
%{
|
||||||
|
"addressRegion" => "sc:addressRegion",
|
||||||
|
"timezone" => %{"@id" => "mz:timezone", "@type" => "sc:Text"},
|
||||||
|
"isOnline" => %{"@id" => "mz:isOnline", "@type" => "sc:Boolean"},
|
||||||
|
"pt" => "https://joinpeertube.org/ns#",
|
||||||
|
"manuallyApprovesFollowers" => "as:manuallyApprovesFollowers",
|
||||||
|
"inLanguage" => "sc:inLanguage",
|
||||||
|
"address" => %{"@id" => "sc:address", "@type" => "sc:PostalAddress"},
|
||||||
|
"discoverable" => "toot:discoverable",
|
||||||
|
"repliesModerationOption" => %{
|
||||||
|
"@id" => "mz:repliesModerationOption",
|
||||||
|
"@type" => "mz:repliesModerationOptionType"
|
||||||
|
},
|
||||||
|
"sc" => "http://schema.org#",
|
||||||
|
"mz" => "https://joinmobilizon.org/ns#",
|
||||||
|
"category" => "sc:category",
|
||||||
|
"joinModeType" => %{"@id" => "mz:joinModeType", "@type" => "rdfs:Class"},
|
||||||
|
"Hashtag" => "as:Hashtag",
|
||||||
|
"propertyID" => "sc:propertyID",
|
||||||
|
"PostalAddress" => "sc:PostalAddress",
|
||||||
|
"discussions" => %{"@id" => "mz:discussions", "@type" => "@id"},
|
||||||
|
"remainingAttendeeCapacity" => "sc:remainingAttendeeCapacity",
|
||||||
|
"streetAddress" => "sc:streetAddress",
|
||||||
|
"anonymousParticipationEnabled" => %{
|
||||||
|
"@id" => "mz:anonymousParticipationEnabled",
|
||||||
|
"@type" => "sc:Boolean"
|
||||||
|
},
|
||||||
|
"addressLocality" => "sc:addressLocality",
|
||||||
|
"joinMode" => %{"@id" => "mz:joinMode", "@type" => "mz:joinModeType"},
|
||||||
|
"location" => %{"@id" => "sc:location", "@type" => "sc:Place"},
|
||||||
|
"toot" => "http://joinmastodon.org/ns#",
|
||||||
|
"participantCount" => %{
|
||||||
|
"@id" => "mz:participantCount",
|
||||||
|
"@type" => "sc:Integer"
|
||||||
|
},
|
||||||
|
"uuid" => "sc:identifier",
|
||||||
|
"maximumAttendeeCapacity" => "sc:maximumAttendeeCapacity",
|
||||||
|
"participationMessage" => %{
|
||||||
|
"@id" => "mz:participationMessage",
|
||||||
|
"@type" => "sc:Text"
|
||||||
|
},
|
||||||
|
"openness" => %{"@id" => "mz:openness", "@type" => "@id"},
|
||||||
|
"members" => %{"@id" => "mz:members", "@type" => "@id"},
|
||||||
|
"events" => %{"@id" => "mz:events", "@type" => "@id"},
|
||||||
|
"resources" => %{"@id" => "mz:resources", "@type" => "@id"},
|
||||||
|
"addressCountry" => "sc:addressCountry",
|
||||||
|
"posts" => %{"@id" => "mz:posts", "@type" => "@id"},
|
||||||
|
"commentsEnabled" => %{
|
||||||
|
"@id" => "pt:commentsEnabled",
|
||||||
|
"@type" => "sc:Boolean"
|
||||||
|
},
|
||||||
|
"value" => "sc:value",
|
||||||
|
"PropertyValue" => "sc:PropertyValue",
|
||||||
|
"repliesModerationOptionType" => %{
|
||||||
|
"@id" => "mz:repliesModerationOptionType",
|
||||||
|
"@type" => "rdfs:Class"
|
||||||
|
},
|
||||||
|
"todos" => %{"@id" => "mz:todos", "@type" => "@id"},
|
||||||
|
"ical" => "http://www.w3.org/2002/12/cal/ical#",
|
||||||
|
"postalCode" => "sc:postalCode",
|
||||||
|
"memberCount" => %{"@id" => "mz:memberCount", "@type" => "sc:Integer"},
|
||||||
|
"@language" => "und"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actor" => "https://mobilizon.org/@tcit",
|
||||||
|
"id" => "https://mobilizon.mkljczk.pl/accept/join/fef2a925-cce5-4b8e-b12f-20afe01e5a0f",
|
||||||
|
"object" => %{
|
||||||
|
"actor" => "https://pleroma.mkljczk.pl/users/mkljczk",
|
||||||
|
"id" => "https://pleroma.mkljczk.pl/activities/7d1f3986-8b2c-48c2-b89e-d27ba8459777",
|
||||||
|
"object" => "https://mobilizon.mkljczk.pl/events/d9d08e46-81af-4ee9-91e5-1298f49beea9",
|
||||||
|
"participationMessage" => nil,
|
||||||
|
"published" => "2022-10-07T18:53:53Z",
|
||||||
|
"type" => "Join"
|
||||||
|
},
|
||||||
|
"type" => "Accept"
|
||||||
|
}
|
74
test/fixtures/tesla_mock/mobilizon-event-join.json
vendored
Normal file
74
test/fixtures/tesla_mock/mobilizon-event-join.json
vendored
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"addressRegion": "sc:addressRegion",
|
||||||
|
"timezone": { "@id": "mz:timezone", "@type": "sc:Text" },
|
||||||
|
"isOnline": { "@id": "mz:isOnline", "@type": "sc:Boolean" },
|
||||||
|
"pt": "https://joinpeertube.org/ns#",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"inLanguage": "sc:inLanguage",
|
||||||
|
"address": { "@id": "sc:address", "@type": "sc:PostalAddress" },
|
||||||
|
"discoverable": "toot:discoverable",
|
||||||
|
"repliesModerationOption": {
|
||||||
|
"@id": "mz:repliesModerationOption",
|
||||||
|
"@type": "mz:repliesModerationOptionType"
|
||||||
|
},
|
||||||
|
"sc": "http://schema.org#",
|
||||||
|
"mz": "https://joinmobilizon.org/ns#",
|
||||||
|
"category": "sc:category",
|
||||||
|
"joinModeType": { "@id": "mz:joinModeType", "@type": "rdfs:Class" },
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"propertyID": "sc:propertyID",
|
||||||
|
"PostalAddress": "sc:PostalAddress",
|
||||||
|
"discussions": { "@id": "mz:discussions", "@type": "@id" },
|
||||||
|
"remainingAttendeeCapacity": "sc:remainingAttendeeCapacity",
|
||||||
|
"streetAddress": "sc:streetAddress",
|
||||||
|
"anonymousParticipationEnabled": {
|
||||||
|
"@id": "mz:anonymousParticipationEnabled",
|
||||||
|
"@type": "sc:Boolean"
|
||||||
|
},
|
||||||
|
"addressLocality": "sc:addressLocality",
|
||||||
|
"joinMode": { "@id": "mz:joinMode", "@type": "mz:joinModeType" },
|
||||||
|
"location": { "@id": "sc:location", "@type": "sc:Place" },
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"participantCount": {
|
||||||
|
"@id": "mz:participantCount",
|
||||||
|
"@type": "sc:Integer"
|
||||||
|
},
|
||||||
|
"uuid": "sc:identifier",
|
||||||
|
"maximumAttendeeCapacity": "sc:maximumAttendeeCapacity",
|
||||||
|
"participationMessage": {
|
||||||
|
"@id": "mz:participationMessage",
|
||||||
|
"@type": "sc:Text"
|
||||||
|
},
|
||||||
|
"openness": { "@id": "mz:openness", "@type": "@id" },
|
||||||
|
"members": { "@id": "mz:members", "@type": "@id" },
|
||||||
|
"events": { "@id": "mz:events", "@type": "@id" },
|
||||||
|
"resources": { "@id": "mz:resources", "@type": "@id" },
|
||||||
|
"addressCountry": "sc:addressCountry",
|
||||||
|
"posts": { "@id": "mz:posts", "@type": "@id" },
|
||||||
|
"commentsEnabled": {
|
||||||
|
"@id": "pt:commentsEnabled",
|
||||||
|
"@type": "sc:Boolean"
|
||||||
|
},
|
||||||
|
"value": "sc:value",
|
||||||
|
"PropertyValue": "sc:PropertyValue",
|
||||||
|
"repliesModerationOptionType": {
|
||||||
|
"@id": "mz:repliesModerationOptionType",
|
||||||
|
"@type": "rdfs:Class"
|
||||||
|
},
|
||||||
|
"todos": { "@id": "mz:todos", "@type": "@id" },
|
||||||
|
"ical": "http://www.w3.org/2002/12/cal/ical#",
|
||||||
|
"postalCode": "sc:postalCode",
|
||||||
|
"memberCount": { "@id": "mz:memberCount", "@type": "sc:Integer" },
|
||||||
|
"@language": "und"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actor": "https://mobilizon.org/@tcit",
|
||||||
|
"id": "https://mobilizon.mkljczk.pl/join/event/d1828aac-b57f-43c9-ac87-17388fab2bc8",
|
||||||
|
"object": "https://pleroma.mkljczk.pl/objects/b800bdb9-2cbb-40b6-9b29-196cfbd42398",
|
||||||
|
"participationMessage": null,
|
||||||
|
"type": "Join"
|
||||||
|
}
|
|
@ -40,6 +40,5 @@ test "Mobilizon Event object" do
|
||||||
assert object.data["name"] == "Mobilizon Launching Party"
|
assert object.data["name"] == "Mobilizon Launching Party"
|
||||||
assert object.data["startTime"] == "2019-12-18T13:00:00Z"
|
assert object.data["startTime"] == "2019-12-18T13:00:00Z"
|
||||||
assert object.data["endTime"] == "2019-12-18T14:00:00Z"
|
assert object.data["endTime"] == "2019-12-18T14:00:00Z"
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.JoinHandlingTest do
|
||||||
|
use Pleroma.DataCase
|
||||||
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Notification
|
||||||
|
alias Pleroma.Object
|
||||||
|
alias Pleroma.Repo
|
||||||
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||||
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
|
|
||||||
|
import Pleroma.Factory
|
||||||
|
import Ecto.Query
|
||||||
|
import Mock
|
||||||
|
|
||||||
|
setup_all do
|
||||||
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "handle_incoming" do
|
||||||
|
test "it works for incoming Mobilizon joins" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
event = insert(:event)
|
||||||
|
|
||||||
|
join_data =
|
||||||
|
File.read!("test/fixtures/tesla_mock/mobilizon-event-join.json")
|
||||||
|
|> Jason.decode!()
|
||||||
|
|> Map.put("actor", user.ap_id)
|
||||||
|
|> Map.put("object", event.data["id"])
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false} = activity} =
|
||||||
|
Transmogrifier.handle_incoming(join_data)
|
||||||
|
|
||||||
|
event = Object.get_by_id(event.id)
|
||||||
|
|
||||||
|
assert event.data["participations"] == [join_data["actor"]]
|
||||||
|
|
||||||
|
activity = Repo.get(Activity, activity.id)
|
||||||
|
assert activity.data["state"] == "accept"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "with restricted events, it does create a Join, but not an Accept" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
event = insert(:event, %{data: %{"joinMode" => "restricted"}})
|
||||||
|
|
||||||
|
join_data =
|
||||||
|
File.read!("test/fixtures/tesla_mock/mobilizon-event-join.json")
|
||||||
|
|> Jason.decode!()
|
||||||
|
|> Map.put("actor", user.ap_id)
|
||||||
|
|> Map.put("object", event.data["id"])
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false} = activity} =
|
||||||
|
Transmogrifier.handle_incoming(join_data)
|
||||||
|
|
||||||
|
event = Object.get_by_id(event.id)
|
||||||
|
|
||||||
|
assert event.data["participations"] == nil
|
||||||
|
|
||||||
|
assert data["state"] == "pending"
|
||||||
|
|
||||||
|
accepts =
|
||||||
|
from(
|
||||||
|
a in Activity,
|
||||||
|
where: fragment("?->>'type' = ?", a.data, "Accept")
|
||||||
|
)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
|
assert Enum.empty?(accepts)
|
||||||
|
|
||||||
|
[notification] = Notification.for_user(user)
|
||||||
|
assert notification.type == "pleroma:participation_request"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue