+
+ let post = Post::create(&mut context.pool(), &form).await?;
+
+ // write mod log entry for lock
+ if Page::is_locked_changed(&old_post, &page.comments_enabled) {
+ let form = ModLockPostForm {
+ mod_person_id: creator.id,
+ post_id: post.id,
+ locked: Some(post.locked),
+ };
+ ModLockPost::create(&mut context.pool(), &form).await?;
+ }
+
+ Ok(post.into())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ #![allow(clippy::unwrap_used)]
+ #![allow(clippy::indexing_slicing)]
+
+ use super::*;
+ 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_db_schema::source::site::Site;
+ use serial_test::serial;
+
+ #[tokio::test]
+ #[serial]
+ async fn test_parse_lemmy_post() {
+ let context = init_context().await;
+ let (person, site) = parse_lemmy_person(&context).await;
+ let community = parse_lemmy_community(&context).await;
+
+ let json = file_to_json_object("assets/lemmy/objects/page.json").unwrap();
+ let url = Url::parse("https://enterprise.lemmy.ml/post/55143").unwrap();
+ ApubPost::verify(&json, &url, &context).await.unwrap();
+ let post = ApubPost::from_json(json, &context).await.unwrap();
+
+ assert_eq!(post.ap_id, url.into());
+ assert_eq!(post.name, "Post title");
+ assert!(post.body.is_some());
+ assert_eq!(post.body.as_ref().unwrap().len(), 45);
+ assert!(!post.locked);
+ assert!(!post.featured_community);
+ assert_eq!(context.request_count(), 0);
+
+ Post::delete(&mut context.pool(), post.id).await.unwrap();
+ Person::delete(&mut context.pool(), person.id)
+ .await
+ .unwrap();
+ Community::delete(&mut context.pool(), community.id)
+ .await
+ .unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();