- let body_slurs_removed = page.source.as_ref().map(|s| remove_slurs(&s.content));
- let form = PostForm {
- name: page.name.clone(),
- url: page.url.clone().map(|u| u.into()),
- body: body_slurs_removed,
- creator_id: creator.id,
- community_id: community.id,
- removed: None,
- locked: page.comments_enabled.map(|e| !e),
- published: Some(page.published.naive_local()),
- updated: page.updated.map(|u| u.naive_local()),
- deleted: None,
- nsfw: page.sensitive,
- stickied: page.stickied,
- embed_title: iframely_title,
- embed_description: iframely_description,
- embed_html: iframely_html,
- thumbnail_url: pictrs_thumbnail.map(|u| u.into()),
- ap_id: Some(page.id.clone().into()),
- local: Some(false),
- };
- Ok(blocking(context.pool(), move |conn| Post::upsert(conn, &form)).await??)
+ #[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();