]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/protocol/mod.rs
Implement instance actor (#1798)
[lemmy.git] / crates / apub / src / protocol / mod.rs
index a7a233964c1023258a4330cea31a18c03d4ce3a7..d1532a9523ae7f4d3b606cdcf6f0c79680b20c6c 100644 (file)
@@ -17,6 +17,15 @@ pub struct Source {
   pub(crate) media_type: MediaTypeMarkdown,
 }
 
+impl Source {
+  pub(crate) fn new(content: String) -> Self {
+    Source {
+      content,
+      media_type: MediaTypeMarkdown::Markdown,
+    }
+  }
+}
+
 #[derive(Clone, Debug, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct ImageObject {
@@ -42,6 +51,7 @@ pub struct Unparsed(HashMap<String, serde_json::Value>);
 pub(crate) mod tests {
   use crate::objects::tests::file_to_json_object;
   use assert_json_diff::assert_json_include;
+  use lemmy_utils::LemmyError;
   use serde::{de::DeserializeOwned, Serialize};
   use std::collections::HashMap;
 
@@ -49,14 +59,14 @@ pub(crate) mod tests {
   /// Ensures that there are no breaking changes in sent data.
   pub(crate) fn test_parse_lemmy_item<T: Serialize + DeserializeOwned + std::fmt::Debug>(
     path: &str,
-  ) -> T {
+  ) -> Result<T, LemmyError> {
     // parse file as T
-    let parsed = file_to_json_object::<T>(path).unwrap();
+    let parsed = file_to_json_object::<T>(path)?;
 
     // parse file into hashmap, which ensures that every field is included
-    let raw = file_to_json_object::<HashMap<String, serde_json::Value>>(path).unwrap();
+    let raw = file_to_json_object::<HashMap<String, serde_json::Value>>(path)?;
     // assert that all fields are identical, otherwise print diff
     assert_json_include!(actual: &parsed, expected: raw);
-    parsed
+    Ok(parsed)
   }
 }