From 10c2575091b1176ddd5ad70b7c40e1977537fd7a Mon Sep 17 00:00:00 2001 From: Hazel Koehler Date: Thu, 20 Jul 2023 22:10:39 -0400 Subject: [PATCH] Coalesce smoke test samples to remove duplicated logic * Sample JSON is now an embedded resource * Samples are grouped by software * Calckey renamed to Firefish * Serialization is also tested Part of #58. --- .../ActivityPub.Types.Tests.csproj | 5 + .../Smoke/Samples/CalckeyActorTests.cs | 113 -------- .../Smoke/Samples/CalckeyOutboxPageTests.cs | 271 ------------------ .../Smoke/Samples/CalckeyOutboxTests.cs | 80 ------ .../Samples/Firefish/FirefishSampleTests.cs | 22 ++ .../Samples/Firefish/OrderedCollection.jsonld | 35 +++ .../Firefish/OrderedCollectionPage.jsonld | 225 +++++++++++++++ .../Smoke/Samples/Firefish/Person.jsonld | 70 +++++ .../Smoke/Samples/SampleTests.cs | 51 ++++ 9 files changed, 408 insertions(+), 464 deletions(-) delete mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyActorTests.cs delete mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxPageTests.cs delete mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxTests.cs create mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/FirefishSampleTests.cs create mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollection.jsonld create mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollectionPage.jsonld create mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/Person.jsonld create mode 100644 Tests/ActivityPub.Types.Tests/Smoke/Samples/SampleTests.cs diff --git a/Tests/ActivityPub.Types.Tests/ActivityPub.Types.Tests.csproj b/Tests/ActivityPub.Types.Tests/ActivityPub.Types.Tests.csproj index e842c36..d4eb367 100644 --- a/Tests/ActivityPub.Types.Tests/ActivityPub.Types.Tests.csproj +++ b/Tests/ActivityPub.Types.Tests/ActivityPub.Types.Tests.csproj @@ -26,4 +26,9 @@ + + + + + diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyActorTests.cs b/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyActorTests.cs deleted file mode 100644 index e0ffd1f..0000000 --- a/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyActorTests.cs +++ /dev/null @@ -1,113 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using ActivityPub.Types.Extended.Actor; -using ActivityPub.Types.Internal.TypeInfo; -using ActivityPub.Types.Json; - -namespace ActivityPub.Types.Tests.Smoke.Samples; - -public class CalckeyActorTests -{ - private const string ActorJson = - """ - { - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - { - "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", - "movedToUri": "as:movedTo", - "sensitive": "as:sensitive", - "Hashtag": "as:Hashtag", - "quoteUri": "fedibird:quoteUri", - "quoteUrl": "as:quoteUrl", - "toot": "http://joinmastodon.org/ns#", - "Emoji": "toot:Emoji", - "featured": "toot:featured", - "discoverable": "toot:discoverable", - "schema": "http://schema.org#", - "PropertyValue": "schema:PropertyValue", - "value": "schema:value", - "misskey": "https://misskey-hub.net/ns#", - "_misskey_content": "misskey:_misskey_content", - "_misskey_quote": "misskey:_misskey_quote", - "_misskey_reaction": "misskey:_misskey_reaction", - "_misskey_votes": "misskey:_misskey_votes", - "_misskey_talk": "misskey:_misskey_talk", - "isCat": "misskey:isCat", - "fedibird": "http://fedibird.com/ns#", - "vcard": "http://www.w3.org/2006/vcard/ns#" - } - ], - "type": "Person", - "id": "https://enby.life/users/9fpnzspgtp", - "inbox": "https://enby.life/users/9fpnzspgtp/inbox", - "outbox": "https://enby.life/users/9fpnzspgtp/outbox", - "followers": "https://enby.life/users/9fpnzspgtp/followers", - "following": "https://enby.life/users/9fpnzspgtp/following", - "featured": "https://enby.life/users/9fpnzspgtp/collections/featured", - "sharedInbox": "https://enby.life/inbox", - "endpoints": { - "sharedInbox": "https://enby.life/inbox" - }, - "url": "https://enby.life/@admin", - "preferredUsername": "admin", - "name": "Enby Admin", - "summary": "

Instance admin - contact for info and technical support

", - "icon": { - "type": "Image", - "url": "https://enby.life/files/a15e1514-0c3a-48a1-8480-bb5b8e880cef", - "sensitive": false, - "name": null - }, - "image": null, - "tag": [], - "manuallyApprovesFollowers": false, - "discoverable": true, - "publicKey": { - "id": "https://enby.life/users/9fpnzspgtp#main-key", - "type": "Key", - "owner": "https://enby.life/users/9fpnzspgtp", - "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAux49fKZK3XxSActEu+Rm\nitMezjOHKhRnQXzbh/UX++nrIrxhk4DJiQSmeOSuoeO3YiwlA8fcgK6ZU8l6RYFp\nhjjVauueWMaB7mrOHCBK2QtY9kPvtyMVtM1lt1cnqbsBsZP7YNWYS+9oZKw0NOCU\nPuapmYhkS+eA1hpBEDDZ0WG74HzNUSlweFD2ssQGeNyy0lTI20LPCvHqfDHO3rI1\nZkouHcf3es2O8CFqz7RIociMFfMWQEzBkmVo8fKxwUdOvrm4u/eKc6dZ5OLKuh3+\nRo8S10zbZvOE8btKosL9HhHF1X51Qg4gbqEU06hnTCKLyyxOvpkrrTFOXCQtaDJu\nypN1xhEEZIYL7j4QfDa+LZSeslzwRT2WywCnLyX2bgIzDvZDCVKeqHxfl/Z5YrX8\nFn+75j8tX/BDyjZs8XGFeesQx5hb/WWGI2FpqHz11GVUm/rcrE9gi4Thghkn43T1\nsY23URvBcKfY5Z+YG4eCkjsoMoJnybLKhLQ08YKY3rap4XGLsvn8SG+XByw7Uk1I\nZlvl/dO+AMJKfjPcme0cj56m85eWrHfmwGXQPOicMcKz6pxQ7u0icDD5Ychm9a8t\ndkgmRv8coB8qCEU5VX5JOK/N826MzmoHX5tG9WBAdXWpDg9wKdNn75ZbbajMm+eV\n5GSCDAq4TtaPFzGu8fKeWuECAwEAAQ==\n-----END PUBLIC KEY-----" - }, - "isCat": false, - "attachment": [ - { - "type": "PropertyValue", - "name": "Test", - "value": "Value" - } - ], - "vcard:Address": "United States of America" - } - """; - - [Fact] - public void ShouldDeserializeWithoutCrash() - { - var result = _jsonLdSerializer.Deserialize(ActorJson); - result.Should().NotBeNull(); - } - - [Fact] - public void ShouldSetKeyFields() - { - var result = _jsonLdSerializer.Deserialize(ActorJson); - - result.Should().BeOfType(); - result?.Id.Should().Be("https://enby.life/users/9fpnzspgtp"); - result.As().Inbox.HRef.Should().Be("https://enby.life/users/9fpnzspgtp/inbox"); - } - - private readonly IJsonLdSerializer _jsonLdSerializer; - - public CalckeyActorTests() - { - var jsonTypeInfoCache = new JsonTypeInfoCache(); - var asTypeInfoCache = new ASTypeInfoCache(jsonTypeInfoCache); - asTypeInfoCache.RegisterAllAssemblies(); - - _jsonLdSerializer = new JsonLdSerializer(asTypeInfoCache, jsonTypeInfoCache); - } -} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxPageTests.cs b/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxPageTests.cs deleted file mode 100644 index 90123e8..0000000 --- a/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxPageTests.cs +++ /dev/null @@ -1,271 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using ActivityPub.Types.Collection; -using ActivityPub.Types.Internal.TypeInfo; -using ActivityPub.Types.Json; - -namespace ActivityPub.Types.Tests.Smoke.Samples; - -public class CalckeyOutboxPageTests -{ - private const string PageJson = - """ - { - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - { - "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", - "movedToUri": "as:movedTo", - "sensitive": "as:sensitive", - "Hashtag": "as:Hashtag", - "quoteUri": "fedibird:quoteUri", - "quoteUrl": "as:quoteUrl", - "toot": "http://joinmastodon.org/ns#", - "Emoji": "toot:Emoji", - "featured": "toot:featured", - "discoverable": "toot:discoverable", - "schema": "http://schema.org#", - "PropertyValue": "schema:PropertyValue", - "value": "schema:value", - "misskey": "https://misskey-hub.net/ns#", - "_misskey_content": "misskey:_misskey_content", - "_misskey_quote": "misskey:_misskey_quote", - "_misskey_reaction": "misskey:_misskey_reaction", - "_misskey_votes": "misskey:_misskey_votes", - "_misskey_talk": "misskey:_misskey_talk", - "isCat": "misskey:isCat", - "fedibird": "http://fedibird.com/ns#", - "vcard": "http://www.w3.org/2006/vcard/ns#" - } - ], - "id": "https://enby.life/users/9fpnzspgtp/outbox?page=true", - "partOf": "https://enby.life/users/9fpnzspgtp/outbox", - "type": "OrderedCollectionPage", - "totalItems": 5, - "orderedItems": [ - { - "id": "https://enby.life/notes/9h203ewltks9dbfb/activity", - "actor": "https://enby.life/users/9fpnzspgtp", - "type": "Create", - "published": "2023-07-11T15:17:48.213Z", - "object": { - "id": "https://enby.life/notes/9h203ewltks9dbfb", - "type": "Note", - "attributedTo": "https://enby.life/users/9fpnzspgtp", - "summary": null, - "content": "

Source for the instance background: https://tech.lgbt/@Gingeh/110117861681527722

", - "_misskey_content": "Source for the instance background: https://tech.lgbt/@Gingeh/110117861681527722", - "source": { - "content": "Source for the instance background: https://tech.lgbt/@Gingeh/110117861681527722", - "mediaType": "text/x.misskeymarkdown" - }, - "published": "2023-07-11T15:17:48.213Z", - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ], - "inReplyTo": null, - "attachment": [], - "sensitive": false, - "tag": [] - }, - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ] - }, - { - "id": "https://enby.life/notes/9h202z6wvqu3unrm/activity", - "actor": "https://enby.life/users/9fpnzspgtp", - "type": "Create", - "published": "2023-07-11T15:17:27.848Z", - "object": { - "id": "https://enby.life/notes/9h202z6wvqu3unrm", - "type": "Note", - "attributedTo": "https://enby.life/users/9fpnzspgtp", - "summary": null, - "content": "

Finally figured out how to set an instance-wide background image on #Calckey. I had to use custom CSS, but its looks really slick and even adapts to match each user's theme!

", - "_misskey_content": "Finally figured out how to set an instance-wide background image on #Calckey. I had to use custom CSS, but its looks really slick and even adapts to match each user's theme!", - "source": { - "content": "Finally figured out how to set an instance-wide background image on #Calckey. I had to use custom CSS, but its looks really slick and even adapts to match each user's theme!", - "mediaType": "text/x.misskeymarkdown" - }, - "published": "2023-07-11T15:17:27.848Z", - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ], - "inReplyTo": null, - "attachment": [], - "sensitive": false, - "tag": [ - { - "type": "Hashtag", - "href": "https://enby.life/tags/calckey", - "name": "#calckey" - } - ] - }, - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ] - }, - { - "id": "https://enby.life/notes/9gjh1o24lu3c00f3/activity", - "actor": "https://enby.life/users/9fpnzspgtp", - "type": "Create", - "published": "2023-06-28T16:04:42.892Z", - "object": { - "id": "https://enby.life/notes/9gjh1o24lu3c00f3", - "type": "Note", - "attributedTo": "https://enby.life/users/9fpnzspgtp", - "summary": null, - "content": "

@hazelnoot crisis averted - I've regained the admin account. Nothing that a bit of root access couldn't fix!

", - "_misskey_content": "@hazelnoot crisis averted - I've regained the admin account. Nothing that a bit of root access couldn't fix!", - "source": { - "content": "@hazelnoot crisis averted - I've regained the admin account. Nothing that a bit of root access couldn't fix!", - "mediaType": "text/x.misskeymarkdown" - }, - "published": "2023-06-28T16:04:42.892Z", - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ], - "inReplyTo": "https://enby.life/notes/9gje2bq6sq0k83t1", - "attachment": [], - "sensitive": false, - "tag": [ - { - "type": "Mention", - "href": "https://enby.life/users/9fpwmts9tv", - "name": "@hazelnoot" - } - ] - }, - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ] - }, - { - "id": "https://enby.life/notes/9fpx4niku4/activity", - "actor": "https://enby.life/users/9fpnzspgtp", - "type": "Create", - "published": "2023-06-07T23:41:50.732Z", - "object": { - "id": "https://enby.life/notes/9fpx4niku4", - "type": "Note", - "attributedTo": "https://enby.life/users/9fpnzspgtp", - "summary": null, - "content": "

testing testing 🦊

", - "_misskey_content": "testing testing 🦊", - "source": { - "content": "testing testing 🦊", - "mediaType": "text/x.misskeymarkdown" - }, - "published": "2023-06-07T23:41:50.732Z", - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ], - "inReplyTo": null, - "attachment": [], - "sensitive": false, - "tag": [] - }, - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ] - }, - { - "id": "https://enby.life/notes/9fpo5w7str/activity", - "actor": "https://enby.life/users/9fpnzspgtp", - "type": "Create", - "published": "2023-06-07T19:30:52.120Z", - "object": { - "id": "https://enby.life/notes/9fpo5w7str", - "type": "Note", - "attributedTo": "https://enby.life/users/9fpnzspgtp", - "summary": null, - "content": "

test post

", - "_misskey_content": "test post", - "source": { - "content": "test post", - "mediaType": "text/x.misskeymarkdown" - }, - "published": "2023-06-07T19:30:52.120Z", - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ], - "inReplyTo": null, - "attachment": [], - "sensitive": false, - "tag": [] - }, - "to": [ - "https://www.w3.org/ns/activitystreams#Public" - ], - "cc": [ - "https://enby.life/users/9fpnzspgtp/followers" - ] - } - ], - "prev": "https://enby.life/users/9fpnzspgtp/outbox?page=true&since_id=9h203ewltks9dbfb", - "next": "https://enby.life/users/9fpnzspgtp/outbox?page=true&until_id=9fpo5w7str" - } - """; - - [Fact] - public void ShouldDeserializeWithoutCrash() - { - var result = _jsonLdSerializer.Deserialize(PageJson); - result.Should().NotBeNull(); - } - - [Fact] - public void ShouldSetKeyFields() - { - var result = _jsonLdSerializer.Deserialize(PageJson); - - result.Should().BeOfType>(); - result?.Id.Should().Be("https://enby.life/users/9fpnzspgtp/outbox?page=true"); - result.As>().IsPaged.Should().BeFalse(); - result.As>().HasItems.Should().BeTrue(); - result.As>().TotalItems.Should().Be(5); - result.As>().Items.Should().HaveCount(5); - } - - private readonly IJsonLdSerializer _jsonLdSerializer; - - public CalckeyOutboxPageTests() - { - var jsonTypeInfoCache = new JsonTypeInfoCache(); - var asTypeInfoCache = new ASTypeInfoCache(jsonTypeInfoCache); - asTypeInfoCache.RegisterAllAssemblies(); - - _jsonLdSerializer = new JsonLdSerializer(asTypeInfoCache, jsonTypeInfoCache); - } -} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxTests.cs b/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxTests.cs deleted file mode 100644 index 7b8af7e..0000000 --- a/Tests/ActivityPub.Types.Tests/Smoke/Samples/CalckeyOutboxTests.cs +++ /dev/null @@ -1,80 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. -// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. - -using ActivityPub.Types.Collection; -using ActivityPub.Types.Internal.TypeInfo; -using ActivityPub.Types.Json; - -namespace ActivityPub.Types.Tests.Smoke.Samples; - -public class CalckeyOutboxTests -{ - private const string OutboxJson = - """ - { - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1", - { - "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", - "movedToUri": "as:movedTo", - "sensitive": "as:sensitive", - "Hashtag": "as:Hashtag", - "quoteUri": "fedibird:quoteUri", - "quoteUrl": "as:quoteUrl", - "toot": "http://joinmastodon.org/ns#", - "Emoji": "toot:Emoji", - "featured": "toot:featured", - "discoverable": "toot:discoverable", - "schema": "http://schema.org#", - "PropertyValue": "schema:PropertyValue", - "value": "schema:value", - "misskey": "https://misskey-hub.net/ns#", - "_misskey_content": "misskey:_misskey_content", - "_misskey_quote": "misskey:_misskey_quote", - "_misskey_reaction": "misskey:_misskey_reaction", - "_misskey_votes": "misskey:_misskey_votes", - "_misskey_talk": "misskey:_misskey_talk", - "isCat": "misskey:isCat", - "fedibird": "http://fedibird.com/ns#", - "vcard": "http://www.w3.org/2006/vcard/ns#" - } - ], - "id": "https://enby.life/users/9fpnzspgtp/outbox", - "type": "OrderedCollection", - "totalItems": 5, - "first": "https://enby.life/users/9fpnzspgtp/outbox?page=true", - "last": "https://enby.life/users/9fpnzspgtp/outbox?page=true&since_id=000000000000000000000000" - } - """; - - [Fact] - public void ShouldDeserializeWithoutCrash() - { - var result = _jsonLdSerializer.Deserialize(OutboxJson); - result.Should().NotBeNull(); - } - - [Fact] - public void ShouldSetKeyFields() - { - var result = _jsonLdSerializer.Deserialize(OutboxJson); - - result.Should().BeOfType>(); - result?.Id.Should().Be("https://enby.life/users/9fpnzspgtp/outbox"); - result.As>().IsPaged.Should().BeTrue(); - result.As>().HasItems.Should().BeFalse(); - result.As>().TotalItems.Should().Be(5); - } - - private readonly IJsonLdSerializer _jsonLdSerializer; - - public CalckeyOutboxTests() - { - var jsonTypeInfoCache = new JsonTypeInfoCache(); - var asTypeInfoCache = new ASTypeInfoCache(jsonTypeInfoCache); - asTypeInfoCache.RegisterAllAssemblies(); - - _jsonLdSerializer = new JsonLdSerializer(asTypeInfoCache, jsonTypeInfoCache); - } -} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/FirefishSampleTests.cs b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/FirefishSampleTests.cs new file mode 100644 index 0000000..98ce0d8 --- /dev/null +++ b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/FirefishSampleTests.cs @@ -0,0 +1,22 @@ +// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using ActivityPub.Types.Collection; +using ActivityPub.Types.Extended.Actor; +using ActivityPub.Types.Tests.Util.Fixtures; + +namespace ActivityPub.Types.Tests.Smoke.Samples.Firefish; + +public class FirefishSampleTests : SampleTests +{ + public FirefishSampleTests(JsonLdSerializerFixture fixture) : base(fixture) {} + + [Fact] + public void PersonActorShouldConvert() => TestSample(typeof(PersonActor), PersonActor.PersonType); + + [Fact] + public void ASOrderedCollectionShouldConvert() => TestSample(typeof(ASOrderedCollection), CollectionTypes.OrderedCollectionType); + + [Fact] + public void ASOrderedCollectionPageShouldConvert() => TestSample(typeof(ASOrderedCollectionPage), CollectionTypes.OrderedCollectionPageType); +} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollection.jsonld b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollection.jsonld new file mode 100644 index 0000000..df8c21c --- /dev/null +++ b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollection.jsonld @@ -0,0 +1,35 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "movedToUri": "as:movedTo", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "quoteUri": "fedibird:quoteUri", + "quoteUrl": "as:quoteUrl", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "featured": "toot:featured", + "discoverable": "toot:discoverable", + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "misskey": "https://misskey-hub.net/ns#", + "_misskey_content": "misskey:_misskey_content", + "_misskey_quote": "misskey:_misskey_quote", + "_misskey_reaction": "misskey:_misskey_reaction", + "_misskey_votes": "misskey:_misskey_votes", + "_misskey_talk": "misskey:_misskey_talk", + "isCat": "misskey:isCat", + "fedibird": "http://fedibird.com/ns#", + "vcard": "http://www.w3.org/2006/vcard/ns#" + } + ], + "id": "https://enby.life/users/9fpnzspgtp/outbox", + "type": "OrderedCollection", + "totalItems": 5, + "first": "https://enby.life/users/9fpnzspgtp/outbox?page=true", + "last": "https://enby.life/users/9fpnzspgtp/outbox?page=true&since_id=000000000000000000000000" +} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollectionPage.jsonld b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollectionPage.jsonld new file mode 100644 index 0000000..f11c06d --- /dev/null +++ b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/OrderedCollectionPage.jsonld @@ -0,0 +1,225 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "movedToUri": "as:movedTo", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "quoteUri": "fedibird:quoteUri", + "quoteUrl": "as:quoteUrl", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "featured": "toot:featured", + "discoverable": "toot:discoverable", + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "misskey": "https://misskey-hub.net/ns#", + "_misskey_content": "misskey:_misskey_content", + "_misskey_quote": "misskey:_misskey_quote", + "_misskey_reaction": "misskey:_misskey_reaction", + "_misskey_votes": "misskey:_misskey_votes", + "_misskey_talk": "misskey:_misskey_talk", + "isCat": "misskey:isCat", + "fedibird": "http://fedibird.com/ns#", + "vcard": "http://www.w3.org/2006/vcard/ns#" + } + ], + "id": "https://enby.life/users/9fpnzspgtp/outbox?page=true", + "partOf": "https://enby.life/users/9fpnzspgtp/outbox", + "type": "OrderedCollectionPage", + "totalItems": 5, + "orderedItems": [ + { + "id": "https://enby.life/notes/9h203ewltks9dbfb/activity", + "actor": "https://enby.life/users/9fpnzspgtp", + "type": "Create", + "published": "2023-07-11T15:17:48.213Z", + "object": { + "id": "https://enby.life/notes/9h203ewltks9dbfb", + "type": "Note", + "attributedTo": "https://enby.life/users/9fpnzspgtp", + "summary": null, + "content": "

Source for the instance background: https://tech.lgbt/@Gingeh/110117861681527722

", + "_misskey_content": "Source for the instance background: https://tech.lgbt/@Gingeh/110117861681527722", + "source": { + "content": "Source for the instance background: https://tech.lgbt/@Gingeh/110117861681527722", + "mediaType": "text/x.misskeymarkdown" + }, + "published": "2023-07-11T15:17:48.213Z", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ], + "inReplyTo": null, + "attachment": [], + "sensitive": false, + "tag": [] + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ] + }, + { + "id": "https://enby.life/notes/9h202z6wvqu3unrm/activity", + "actor": "https://enby.life/users/9fpnzspgtp", + "type": "Create", + "published": "2023-07-11T15:17:27.848Z", + "object": { + "id": "https://enby.life/notes/9h202z6wvqu3unrm", + "type": "Note", + "attributedTo": "https://enby.life/users/9fpnzspgtp", + "summary": null, + "content": "

Finally figured out how to set an instance-wide background image on #Calckey. I had to use custom CSS, but its looks really slick and even adapts to match each user's theme!

", + "_misskey_content": "Finally figured out how to set an instance-wide background image on #Calckey. I had to use custom CSS, but its looks really slick and even adapts to match each user's theme!", + "source": { + "content": "Finally figured out how to set an instance-wide background image on #Calckey. I had to use custom CSS, but its looks really slick and even adapts to match each user's theme!", + "mediaType": "text/x.misskeymarkdown" + }, + "published": "2023-07-11T15:17:27.848Z", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ], + "inReplyTo": null, + "attachment": [], + "sensitive": false, + "tag": [ + { + "type": "Hashtag", + "href": "https://enby.life/tags/calckey", + "name": "#calckey" + } + ] + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ] + }, + { + "id": "https://enby.life/notes/9gjh1o24lu3c00f3/activity", + "actor": "https://enby.life/users/9fpnzspgtp", + "type": "Create", + "published": "2023-06-28T16:04:42.892Z", + "object": { + "id": "https://enby.life/notes/9gjh1o24lu3c00f3", + "type": "Note", + "attributedTo": "https://enby.life/users/9fpnzspgtp", + "summary": null, + "content": "

@hazelnoot crisis averted - I've regained the admin account. Nothing that a bit of root access couldn't fix!

", + "_misskey_content": "@hazelnoot crisis averted - I've regained the admin account. Nothing that a bit of root access couldn't fix!", + "source": { + "content": "@hazelnoot crisis averted - I've regained the admin account. Nothing that a bit of root access couldn't fix!", + "mediaType": "text/x.misskeymarkdown" + }, + "published": "2023-06-28T16:04:42.892Z", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ], + "inReplyTo": "https://enby.life/notes/9gje2bq6sq0k83t1", + "attachment": [], + "sensitive": false, + "tag": [ + { + "type": "Mention", + "href": "https://enby.life/users/9fpwmts9tv", + "name": "@hazelnoot" + } + ] + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ] + }, + { + "id": "https://enby.life/notes/9fpx4niku4/activity", + "actor": "https://enby.life/users/9fpnzspgtp", + "type": "Create", + "published": "2023-06-07T23:41:50.732Z", + "object": { + "id": "https://enby.life/notes/9fpx4niku4", + "type": "Note", + "attributedTo": "https://enby.life/users/9fpnzspgtp", + "summary": null, + "content": "

testing testing 🦊

", + "_misskey_content": "testing testing 🦊", + "source": { + "content": "testing testing 🦊", + "mediaType": "text/x.misskeymarkdown" + }, + "published": "2023-06-07T23:41:50.732Z", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ], + "inReplyTo": null, + "attachment": [], + "sensitive": false, + "tag": [] + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ] + }, + { + "id": "https://enby.life/notes/9fpo5w7str/activity", + "actor": "https://enby.life/users/9fpnzspgtp", + "type": "Create", + "published": "2023-06-07T19:30:52.120Z", + "object": { + "id": "https://enby.life/notes/9fpo5w7str", + "type": "Note", + "attributedTo": "https://enby.life/users/9fpnzspgtp", + "summary": null, + "content": "

test post

", + "_misskey_content": "test post", + "source": { + "content": "test post", + "mediaType": "text/x.misskeymarkdown" + }, + "published": "2023-06-07T19:30:52.120Z", + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ], + "inReplyTo": null, + "attachment": [], + "sensitive": false, + "tag": [] + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public" + ], + "cc": [ + "https://enby.life/users/9fpnzspgtp/followers" + ] + } + ], + "prev": "https://enby.life/users/9fpnzspgtp/outbox?page=true&since_id=9h203ewltks9dbfb", + "next": "https://enby.life/users/9fpnzspgtp/outbox?page=true&until_id=9fpo5w7str" +} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/Person.jsonld b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/Person.jsonld new file mode 100644 index 0000000..a643af2 --- /dev/null +++ b/Tests/ActivityPub.Types.Tests/Smoke/Samples/Firefish/Person.jsonld @@ -0,0 +1,70 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "movedToUri": "as:movedTo", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "quoteUri": "fedibird:quoteUri", + "quoteUrl": "as:quoteUrl", + "toot": "http://joinmastodon.org/ns#", + "Emoji": "toot:Emoji", + "featured": "toot:featured", + "discoverable": "toot:discoverable", + "schema": "http://schema.org#", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value", + "misskey": "https://misskey-hub.net/ns#", + "_misskey_content": "misskey:_misskey_content", + "_misskey_quote": "misskey:_misskey_quote", + "_misskey_reaction": "misskey:_misskey_reaction", + "_misskey_votes": "misskey:_misskey_votes", + "_misskey_talk": "misskey:_misskey_talk", + "isCat": "misskey:isCat", + "fedibird": "http://fedibird.com/ns#", + "vcard": "http://www.w3.org/2006/vcard/ns#" + } + ], + "type": "Person", + "id": "https://enby.life/users/9fpnzspgtp", + "inbox": "https://enby.life/users/9fpnzspgtp/inbox", + "outbox": "https://enby.life/users/9fpnzspgtp/outbox", + "followers": "https://enby.life/users/9fpnzspgtp/followers", + "following": "https://enby.life/users/9fpnzspgtp/following", + "featured": "https://enby.life/users/9fpnzspgtp/collections/featured", + "sharedInbox": "https://enby.life/inbox", + "endpoints": { + "sharedInbox": "https://enby.life/inbox" + }, + "url": "https://enby.life/@admin", + "preferredUsername": "admin", + "name": "Enby Admin", + "summary": "

Instance admin - contact for info and technical support

", + "icon": { + "type": "Image", + "url": "https://enby.life/files/a15e1514-0c3a-48a1-8480-bb5b8e880cef", + "sensitive": false, + "name": null + }, + "image": null, + "tag": [], + "manuallyApprovesFollowers": false, + "discoverable": true, + "publicKey": { + "id": "https://enby.life/users/9fpnzspgtp#main-key", + "type": "Key", + "owner": "https://enby.life/users/9fpnzspgtp", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAux49fKZK3XxSActEu+Rm\nitMezjOHKhRnQXzbh/UX++nrIrxhk4DJiQSmeOSuoeO3YiwlA8fcgK6ZU8l6RYFp\nhjjVauueWMaB7mrOHCBK2QtY9kPvtyMVtM1lt1cnqbsBsZP7YNWYS+9oZKw0NOCU\nPuapmYhkS+eA1hpBEDDZ0WG74HzNUSlweFD2ssQGeNyy0lTI20LPCvHqfDHO3rI1\nZkouHcf3es2O8CFqz7RIociMFfMWQEzBkmVo8fKxwUdOvrm4u/eKc6dZ5OLKuh3+\nRo8S10zbZvOE8btKosL9HhHF1X51Qg4gbqEU06hnTCKLyyxOvpkrrTFOXCQtaDJu\nypN1xhEEZIYL7j4QfDa+LZSeslzwRT2WywCnLyX2bgIzDvZDCVKeqHxfl/Z5YrX8\nFn+75j8tX/BDyjZs8XGFeesQx5hb/WWGI2FpqHz11GVUm/rcrE9gi4Thghkn43T1\nsY23URvBcKfY5Z+YG4eCkjsoMoJnybLKhLQ08YKY3rap4XGLsvn8SG+XByw7Uk1I\nZlvl/dO+AMJKfjPcme0cj56m85eWrHfmwGXQPOicMcKz6pxQ7u0icDD5Ychm9a8t\ndkgmRv8coB8qCEU5VX5JOK/N826MzmoHX5tG9WBAdXWpDg9wKdNn75ZbbajMm+eV\n5GSCDAq4TtaPFzGu8fKeWuECAwEAAQ==\n-----END PUBLIC KEY-----" + }, + "isCat": false, + "attachment": [ + { + "type": "PropertyValue", + "name": "Test", + "value": "Value" + } + ], + "vcard:Address": "United States of America" +} \ No newline at end of file diff --git a/Tests/ActivityPub.Types.Tests/Smoke/Samples/SampleTests.cs b/Tests/ActivityPub.Types.Tests/Smoke/Samples/SampleTests.cs new file mode 100644 index 0000000..c123667 --- /dev/null +++ b/Tests/ActivityPub.Types.Tests/Smoke/Samples/SampleTests.cs @@ -0,0 +1,51 @@ +// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +// If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using ActivityPub.Types.Json; +using ActivityPub.Types.Tests.Util.Fixtures; + +namespace ActivityPub.Types.Tests.Smoke.Samples; + +public abstract class SampleTests : IClassFixture +{ + private readonly IJsonLdSerializer _jsonLdSerializer; + protected SampleTests(JsonLdSerializerFixture fixture) => _jsonLdSerializer = fixture.JsonLdSerializer; + + protected void TestSample(Type expectedType, string sampleType) => TestSample(expectedType, sampleType, sampleType); + protected void TestSample(Type expectedType, string sampleType, string sampleName) + { + // Quick check - not an assertion because this isn't part of the test. + if (!expectedType.IsAssignableTo(typeof(ASType))) + throw new ArgumentException("expected type must derive from ASType", nameof(expectedType)); + + // Load sample + var testInput = LoadJson(sampleName); + + // Test deserialize + var valueObject = _jsonLdSerializer.Deserialize(testInput); + valueObject.Should().NotBeNull(); + valueObject.Should().BeOfType(expectedType); + valueObject?.Types.Should().Contain(sampleType); + + // Test serialize + var valueJson = _jsonLdSerializer.SerializeToElement(valueObject); + valueJson.Should().BeJsonObject(); + valueJson.Should().HaveASType(sampleType); + } + + // I've done this many times in my career but I can NEVER remember how it works /annoyed + // https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getmanifestresourcestream?view=net-7.0 + // https://stackoverflow.com/a/3314213 + private string LoadJson(string sampleName) + { + var jsonPath = $"{sampleName}.jsonld"; + var thisType = GetType(); + + using var stream = thisType.Assembly.GetManifestResourceStream(thisType, jsonPath); + if (stream == null) + throw new ArgumentException($"Failed to load a JSON sample with name {jsonPath}"); + + using var reader = new StreamReader(stream); + return reader.ReadToEnd(); + } +} \ No newline at end of file