diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs
index 68eb1cb27..fc02b8f37 100644
--- a/crates/apub/src/objects/comment.rs
+++ b/crates/apub/src/objects/comment.rs
@@ -319,19 +319,29 @@ mod tests {
use assert_json_diff::assert_json_include;
use serial_test::serial;
- async fn prepare_comment_test(url: &Url, context: &LemmyContext) {
+ async fn prepare_comment_test(
+ url: &Url,
+ context: &LemmyContext,
+ ) -> (ApubPerson, ApubCommunity, ApubPost) {
let person_json = file_to_json_object("assets/lemmy-person.json");
- ApubPerson::from_apub(&person_json, context, url, &mut 0)
+ let person = ApubPerson::from_apub(&person_json, context, url, &mut 0)
.await
.unwrap();
let community_json = file_to_json_object("assets/lemmy-community.json");
- ApubCommunity::from_apub(&community_json, context, url, &mut 0)
+ let community = ApubCommunity::from_apub(&community_json, context, url, &mut 0)
.await
.unwrap();
let post_json = file_to_json_object("assets/lemmy-post.json");
- ApubPost::from_apub(&post_json, context, url, &mut 0)
+ let post = ApubPost::from_apub(&post_json, context, url, &mut 0)
.await
.unwrap();
+ (person, community, post)
+ }
+
+ fn cleanup(data: (ApubPerson, ApubCommunity, ApubPost), context: &LemmyContext) {
+ Post::delete(&*context.pool().get().unwrap(), data.2.id).unwrap();
+ Community::delete(&*context.pool().get().unwrap(), data.1.id).unwrap();
+ Person::delete(&*context.pool().get().unwrap(), data.0.id).unwrap();
}
#[actix_rt::test]
@@ -339,7 +349,7 @@ mod tests {
async fn test_fetch_lemmy_comment() {
let context = init_context();
let url = Url::parse("https://lemmy.ml/comment/38741").unwrap();
- prepare_comment_test(&url, &context).await;
+ let data = prepare_comment_test(&url, &context).await;
let json = file_to_json_object("assets/lemmy-comment.json");
let mut request_counter = 0;
@@ -354,6 +364,9 @@ mod tests {
let to_apub = comment.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
+
+ Comment::delete(&*context.pool().get().unwrap(), comment.id).unwrap();
+ cleanup(data, &context);
}
#[actix_rt::test]
@@ -361,7 +374,7 @@ mod tests {
async fn test_fetch_pleroma_comment() {
let context = init_context();
let url = Url::parse("https://lemmy.ml/comment/38741").unwrap();
- prepare_comment_test(&url, &context).await;
+ let data = prepare_comment_test(&url, &context).await;
let pleroma_url =
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")
@@ -380,12 +393,15 @@ mod tests {
assert_eq!(comment.content.len(), 64);
assert!(!comment.local);
assert_eq!(request_counter, 0);
+
+ Comment::delete(&*context.pool().get().unwrap(), comment.id).unwrap();
+ cleanup(data, &context);
}
#[actix_rt::test]
#[serial]
async fn test_html_to_markdown_sanitize() {
- let parsed = parse_html(&"hello");
+ let parsed = parse_html("hello");
assert_eq!(parsed, "**hello**");
}
}
diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs
index e70a3f906..525ae854d 100644
--- a/crates/apub/src/objects/community.rs
+++ b/crates/apub/src/objects/community.rs
@@ -319,6 +319,7 @@ mod tests {
use super::*;
use crate::objects::tests::{file_to_json_object, init_context};
use assert_json_diff::assert_json_include;
+ use lemmy_db_schema::traits::Crud;
use serial_test::serial;
#[actix_rt::test]
@@ -347,5 +348,7 @@ mod tests {
let to_apub = community.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json_orig, expected: to_apub);
+
+ Community::delete(&*context.pool().get().unwrap(), community.id).unwrap();
}
}
diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs
index 7f7c340c7..7d5b99234 100644
--- a/crates/apub/src/objects/person.rs
+++ b/crates/apub/src/objects/person.rs
@@ -272,6 +272,7 @@ mod tests {
use super::*;
use crate::objects::tests::{file_to_json_object, init_context};
use assert_json_diff::assert_json_include;
+ use lemmy_db_schema::traits::Crud;
use serial_test::serial;
#[actix_rt::test]
@@ -294,15 +295,18 @@ mod tests {
let to_apub = person.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
+
+ DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
}
#[actix_rt::test]
#[serial]
async fn test_fetch_pleroma_person() {
+ let context = init_context();
let json = file_to_json_object("assets/pleroma-person.json");
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
let mut request_counter = 0;
- let person = ApubPerson::from_apub(&json, &init_context(), &url, &mut request_counter)
+ let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter)
.await
.unwrap();
@@ -313,5 +317,7 @@ mod tests {
assert_eq!(request_counter, 0);
// TODO: pleroma uses summary for user profile, while we use content
//assert!(person.bio.is_some());
+
+ DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
}
}
diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs
index 47d4859fb..47b4b99a9 100644
--- a/crates/apub/src/objects/post.rs
+++ b/crates/apub/src/objects/post.rs
@@ -294,11 +294,11 @@ mod tests {
let context = init_context();
let url = Url::parse("https://lemmy.ml/post/55143").unwrap();
let community_json = file_to_json_object("assets/lemmy-community.json");
- ApubCommunity::from_apub(&community_json, &context, &url, &mut 0)
+ let community = ApubCommunity::from_apub(&community_json, &context, &url, &mut 0)
.await
.unwrap();
let person_json = file_to_json_object("assets/lemmy-person.json");
- ApubPerson::from_apub(&person_json, &context, &url, &mut 0)
+ let person = ApubPerson::from_apub(&person_json, &context, &url, &mut 0)
.await
.unwrap();
let json = file_to_json_object("assets/lemmy-post.json");
@@ -317,5 +317,9 @@ mod tests {
let to_apub = post.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
+
+ Post::delete(&*context.pool().get().unwrap(), post.id).unwrap();
+ Person::delete(&*context.pool().get().unwrap(), person.id).unwrap();
+ Community::delete(&*context.pool().get().unwrap(), community.id).unwrap();
}
}
diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs
index 41e940b03..cf622eccb 100644
--- a/crates/apub/src/objects/private_message.rs
+++ b/crates/apub/src/objects/private_message.rs
@@ -213,12 +213,12 @@ mod tests {
let context = init_context();
let url = Url::parse("https://lemmy.ml/private_message/1621").unwrap();
let lemmy_person = file_to_json_object("assets/lemmy-person.json");
- ApubPerson::from_apub(&lemmy_person, &context, &url, &mut 0)
+ let person1 = ApubPerson::from_apub(&lemmy_person, &context, &url, &mut 0)
.await
.unwrap();
let pleroma_person = file_to_json_object("assets/pleroma-person.json");
let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
- ApubPerson::from_apub(&pleroma_person, &context, &pleroma_url, &mut 0)
+ let person2 = ApubPerson::from_apub(&pleroma_person, &context, &pleroma_url, &mut 0)
.await
.unwrap();
let json = file_to_json_object("assets/lemmy-private-message.json");
@@ -233,5 +233,9 @@ mod tests {
let to_apub = pm.to_apub(context.pool()).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
+
+ PrivateMessage::delete(&*context.pool().get().unwrap(), pm.id).unwrap();
+ Person::delete(&*context.pool().get().unwrap(), person1.id).unwrap();
+ Person::delete(&*context.pool().get().unwrap(), person2.id).unwrap();
}
}
diff --git a/crates/db_schema/src/impls/private_message.rs b/crates/db_schema/src/impls/private_message.rs
index 735c775e0..6a2e9ee84 100644
--- a/crates/db_schema/src/impls/private_message.rs
+++ b/crates/db_schema/src/impls/private_message.rs
@@ -33,6 +33,10 @@ impl Crud for PrivateMessage {
.set(private_message_form)
.get_result::(conn)
}
+ fn delete(conn: &PgConnection, pm_id: Self::IdType) -> Result {
+ use crate::schema::private_message::dsl::*;
+ diesel::delete(private_message.find(pm_id)).execute(conn)
+ }
}
impl PrivateMessage {