]> Untitled Git - lemmy.git/commitdiff
Reorganize federation tests (#2092)
authorNutomic <me@nutomic.com>
Thu, 17 Feb 2022 22:04:01 +0000 (22:04 +0000)
committerGitHub <noreply@github.com>
Thu, 17 Feb 2022 22:04:01 +0000 (22:04 +0000)
* Reorganize apub protocol tests

* Reorder apub protocol struct members to clarify mandatory/optional fields

47 files changed:
crates/apub/assets/lemmy/objects/instance.json
crates/apub/assets/lemmy/objects/person.json
crates/apub/assets/mastodon/activities/create_note.json
crates/apub/assets/mastodon/activities/follow.json [new file with mode: 0644]
crates/apub/assets/mastodon/activities/undo_follow.json [new file with mode: 0644]
crates/apub/assets/smithereen/objects/note.json
crates/apub/src/collections/community_moderators.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/instance.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/apub/src/protocol/activities/block/block_user.rs
crates/apub/src/protocol/activities/block/mod.rs
crates/apub/src/protocol/activities/block/undo_block_user.rs
crates/apub/src/protocol/activities/community/add_mod.rs
crates/apub/src/protocol/activities/community/announce.rs
crates/apub/src/protocol/activities/community/mod.rs
crates/apub/src/protocol/activities/community/remove_mod.rs
crates/apub/src/protocol/activities/community/report.rs
crates/apub/src/protocol/activities/community/update.rs
crates/apub/src/protocol/activities/create_or_update/comment.rs
crates/apub/src/protocol/activities/create_or_update/mod.rs
crates/apub/src/protocol/activities/create_or_update/post.rs
crates/apub/src/protocol/activities/create_or_update/private_message.rs
crates/apub/src/protocol/activities/deletion/delete.rs
crates/apub/src/protocol/activities/deletion/mod.rs
crates/apub/src/protocol/activities/deletion/undo_delete.rs
crates/apub/src/protocol/activities/following/accept.rs
crates/apub/src/protocol/activities/following/follow.rs
crates/apub/src/protocol/activities/following/mod.rs
crates/apub/src/protocol/activities/following/undo_follow.rs
crates/apub/src/protocol/activities/mod.rs
crates/apub/src/protocol/activities/voting/mod.rs
crates/apub/src/protocol/activities/voting/undo_vote.rs
crates/apub/src/protocol/activities/voting/vote.rs
crates/apub/src/protocol/collections/mod.rs
crates/apub/src/protocol/mod.rs
crates/apub/src/protocol/objects/chat_message.rs
crates/apub/src/protocol/objects/group.rs
crates/apub/src/protocol/objects/instance.rs
crates/apub/src/protocol/objects/mod.rs
crates/apub/src/protocol/objects/note.rs
crates/apub/src/protocol/objects/page.rs
crates/apub/src/protocol/objects/person.rs

index 73df8775967fe609ada1888a0712316ca2fd33dd..524055f33d229da71b6b19eddf8082bb2188f026 100644 (file)
@@ -1,23 +1,4 @@
 {
-  "@context": [
-    "https://www.w3.org/ns/activitystreams",
-    {
-      "stickied": "as:stickied",
-      "pt": "https://join-lemmy.org#",
-      "sc": "http://schema.org#",
-      "matrixUserId": {
-        "type": "sc:Text",
-        "id": "as:alsoKnownAs"
-      },
-      "sensitive": "as:sensitive",
-      "comments_enabled": {
-        "type": "sc:Boolean",
-        "id": "pt:commentsEnabled"
-      },
-      "moderators": "as:moderators"
-    },
-    "https://w3id.org/security/v1"
-  ],
   "type": "Service",
   "id": "https://enterprise.lemmy.ml/",
   "name": "Enterprise",
index e21fa4d22916f0c3756eff3b05f267751fb9d1e0..4f708656ca8815a00ed958e261267f3e1f67bdb2 100644 (file)
@@ -16,7 +16,7 @@
     "type": "Image",
     "url": "https://enterprise.lemmy.ml/pictrs/image/XenaYI5hTn.png"
   },
-  "matrix_user_id": "@picard:matrix.org",
+  "matrixUserId": "@picard:matrix.org",
   "inbox": "https://enterprise.lemmy.ml/u/picard/inbox",
   "outbox": "https://enterprise.lemmy.ml/u/picard/outbox",
   "endpoints": {
index 8b836fb24baa01f85832a98fdbc3eaf72e4a4590..d796a043eb9af2fbd417b87eecfbf27743163324 100644 (file)
@@ -1,4 +1,11 @@
 {
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    {
+      "ostatus": "http://ostatus.org#",
+      "atomUri": "ostatus:atomUri"
+    }
+  ],
   "id": "https://mastodon.madrid/users/felix/statuses/107224289116410645/activity",
   "type": "Create",
   "actor": "https://mastodon.madrid/users/felix",
diff --git a/crates/apub/assets/mastodon/activities/follow.json b/crates/apub/assets/mastodon/activities/follow.json
new file mode 100644 (file)
index 0000000..2381ed5
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  "@context": "https://www.w3.org/ns/activitystreams",
+  "id": "https://masto.asonix.dog/1ea87517-63c5-4118-8831-460ee641b2cf",
+  "type": "Follow",
+  "actor": "https://masto.asonix.dog/users/asonix",
+  "object": "https://ds9.lemmy.ml/c/testcom"
+}
diff --git a/crates/apub/assets/mastodon/activities/undo_follow.json b/crates/apub/assets/mastodon/activities/undo_follow.json
new file mode 100644 (file)
index 0000000..d47ecd8
--- /dev/null
@@ -0,0 +1,13 @@
+{
+  "@context": "https://www.w3.org/ns/activitystreams",
+  "id": "https://masto.asonix.dog/users/asonix#follows/449/undo",
+  "type": "Undo",
+  "actor": "https://masto.asonix.dog/users/asonix",
+  "object": {
+    "id": "https://masto.asonix.dog/1ea87517-63c5-4118-8831-460ee641b2cf",
+    "type": "Follow",
+    "actor": "https://masto.asonix.dog/users/asonix",
+    "object": "https://ds9.lemmy.ml/c/testcom"
+  }
+}
+
index 0a948ee3daa14bdf0f7136ba0f93e9900f455b00..a8080cae112d9b74d7bf59ee683fae55877b2112 100644 (file)
     }
   },
   "sensitive": false,
-  "likes": "https://friends.grishka.me/posts/66561/likes"
+  "likes": "https://friends.grishka.me/posts/66561/likes",
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    {
+      "sensitive": "as:sensitive"
+    }
+  ]
 }
\ No newline at end of file
index 72d23d4acd5287d23a0d7e65ec5e0fbb87512987..d24f06a13e1c32857b516b58c1bc00d82ec99814 100644 (file)
@@ -138,10 +138,13 @@ impl ApubObject for ApubCommunityModerators {
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::objects::{
-    community::tests::parse_lemmy_community,
-    person::tests::parse_lemmy_person,
-    tests::{file_to_json_object, init_context},
+  use crate::{
+    objects::{
+      community::tests::parse_lemmy_community,
+      person::tests::parse_lemmy_person,
+      tests::init_context,
+    },
+    protocol::tests::file_to_json_object,
   };
   use lemmy_apub_lib::activity_queue::create_activity_queue;
   use lemmy_db_schema::{
index 82d9e4e4458816edabfc5859dc5fa7bf4ef9cc8a..e61cb869911ad0962304ec26aad5528232c9832d 100644 (file)
@@ -125,7 +125,6 @@ impl ApubObject for ApubComment {
       published: Some(convert_datetime(self.published)),
       updated: self.updated.map(convert_datetime),
       tag: maa.tags,
-      unparsed: Default::default(),
     };
 
     Ok(note)
@@ -208,12 +207,15 @@ impl ApubObject for ApubComment {
 #[cfg(test)]
 pub(crate) mod tests {
   use super::*;
-  use crate::objects::{
-    community::{tests::parse_lemmy_community, ApubCommunity},
-    instance::ApubSite,
-    person::{tests::parse_lemmy_person, ApubPerson},
-    post::ApubPost,
-    tests::{file_to_json_object, init_context},
+  use crate::{
+    objects::{
+      community::{tests::parse_lemmy_community, ApubCommunity},
+      instance::ApubSite,
+      person::{tests::parse_lemmy_person, ApubPerson},
+      post::ApubPost,
+      tests::init_context,
+    },
+    protocol::tests::file_to_json_object,
   };
   use assert_json_diff::assert_json_include;
   use lemmy_apub_lib::activity_queue::create_activity_queue;
index 4a618bf8867a0b02a524df7e063066d6fd486f7f..612616cf94c2c9f4d84152261340a92d4325fadd 100644 (file)
@@ -102,7 +102,6 @@ impl ApubObject for ApubCommunity {
       public_key: self.get_public_key()?,
       published: Some(convert_datetime(self.published)),
       updated: self.updated.map(convert_datetime),
-      unparsed: Default::default(),
     };
     Ok(group)
   }
@@ -214,9 +213,9 @@ impl ApubCommunity {
 #[cfg(test)]
 pub(crate) mod tests {
   use super::*;
-  use crate::objects::{
-    instance::tests::parse_lemmy_instance,
-    tests::{file_to_json_object, init_context},
+  use crate::{
+    objects::{instance::tests::parse_lemmy_instance, tests::init_context},
+    protocol::tests::file_to_json_object,
   };
   use lemmy_apub_lib::activity_queue::create_activity_queue;
   use lemmy_db_schema::{source::site::Site, traits::Crud};
index cdd76c5a959300a54a6f00c451f2258a69cad15c..40b585b5a10f0056f5bccdd22f20df3f1513f04e 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{
   check_is_apub_id_valid,
   objects::get_summary_from_string_or_source,
-  protocol::{objects::instance::Instance, ImageObject, Source, Unparsed},
+  protocol::{objects::instance::Instance, ImageObject, Source},
 };
 use activitystreams_kinds::actor::ServiceType;
 use chrono::NaiveDateTime;
@@ -86,7 +86,6 @@ impl ApubObject for ApubSite {
       public_key: self.get_public_key()?,
       published: convert_datetime(self.published),
       updated: self.updated.map(convert_datetime),
-      unparsed: Unparsed::default(),
     };
     Ok(instance)
   }
@@ -186,7 +185,7 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object(
 #[cfg(test)]
 pub(crate) mod tests {
   use super::*;
-  use crate::objects::tests::{file_to_json_object, init_context};
+  use crate::{objects::tests::init_context, protocol::tests::file_to_json_object};
   use lemmy_apub_lib::activity_queue::create_activity_queue;
   use lemmy_db_schema::traits::Crud;
   use serial_test::serial;
index d7e386b1063bdadb5b68f8c1797e2d4fa92991d9..cfe1ecd36c7666442c637bc7d5b9976ab5b65e3d 100644 (file)
@@ -41,8 +41,7 @@ pub(crate) mod tests {
   use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
   use reqwest::Client;
   use reqwest_middleware::ClientBuilder;
-  use serde::de::DeserializeOwned;
-  use std::{fs::File, io::BufReader, sync::Arc};
+  use std::sync::Arc;
   use tokio::sync::Mutex;
 
   // TODO: would be nice if we didnt have to use a full context for tests.
@@ -90,10 +89,4 @@ pub(crate) mod tests {
     .start();
     LemmyContext::create(pool, chat_server, client, activity_queue, settings, secret)
   }
-
-  pub(crate) fn file_to_json_object<T: DeserializeOwned>(path: &str) -> Result<T, LemmyError> {
-    let file = File::open(path)?;
-    let reader = BufReader::new(file);
-    Ok(serde_json::from_reader(reader)?)
-  }
 }
index 80dd8bfd1c13640704e8e46245474f6224658a8b..b75b107a11cb47c77a0f59189ec725c8a54662a8 100644 (file)
@@ -105,7 +105,6 @@ impl ApubObject for ApubPerson {
       }),
       public_key: self.get_public_key()?,
       updated: self.updated.map(convert_datetime),
-      unparsed: Default::default(),
       inbox: self.inbox_url.clone().into(),
     };
     Ok(person)
@@ -204,9 +203,9 @@ pub(crate) mod tests {
   use crate::{
     objects::{
       instance::{tests::parse_lemmy_instance, ApubSite},
-      tests::{file_to_json_object, init_context},
+      tests::init_context,
     },
-    protocol::objects::instance::Instance,
+    protocol::{objects::instance::Instance, tests::file_to_json_object},
   };
   use lemmy_apub_lib::activity_queue::create_activity_queue;
   use lemmy_db_schema::{source::site::Site, traits::Crud};
index b15c9374b55d5bc38279c887de17734f67c9ad11..3fb4b9cfdd3199fb034ec8b492d8f9676eb15b43 100644 (file)
@@ -122,7 +122,6 @@ impl ApubObject for ApubPost {
       stickied: Some(self.stickied),
       published: Some(convert_datetime(self.published)),
       updated: self.updated.map(convert_datetime),
-      unparsed: Default::default(),
     };
     Ok(page)
   }
@@ -207,11 +206,14 @@ impl ApubObject for ApubPost {
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::objects::{
-    community::tests::parse_lemmy_community,
-    person::tests::parse_lemmy_person,
-    post::ApubPost,
-    tests::{file_to_json_object, init_context},
+  use crate::{
+    objects::{
+      community::tests::parse_lemmy_community,
+      person::tests::parse_lemmy_person,
+      post::ApubPost,
+      tests::init_context,
+    },
+    protocol::tests::file_to_json_object,
   };
   use lemmy_apub_lib::activity_queue::create_activity_queue;
   use lemmy_db_schema::source::site::Site;
index 62af385533dbb3d459f367a4efc918c09faf2e8d..329767fdd99c6b91624f8618f39c98dd89fe30d3 100644 (file)
@@ -90,7 +90,6 @@ impl ApubObject for ApubPrivateMessage {
       source: Some(Source::new(self.content.clone())),
       published: Some(convert_datetime(self.published)),
       updated: self.updated.map(convert_datetime),
-      unparsed: Default::default(),
     };
     Ok(note)
   }
@@ -159,9 +158,9 @@ impl ApubObject for ApubPrivateMessage {
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::objects::{
-    person::ApubPerson,
-    tests::{file_to_json_object, init_context},
+  use crate::{
+    objects::{person::ApubPerson, tests::init_context},
+    protocol::tests::file_to_json_object,
   };
   use assert_json_diff::assert_json_include;
   use lemmy_apub_lib::activity_queue::create_activity_queue;
index 5d49fc602a00d1fcaee319da37ae7d202932ece6..ab4e3eca91653f32399d378d393154a7db340c2f 100644 (file)
@@ -17,13 +17,14 @@ pub struct BlockUser {
   pub(crate) target: ObjectId<SiteOrCommunity>,
   #[serde(rename = "type")]
   pub(crate) kind: BlockType,
+  pub(crate) id: Url,
+
   /// Quick and dirty solution.
   /// TODO: send a separate Delete activity instead
   pub(crate) remove_data: Option<bool>,
   /// block reason, written to mod log
   pub(crate) summary: Option<String>,
-  pub(crate) id: Url,
+  pub(crate) expires: Option<DateTime<FixedOffset>>,
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
-  pub(crate) expires: Option<DateTime<FixedOffset>>,
 }
index eb3736f7697e2646de9a696b3be6e8800cad70fc..eaf05b9ac8b4b34a58548bd9c0774999ea01f004 100644 (file)
@@ -8,8 +8,8 @@ mod tests {
     tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_lemmy_block() {
+  #[test]
+  fn test_parse_lemmy_block() {
     test_parse_lemmy_item::<BlockUser>("assets/lemmy/activities/block/block_user.json").unwrap();
     test_parse_lemmy_item::<UndoBlockUser>("assets/lemmy/activities/block/undo_block_user.json")
       .unwrap();
index d3db580e401a5dec0eb2ec1fa2f17a876842bf88..8e756be5559ecde7bf0d296dca9f5eebccbe519b 100644 (file)
@@ -19,6 +19,7 @@ pub struct UndoBlockUser {
   #[serde(rename = "type")]
   pub(crate) kind: UndoType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 915c24668e8449ba930348c9f21fc44769698692..5697c19f4002c3e1789543faf5aabbaa4c402f58 100644 (file)
@@ -17,6 +17,7 @@ pub struct AddMod {
   #[serde(rename = "type")]
   pub(crate) kind: AddType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 0bda9ebc5a036ed8c0b8f6a654b39a306f28374a..d693ed6f71a885b3c96ebee7c98dfdab94953f2f 100644 (file)
@@ -20,6 +20,7 @@ pub struct AnnounceActivity {
   #[serde(rename = "type")]
   pub(crate) kind: AnnounceType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index a25d5ca2d27c08ed67ab83c179778be30deea12e..47771891ffed0b071a6e38e377231457bb19da76 100644 (file)
@@ -17,8 +17,8 @@ mod tests {
     tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_lemmy_community() {
+  #[test]
+  fn test_parse_lemmy_community_activities() {
     test_parse_lemmy_item::<AnnounceActivity>(
       "assets/lemmy/activities/community/announce_create_page.json",
     )
index 74619c81d13131cf6132e4fe698712e0ddec5c2a..304772bb22f1218897b19380f0cd957691f33eff 100644 (file)
@@ -17,6 +17,7 @@ pub struct RemoveMod {
   pub(crate) kind: RemoveType,
   pub(crate) target: Url,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 18b74c23847246bfa1f666cbfc578b8f2e85f688..40bbe83bd74aeb0e077d5afdcc02d31c8595067c 100644 (file)
@@ -19,6 +19,7 @@ pub struct Report {
   #[serde(rename = "type")]
   pub(crate) kind: FlagType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index bb9b561142970703c3eff4b684d94d1264661a2d..4c4ef2f0308753d88830520a2edfe10352b4eac7 100644 (file)
@@ -22,6 +22,7 @@ pub struct UpdateCommunity {
   #[serde(rename = "type")]
   pub(crate) kind: UpdateType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 091c0f97cb1a87f18b8dd978cf32c0b4aae54c44..d63aabf844c61f0cc80650a50227b140a302ef9b 100644 (file)
@@ -21,6 +21,7 @@ pub struct CreateOrUpdateComment {
   #[serde(rename = "type")]
   pub(crate) kind: CreateOrUpdateType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index ff03c5a099e4fd4d7759d959d6b26f05e3ded226..0d233ccfcfafff1902c0ea1b84f96517b9a820cc 100644 (file)
@@ -4,21 +4,17 @@ pub mod private_message;
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    context::WithContext,
-    objects::tests::file_to_json_object,
-    protocol::{
-      activities::create_or_update::{
-        comment::CreateOrUpdateComment,
-        post::CreateOrUpdatePost,
-        private_message::CreateOrUpdatePrivateMessage,
-      },
-      tests::test_parse_lemmy_item,
+  use crate::protocol::{
+    activities::create_or_update::{
+      comment::CreateOrUpdateComment,
+      post::CreateOrUpdatePost,
+      private_message::CreateOrUpdatePrivateMessage,
     },
+    tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_create_or_update() {
+  #[test]
+  fn test_parse_lemmy_create_or_update() {
     test_parse_lemmy_item::<CreateOrUpdatePost>(
       "assets/lemmy/activities/create_or_update/create_page.json",
     )
@@ -35,23 +31,5 @@ mod tests {
       "assets/lemmy/activities/create_or_update/create_private_message.json",
     )
     .unwrap();
-
-    file_to_json_object::<WithContext<CreateOrUpdateComment>>(
-      "assets/pleroma/activities/create_note.json",
-    )
-    .unwrap();
-    file_to_json_object::<WithContext<CreateOrUpdateComment>>(
-      "assets/smithereen/activities/create_note.json",
-    )
-    .unwrap();
-    file_to_json_object::<CreateOrUpdateComment>("assets/mastodon/activities/create_note.json")
-      .unwrap();
-
-    file_to_json_object::<CreateOrUpdatePost>("assets/lotide/activities/create_page.json").unwrap();
-    file_to_json_object::<CreateOrUpdateComment>("assets/lotide/activities/create_note_reply.json")
-      .unwrap();
-
-    file_to_json_object::<CreateOrUpdateComment>("assets/friendica/activities/create_note.json")
-      .unwrap();
   }
 }
index 2061c88151f0ba7ea17a0fd121408b53ea9f9ee4..eb96572f17d34dcf61e34663b0129f0f4c8b99bb 100644 (file)
@@ -18,6 +18,7 @@ pub struct CreateOrUpdatePost {
   #[serde(rename = "type")]
   pub(crate) kind: CreateOrUpdateType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 9558d074a6329b853db5a078539778a895a85c88..a4e62b6566e2dc39e6e02e6cd7f7f64353e93406 100644 (file)
@@ -16,6 +16,7 @@ pub struct CreateOrUpdatePrivateMessage {
   pub(crate) object: ChatMessage,
   #[serde(rename = "type")]
   pub(crate) kind: CreateOrUpdateType,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 70b38af6c96fc69d962114ad75e8930f8a6f8779..6913652faf73324cd521d3e9af82aa07aeffafee 100644 (file)
@@ -13,16 +13,17 @@ pub struct Delete {
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   pub(crate) to: Vec<Url>,
   pub(crate) object: IdOrNestedObject,
+  #[serde(rename = "type")]
+  pub(crate) kind: DeleteType,
+  pub(crate) id: Url,
+
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   #[serde(default)]
   #[serde(skip_serializing_if = "Vec::is_empty")]
   pub(crate) cc: Vec<Url>,
-  #[serde(rename = "type")]
-  pub(crate) kind: DeleteType,
   /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
   /// deleting their own content.
   pub(crate) summary: Option<String>,
-  pub(crate) id: Url,
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 9ecb65c4ce1103773b3aecec7fcb4a3e0b3588f3..24f7ab16e93e0cd4e6d78ffa833c72abf937358f 100644 (file)
@@ -3,17 +3,13 @@ pub mod undo_delete;
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    context::WithContext,
-    objects::tests::file_to_json_object,
-    protocol::{
-      activities::deletion::{delete::Delete, undo_delete::UndoDelete},
-      tests::test_parse_lemmy_item,
-    },
+  use crate::protocol::{
+    activities::deletion::{delete::Delete, undo_delete::UndoDelete},
+    tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_deletion() {
+  #[test]
+  fn test_parse_lemmy_deletion() {
     test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/remove_note.json").unwrap();
     test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_page.json").unwrap();
 
@@ -27,8 +23,5 @@ mod tests {
       "assets/lemmy/activities/deletion/undo_delete_private_message.json",
     )
     .unwrap();
-
-    file_to_json_object::<WithContext<Delete>>("assets/pleroma/activities/delete.json").unwrap();
-    file_to_json_object::<WithContext<Delete>>("assets/mastodon/activities/delete.json").unwrap();
   }
 }
index f2f2d764494d84c76204e92171b6222b4611b1f4..bc5b942ffb6e87736e9c77371cd45f2eb2ca4255 100644 (file)
@@ -14,13 +14,14 @@ pub struct UndoDelete {
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   pub(crate) to: Vec<Url>,
   pub(crate) object: Delete,
+  #[serde(rename = "type")]
+  pub(crate) kind: UndoType,
+  pub(crate) id: Url,
+
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   #[serde(default)]
   #[serde(skip_serializing_if = "Vec::is_empty")]
   pub(crate) cc: Vec<Url>,
-  #[serde(rename = "type")]
-  pub(crate) kind: UndoType,
-  pub(crate) id: Url,
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 09d3419a1b0e29fdaa8024acaf51034b874b9719..dcb0b181ab5cd9cd015824ede668c8f4db33568d 100644 (file)
@@ -15,6 +15,7 @@ pub struct AcceptFollowCommunity {
   #[serde(rename = "type")]
   pub(crate) kind: AcceptType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index cc2cc8e0aabe3b8c6e65541ef922009eb053ad54..2072af486f08aeebe4d17d0f47b81c93eeea8a0e 100644 (file)
@@ -15,6 +15,7 @@ pub struct FollowCommunity {
   #[serde(rename = "type")]
   pub(crate) kind: FollowType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 2b21b48341bdf2b0d10c9c3e216ddad78957b8eb..1265512f93e3bfde132d1288b977828c63abf73f 100644 (file)
@@ -4,21 +4,17 @@ pub mod undo_follow;
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    context::WithContext,
-    objects::tests::file_to_json_object,
-    protocol::{
-      activities::following::{
-        accept::AcceptFollowCommunity,
-        follow::FollowCommunity,
-        undo_follow::UndoFollowCommunity,
-      },
-      tests::test_parse_lemmy_item,
+  use crate::protocol::{
+    activities::following::{
+      accept::AcceptFollowCommunity,
+      follow::FollowCommunity,
+      undo_follow::UndoFollowCommunity,
     },
+    tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_lemmy_accept_follow() {
+  #[test]
+  fn test_parse_lemmy_accept_follow() {
     test_parse_lemmy_item::<FollowCommunity>("assets/lemmy/activities/following/follow.json")
       .unwrap();
     test_parse_lemmy_item::<AcceptFollowCommunity>("assets/lemmy/activities/following/accept.json")
@@ -27,8 +23,5 @@ mod tests {
       "assets/lemmy/activities/following/undo_follow.json",
     )
     .unwrap();
-
-    file_to_json_object::<WithContext<FollowCommunity>>("assets/pleroma/activities/follow.json")
-      .unwrap();
   }
 }
index f14e3a48d6c8196fc0a204f3a8d94d6c2b0c636a..1936146909e4fbd8c900c372a38296cfa6d4aa10 100644 (file)
@@ -15,6 +15,7 @@ pub struct UndoFollowCommunity {
   #[serde(rename = "type")]
   pub(crate) kind: UndoType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 9279cab12cbf2b0369ff831616b30a4dab120e71..0f9509319febdec043c2e0cba5e6fea5892b0017 100644 (file)
@@ -13,3 +13,46 @@ pub enum CreateOrUpdateType {
   Create,
   Update,
 }
+
+#[cfg(test)]
+mod tests {
+  use crate::protocol::{
+    activities::{
+      create_or_update::{comment::CreateOrUpdateComment, post::CreateOrUpdatePost},
+      deletion::delete::Delete,
+      following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity},
+    },
+    tests::test_json,
+  };
+
+  #[test]
+  fn test_parse_smithereen_activities() {
+    test_json::<CreateOrUpdateComment>("assets/smithereen/activities/create_note.json").unwrap();
+  }
+
+  #[test]
+  fn test_parse_pleroma_activities() {
+    test_json::<CreateOrUpdateComment>("assets/pleroma/activities/create_note.json").unwrap();
+    test_json::<Delete>("assets/pleroma/activities/delete.json").unwrap();
+    test_json::<FollowCommunity>("assets/pleroma/activities/follow.json").unwrap();
+  }
+
+  #[test]
+  fn test_parse_mastodon_activities() {
+    test_json::<CreateOrUpdateComment>("assets/mastodon/activities/create_note.json").unwrap();
+    test_json::<Delete>("assets/mastodon/activities/delete.json").unwrap();
+    test_json::<FollowCommunity>("assets/mastodon/activities/follow.json").unwrap();
+    test_json::<UndoFollowCommunity>("assets/mastodon/activities/undo_follow.json").unwrap();
+  }
+
+  #[test]
+  fn test_parse_lotide_activities() {
+    test_json::<CreateOrUpdatePost>("assets/lotide/activities/create_page.json").unwrap();
+    test_json::<CreateOrUpdateComment>("assets/lotide/activities/create_note_reply.json").unwrap();
+  }
+
+  #[test]
+  fn test_parse_friendica_activities() {
+    test_json::<CreateOrUpdateComment>("assets/friendica/activities/create_note.json").unwrap();
+  }
+}
index ab405d0d83bcbada3bceb92e73be0a634037874f..94f759ed83697f166ec71bf5508957ec927d4dba 100644 (file)
@@ -8,8 +8,8 @@ mod tests {
     tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_lemmy_voting() {
+  #[test]
+  fn test_parse_lemmy_voting() {
     test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/like_note.json").unwrap();
     test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/dislike_page.json").unwrap();
 
index d3f4fb33780bc6b07d5c127cd06665ed92ddb831..d8ba7cbae3d88e0f915e3994802cd2f88659dfa7 100644 (file)
@@ -19,6 +19,7 @@ pub struct UndoVote {
   #[serde(rename = "type")]
   pub(crate) kind: UndoType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index 2f07aea858d2fc0c9f7eeb30f3956c62197db6fe..cafd6bbc34cf022cd61205f3add70336e64fa3e3 100644 (file)
@@ -22,6 +22,7 @@ pub struct Vote {
   #[serde(rename = "type")]
   pub(crate) kind: VoteType,
   pub(crate) id: Url,
+
   #[serde(flatten)]
   pub(crate) unparsed: Unparsed,
 }
index f34dd1d10800b763a8f6416e68b777837a23c611..0e251a1bbf4c5da4ef5aabd88b1ba3664b328ba0 100644 (file)
@@ -15,8 +15,8 @@ mod tests {
     tests::test_parse_lemmy_item,
   };
 
-  #[actix_rt::test]
-  async fn test_parse_lemmy_collections() {
+  #[test]
+  fn test_parse_lemmy_collections() {
     test_parse_lemmy_item::<GroupFollowers>("assets/lemmy/collections/group_followers.json")
       .unwrap();
     let outbox =
index d1532a9523ae7f4d3b606cdcf6f0c79680b20c6c..bb384de643a467f05f887d130699ab38de72c8b8 100644 (file)
@@ -49,11 +49,21 @@ pub struct Unparsed(HashMap<String, serde_json::Value>);
 
 #[cfg(test)]
 pub(crate) mod tests {
-  use crate::objects::tests::file_to_json_object;
+  use crate::context::WithContext;
   use assert_json_diff::assert_json_include;
   use lemmy_utils::LemmyError;
   use serde::{de::DeserializeOwned, Serialize};
-  use std::collections::HashMap;
+  use std::{collections::HashMap, fs::File, io::BufReader};
+
+  pub(crate) fn file_to_json_object<T: DeserializeOwned>(path: &str) -> Result<T, LemmyError> {
+    let file = File::open(path)?;
+    let reader = BufReader::new(file);
+    Ok(serde_json::from_reader(reader)?)
+  }
+
+  pub(crate) fn test_json<T: DeserializeOwned>(path: &str) -> Result<WithContext<T>, LemmyError> {
+    file_to_json_object::<WithContext<T>>(path)
+  }
 
   /// Check that json deserialize -> serialize -> deserialize gives identical file as initial one.
   /// Ensures that there are no breaking changes in sent data.
index 608300ce10aa535910890f72fffd5f9e8a15aa98..a39f7b250022c5dc40ae29a3da0d45d173c06bdd 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   objects::{person::ApubPerson, private_message::ApubPrivateMessage},
-  protocol::{Source, Unparsed},
+  protocol::Source,
 };
 use chrono::{DateTime, FixedOffset};
 use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml};
@@ -17,12 +17,11 @@ pub struct ChatMessage {
   #[serde(deserialize_with = "crate::deserialize_one")]
   pub(crate) to: [ObjectId<ApubPerson>; 1],
   pub(crate) content: String,
+
   pub(crate) media_type: Option<MediaTypeHtml>,
   pub(crate) source: Option<Source>,
   pub(crate) published: Option<DateTime<FixedOffset>>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
-  #[serde(flatten)]
-  pub(crate) unparsed: Unparsed,
 }
 
 /// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages
index 5a2d394537a202ce4583a5d3888c9c4c5e0bdde8..51e3a00ac137a769875dab8ac29b9296089d190f 100644 (file)
@@ -5,7 +5,7 @@ use crate::{
     community_outbox::ApubCommunityOutbox,
   },
   objects::{community::ApubCommunity, get_summary_from_string_or_source},
-  protocol::{objects::Endpoints, ImageObject, Source, Unparsed},
+  protocol::{objects::Endpoints, ImageObject, Source},
 };
 use activitystreams_kinds::actor::GroupType;
 use chrono::{DateTime, FixedOffset};
@@ -27,10 +27,14 @@ pub struct Group {
   #[serde(rename = "type")]
   pub(crate) kind: GroupType,
   pub(crate) id: ObjectId<ApubCommunity>,
-  /// username, set at account creation and can never be changed
+  /// username, set at account creation and usually fixed after that
   pub(crate) preferred_username: String,
-  /// title (can be changed at any time)
+  /// displayname
   pub(crate) name: String,
+  pub(crate) inbox: Url,
+  pub(crate) followers: Url,
+  pub(crate) public_key: PublicKey,
+
   pub(crate) summary: Option<String>,
   pub(crate) source: Option<Source>,
   pub(crate) icon: Option<ImageObject>,
@@ -40,15 +44,10 @@ pub struct Group {
   pub(crate) sensitive: Option<bool>,
   // lemmy extension
   pub(crate) moderators: Option<ObjectId<ApubCommunityModerators>>,
-  pub(crate) inbox: Url,
   pub(crate) outbox: ObjectId<ApubCommunityOutbox>,
-  pub(crate) followers: Url,
   pub(crate) endpoints: Option<Endpoints>,
-  pub(crate) public_key: PublicKey,
   pub(crate) published: Option<DateTime<FixedOffset>>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
-  #[serde(flatten)]
-  pub(crate) unparsed: Unparsed,
 }
 
 impl Group {
index 2a967ac522ca55f87e0ad256941b7b2a6ed66c87..c70a780f41d8c9a878d0b08c5dadfcaa1e08649b 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   objects::instance::ApubSite,
-  protocol::{ImageObject, Source, Unparsed},
+  protocol::{ImageObject, Source},
 };
 use activitystreams_kinds::actor::ServiceType;
 use chrono::{DateTime, FixedOffset};
@@ -18,6 +18,11 @@ pub struct Instance {
   pub(crate) id: ObjectId<ApubSite>,
   // site name
   pub(crate) name: String,
+  pub(crate) inbox: Url,
+  /// mandatory field in activitypub, lemmy currently serves an empty outbox
+  pub(crate) outbox: Url,
+  pub(crate) public_key: PublicKey,
+
   // sidebar
   pub(crate) content: Option<String>,
   pub(crate) source: Option<Source>,
@@ -28,12 +33,6 @@ pub struct Instance {
   pub(crate) icon: Option<ImageObject>,
   /// instance banner
   pub(crate) image: Option<ImageObject>,
-  pub(crate) inbox: Url,
-  /// mandatory field in activitypub, currently empty in lemmy
-  pub(crate) outbox: Url,
-  pub(crate) public_key: PublicKey,
   pub(crate) published: DateTime<FixedOffset>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
-  #[serde(flatten)]
-  pub(crate) unparsed: Unparsed,
 }
index 20aaca181cfef1f92560efb99ee4d041bd212445..dfe502f3a27153daa06a5395af890a86f5ac4f0d 100644 (file)
@@ -17,25 +17,21 @@ pub struct Endpoints {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    context::WithContext,
-    objects::tests::file_to_json_object,
-    protocol::{
-      objects::{
-        chat_message::ChatMessage,
-        group::Group,
-        instance::Instance,
-        note::Note,
-        page::Page,
-        person::Person,
-        tombstone::Tombstone,
-      },
-      tests::test_parse_lemmy_item,
+  use crate::protocol::{
+    objects::{
+      chat_message::ChatMessage,
+      group::Group,
+      instance::Instance,
+      note::Note,
+      page::Page,
+      person::Person,
+      tombstone::Tombstone,
     },
+    tests::{test_json, test_parse_lemmy_item},
   };
 
-  #[actix_rt::test]
-  async fn test_parse_objects_lemmy() {
+  #[test]
+  fn test_parse_objects_lemmy() {
     test_parse_lemmy_item::<Instance>("assets/lemmy/objects/instance.json").unwrap();
     test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json").unwrap();
     test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json").unwrap();
@@ -45,38 +41,37 @@ mod tests {
     test_parse_lemmy_item::<Tombstone>("assets/lemmy/objects/tombstone.json").unwrap();
   }
 
-  #[actix_rt::test]
-  async fn test_parse_objects_pleroma() {
-    file_to_json_object::<WithContext<Person>>("assets/pleroma/objects/person.json").unwrap();
-    file_to_json_object::<WithContext<Note>>("assets/pleroma/objects/note.json").unwrap();
-    file_to_json_object::<WithContext<ChatMessage>>("assets/pleroma/objects/chat_message.json")
-      .unwrap();
+  #[test]
+  fn test_parse_objects_pleroma() {
+    test_json::<Person>("assets/pleroma/objects/person.json").unwrap();
+    test_json::<Note>("assets/pleroma/objects/note.json").unwrap();
+    test_json::<ChatMessage>("assets/pleroma/objects/chat_message.json").unwrap();
   }
 
-  #[actix_rt::test]
-  async fn test_parse_objects_smithereen() {
-    file_to_json_object::<WithContext<Person>>("assets/smithereen/objects/person.json").unwrap();
-    file_to_json_object::<Note>("assets/smithereen/objects/note.json").unwrap();
+  #[test]
+  fn test_parse_objects_smithereen() {
+    test_json::<Person>("assets/smithereen/objects/person.json").unwrap();
+    test_json::<Note>("assets/smithereen/objects/note.json").unwrap();
   }
 
-  #[actix_rt::test]
-  async fn test_parse_objects_mastodon() {
-    file_to_json_object::<WithContext<Person>>("assets/mastodon/objects/person.json").unwrap();
-    file_to_json_object::<WithContext<Note>>("assets/mastodon/objects/note.json").unwrap();
+  #[test]
+  fn test_parse_objects_mastodon() {
+    test_json::<Person>("assets/mastodon/objects/person.json").unwrap();
+    test_json::<Note>("assets/mastodon/objects/note.json").unwrap();
   }
 
-  #[actix_rt::test]
-  async fn test_parse_objects_lotide() {
-    file_to_json_object::<WithContext<Group>>("assets/lotide/objects/group.json").unwrap();
-    file_to_json_object::<WithContext<Person>>("assets/lotide/objects/person.json").unwrap();
-    file_to_json_object::<WithContext<Note>>("assets/lotide/objects/note.json").unwrap();
-    file_to_json_object::<WithContext<Page>>("assets/lotide/objects/page.json").unwrap();
-    file_to_json_object::<WithContext<Tombstone>>("assets/lotide/objects/tombstone.json").unwrap();
+  #[test]
+  fn test_parse_objects_lotide() {
+    test_json::<Group>("assets/lotide/objects/group.json").unwrap();
+    test_json::<Person>("assets/lotide/objects/person.json").unwrap();
+    test_json::<Note>("assets/lotide/objects/note.json").unwrap();
+    test_json::<Page>("assets/lotide/objects/page.json").unwrap();
+    test_json::<Tombstone>("assets/lotide/objects/tombstone.json").unwrap();
   }
 
-  #[actix_rt::test]
-  async fn test_parse_object_friendica() {
-    file_to_json_object::<WithContext<Person>>("assets/friendica/objects/person.json").unwrap();
-    file_to_json_object::<WithContext<Note>>("assets/friendica/objects/note.json").unwrap();
+  #[test]
+  fn test_parse_object_friendica() {
+    test_json::<Person>("assets/friendica/objects/person.json").unwrap();
+    test_json::<Note>("assets/friendica/objects/note.json").unwrap();
   }
 }
index 73e4a1304157f30a09007d622fec9817308de706..d5c61c1f8c5e1f17254c6a39c3637d4f6f25cde2 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   fetcher::post_or_comment::PostOrComment,
   mentions::Mention,
   objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
-  protocol::{Source, Unparsed},
+  protocol::Source,
 };
 use activitystreams_kinds::object::NoteType;
 use chrono::{DateTime, FixedOffset};
@@ -30,16 +30,15 @@ pub struct Note {
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   pub(crate) cc: Vec<Url>,
   pub(crate) content: String,
+  pub(crate) in_reply_to: ObjectId<PostOrComment>,
+
   pub(crate) media_type: Option<MediaTypeHtml>,
   #[serde(default)]
   pub(crate) source: SourceCompat,
-  pub(crate) in_reply_to: ObjectId<PostOrComment>,
   pub(crate) published: Option<DateTime<FixedOffset>>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
   #[serde(default)]
   pub(crate) tag: Vec<Mention>,
-  #[serde(flatten)]
-  pub(crate) unparsed: Unparsed,
 }
 
 /// Pleroma puts a raw string in the source, so we have to handle it here for deserialization to work
index 08906e757f8d34527655470645b1bd005173455c..f6a2823126debf55f8bff85a475464ec60c0db43 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
-  protocol::{ImageObject, Source, Unparsed},
+  protocol::{ImageObject, Source},
 };
 use chrono::{DateTime, FixedOffset};
 use lemmy_apub_lib::{
@@ -30,10 +30,11 @@ pub struct Page {
   pub(crate) attributed_to: ObjectId<ApubPerson>,
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   pub(crate) to: Vec<Url>,
+  pub(crate) name: String,
+
   #[serde(default)]
   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
   pub(crate) cc: Vec<Url>,
-  pub(crate) name: String,
   pub(crate) content: Option<String>,
   pub(crate) media_type: Option<MediaTypeHtml>,
   pub(crate) source: Option<Source>,
@@ -44,8 +45,6 @@ pub struct Page {
   pub(crate) stickied: Option<bool>,
   pub(crate) published: Option<DateTime<FixedOffset>>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
-  #[serde(flatten)]
-  pub(crate) unparsed: Unparsed,
 }
 
 impl Page {
index e254ed07809bef1c817eb069dbf406e0d2eb1078..0ab359dfd13c824586a5c039f968e4e8b322e447 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   objects::person::ApubPerson,
-  protocol::{objects::Endpoints, ImageObject, Source, Unparsed},
+  protocol::{objects::Endpoints, ImageObject, Source},
 };
 use chrono::{DateTime, FixedOffset};
 use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey};
@@ -21,9 +21,14 @@ pub struct Person {
   #[serde(rename = "type")]
   pub(crate) kind: UserTypes,
   pub(crate) id: ObjectId<ApubPerson>,
-  /// username, set at account creation and can never be changed
+  /// username, set at account creation and usually fixed after that
   pub(crate) preferred_username: String,
-  /// displayname (can be changed at any time)
+  pub(crate) inbox: Url,
+  /// mandatory field in activitypub, lemmy currently serves an empty outbox
+  pub(crate) outbox: Url,
+  pub(crate) public_key: PublicKey,
+
+  /// displayname
   pub(crate) name: Option<String>,
   pub(crate) summary: Option<String>,
   pub(crate) source: Option<Source>,
@@ -32,13 +37,7 @@ pub struct Person {
   /// user banner
   pub(crate) image: Option<ImageObject>,
   pub(crate) matrix_user_id: Option<String>,
-  pub(crate) inbox: Url,
-  /// mandatory field in activitypub, currently empty in lemmy
-  pub(crate) outbox: Url,
   pub(crate) endpoints: Option<Endpoints>,
-  pub(crate) public_key: PublicKey,
   pub(crate) published: Option<DateTime<FixedOffset>>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
-  #[serde(flatten)]
-  pub(crate) unparsed: Unparsed,
 }