From c15123e5ea5eb8116a8cde62b692a0bcd011fa2d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 10 Nov 2021 16:41:01 +0100 Subject: [PATCH] Add tests for Gancio compatibility Signed-off-by: Thomas Citharel --- .../activity_pub/transmogrifier_test.exs | 37 ++++++++++++++++ test/fixtures/gancio-event-activity.json | 42 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 test/fixtures/gancio-event-activity.json diff --git a/test/federation/activity_pub/transmogrifier_test.exs b/test/federation/activity_pub/transmogrifier_test.exs index 841b54f9..8e226754 100644 --- a/test/federation/activity_pub/transmogrifier_test.exs +++ b/test/federation/activity_pub/transmogrifier_test.exs @@ -79,6 +79,43 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do end end + test "it works for incoming events from Gancio" do + data = File.read!("test/fixtures/gancio-event-activity.json") |> Jason.decode!() + + {:ok, %Activity{data: data, local: false}, %Event{} = event} = + Transmogrifier.handle_incoming(data) + + assert data["id"] == "https://demo.gancio.org/federation/m/1/activity" + + assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"] + + # assert data["cc"] == [nil] + + assert data["actor"] == "https://demo.gancio.org/federation/u/gancio" + + object = data["object"] + + assert object["id"] == + "https://demo.gancio.org/federation/m/1" + + assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"] + + assert object["cc"] == [] + + assert object["actor"] == "https://demo.gancio.org/federation/u/gancio" + assert object["location"]["name"] == "Colosseo" + assert object["attributedTo"] == "https://demo.gancio.org/federation/u/gancio" + + assert event.title == "Demo event" + assert event.begins_on == ~U[2021-07-14 15:30:57Z] + assert event.ends_on == ~U[2021-07-14 16:30:57Z] + assert event.picture.file.content_type == "image/jpeg" + assert event.picture.file.name == "unknown.jpg" + assert length(event.tags) == 1 + assert hd(event.tags).title == "test" + assert event.physical_address.description == "Colosseo" + end + test "it works for incoming events for local groups" do %Actor{url: group_url, id: group_id} = group = insert(:group) diff --git a/test/fixtures/gancio-event-activity.json b/test/fixtures/gancio-event-activity.json new file mode 100644 index 00000000..e7a02e7e --- /dev/null +++ b/test/fixtures/gancio-event-activity.json @@ -0,0 +1,42 @@ +{ + "id": "https://demo.gancio.org/federation/m/1#create", + "type": "Create", + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "cc": ["https://demo.gancio.org/federation/u/gancio/followers"], + "published": "2021-07-01T22:33:36Z", + "actor": "https://demo.gancio.org/federation/u/gancio", + "object": { + "id": "https://demo.gancio.org/federation/m/1", + "name": "Demo event", + "url": "https://demo.gancio.org/event/demo-event", + "type": "Event", + "startTime": "2021-07-14T17:30:57+02:00", + "endTime": "2021-07-14T18:30:57+02:00", + "location": { + "name": "Colosseo" + }, + "attachment": [ + { + "type": "Document", + "mediaType": "image/jpeg", + "url": "https://demo.gancio.org/media/7215892e7326a9b326b6bcad5b57642e.jpg", + "name": "", + "blurHash": null, + "focalPoint": [0, 0] + } + ], + "tag": [ + { + "type": "Hashtag", + "name": "#test", + "href": "/tags/test" + } + ], + "published": "2021-07-01T22:33:36Z", + "attributedTo": "https://demo.gancio.org/federation/u/gancio", + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "cc": ["https://demo.gancio.org/federation/u/gancio/followers"], + "content": "\n 📍 Colosseo\n 📅 Wednesday, 14 July (17:30)\n\n \n ", + "summary": "\n 📍 Colosseo\n 📅 Wednesday, 14 July (17:30)\n\n \n " + } +}