From: Dessalines Date: Thu, 3 Mar 2022 17:51:55 +0000 (-0500) Subject: Fixing unit tests. X-Git-Url: http://these/git/%7B%24%7B%60data:application/%22%7Burl%7D/%7Bthis.state.url%7D?a=commitdiff_plain;h=a5433ebf77e490799be6c7e4004471ccaf4b2b46;p=lemmy.git Fixing unit tests. --- diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 329767fd..b1d5e5b1 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -159,15 +159,24 @@ impl ApubObject for ApubPrivateMessage { mod tests { use super::*; use crate::{ - objects::{person::ApubPerson, tests::init_context}, + objects::{ + instance::{tests::parse_lemmy_instance, ApubSite}, + person::ApubPerson, + tests::init_context, + }, protocol::tests::file_to_json_object, }; use assert_json_diff::assert_json_include; use lemmy_apub_lib::activity_queue::create_activity_queue; + use lemmy_db_schema::source::site::Site; use serial_test::serial; - async fn prepare_comment_test(url: &Url, context: &LemmyContext) -> (ApubPerson, ApubPerson) { + async fn prepare_comment_test( + url: &Url, + context: &LemmyContext, + ) -> (ApubPerson, ApubPerson, ApubSite) { let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json").unwrap(); + let site = parse_lemmy_instance(context).await; ApubPerson::verify(&lemmy_person, url, context, &mut 0) .await .unwrap(); @@ -182,12 +191,13 @@ mod tests { let person2 = ApubPerson::from_apub(pleroma_person, context, &mut 0) .await .unwrap(); - (person1, person2) + (person1, person2, site) } - fn cleanup(data: (ApubPerson, ApubPerson), context: &LemmyContext) { + fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &LemmyContext) { Person::delete(&*context.pool().get().unwrap(), data.0.id).unwrap(); Person::delete(&*context.pool().get().unwrap(), data.1.id).unwrap(); + Site::delete(&*context.pool().get().unwrap(), data.2.id).unwrap(); } #[actix_rt::test] diff --git a/crates/db_schema/src/aggregates/site_aggregates.rs b/crates/db_schema/src/aggregates/site_aggregates.rs index 58dfe0b0..745097df 100644 --- a/crates/db_schema/src/aggregates/site_aggregates.rs +++ b/crates/db_schema/src/aggregates/site_aggregates.rs @@ -58,7 +58,7 @@ mod tests { ..Default::default() }; - Site::create(&conn, &site_form).unwrap(); + let inserted_site = Site::create(&conn, &site_form).unwrap(); let new_community = CommunityForm { name: "TIL_site_agg".into(), @@ -124,8 +124,7 @@ mod tests { let after_delete_creator = SiteAggregates::read(&conn); assert!(after_delete_creator.is_ok()); - let site_id = after_delete_creator.unwrap().id; - Site::delete(&conn, site_id).unwrap(); + Site::delete(&conn, inserted_site.id).unwrap(); let after_delete_site = SiteAggregates::read(&conn); assert!(after_delete_site.is_err()); }