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,
21 pub(crate) fn new(content: String) -> Self {
24 media_type: MediaTypeMarkdown::Markdown,
29 #[derive(Clone, Debug, Deserialize, Serialize)]
30 #[serde(rename_all = "camelCase")]
31 pub struct ImageObject {
32 #[serde(rename = "type")]
38 pub(crate) fn new(url: DbUrl) -> Self {
40 kind: ImageType::Image,
46 #[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
48 pub struct Unparsed(HashMap<String, serde_json::Value>);
51 pub(crate) mod tests {
52 use crate::objects::tests::file_to_json_object;
53 use assert_json_diff::assert_json_include;
54 use lemmy_utils::LemmyError;
55 use serde::{de::DeserializeOwned, Serialize};
56 use std::collections::HashMap;
58 /// Check that json deserialize -> serialize -> deserialize gives identical file as initial one.
59 /// Ensures that there are no breaking changes in sent data.
60 pub(crate) fn test_parse_lemmy_item<T: Serialize + DeserializeOwned + std::fmt::Debug>(
62 ) -> Result<T, LemmyError> {
64 let parsed = file_to_json_object::<T>(path)?;
66 // parse file into hashmap, which ensures that every field is included
67 let raw = file_to_json_object::<HashMap<String, serde_json::Value>>(path)?;
68 // assert that all fields are identical, otherwise print diff
69 assert_json_include!(actual: &parsed, expected: raw);