1 use activitystreams_kinds::object::ImageType;
2 use serde::{Deserialize, Serialize};
5 use lemmy_apub_lib::values::MediaTypeMarkdown;
6 use lemmy_db_schema::newtypes::DbUrl;
7 use std::collections::HashMap;
10 pub(crate) mod collections;
11 pub(crate) mod objects;
13 #[derive(Clone, Debug, Deserialize, Serialize)]
14 #[serde(rename_all = "camelCase")]
16 pub(crate) content: String,
17 pub(crate) media_type: MediaTypeMarkdown,
20 #[derive(Clone, Debug, Deserialize, Serialize)]
21 #[serde(rename_all = "camelCase")]
22 pub struct ImageObject {
23 #[serde(rename = "type")]
29 pub(crate) fn new(url: DbUrl) -> Self {
31 kind: ImageType::Image,
37 #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
39 pub struct Unparsed(HashMap<String, serde_json::Value>);
42 pub(crate) mod tests {
43 use crate::objects::tests::file_to_json_object;
44 use assert_json_diff::assert_json_include;
45 use lemmy_utils::LemmyError;
46 use serde::{de::DeserializeOwned, Serialize};
47 use std::collections::HashMap;
49 /// Check that json deserialize -> serialize -> deserialize gives identical file as initial one.
50 /// Ensures that there are no breaking changes in sent data.
51 pub(crate) fn test_parse_lemmy_item<T: Serialize + DeserializeOwned + std::fmt::Debug>(
53 ) -> Result<T, LemmyError> {
55 let parsed = file_to_json_object::<T>(path)?;
57 // parse file into hashmap, which ensures that every field is included
58 let raw = file_to_json_object::<HashMap<String, serde_json::Value>>(path)?;
59 // assert that all fields are identical, otherwise print diff
60 assert_json_include!(actual: &parsed, expected: raw);