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 {
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;
+ /// Check that json deserialize -> serialize -> deserialize gives identical file as initial one.
+ /// 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 {
- let parsed = file_to_json_object::<T>(path);
+ ) -> Result<T, LemmyError> {
+ // parse file as T
+ let parsed = file_to_json_object::<T>(path)?;
- // ensure that no field is ignored when parsing
- let raw = file_to_json_object::<HashMap<String, serde_json::Value>>(path);
+ // parse file into hashmap, which ensures that every field is included
+ 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)
}
}