From 2739ebe3c3c45b803dd48bc2401857996693e683 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 10 Apr 2024 11:03:29 +0200 Subject: [PATCH] add test --- examples/live_federation/objects/post.rs | 12 ++++++++--- src/config.rs | 26 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/examples/live_federation/objects/post.rs b/examples/live_federation/objects/post.rs index 9a08b9d..1b19fac 100644 --- a/examples/live_federation/objects/post.rs +++ b/examples/live_federation/objects/post.rs @@ -21,7 +21,6 @@ pub struct DbPost { pub text: String, pub ap_id: ObjectId, pub creator: ObjectId, - pub local: bool, } #[derive(Deserialize, Serialize, Debug)] @@ -59,7 +58,15 @@ impl Object for DbPost { } async fn into_json(self, _data: &Data) -> Result { - unimplemented!() + Ok(Note { + kind: NoteType::Note, + id: self.ap_id, + content: self.text, + attributed_to: self.creator, + to: vec![public()], + tag: vec![], + in_reply_to: None, + }) } async fn verify( @@ -81,7 +88,6 @@ impl Object for DbPost { text: json.content, ap_id: json.id.clone(), creator: json.attributed_to.clone(), - local: false, }; let mention = Mention { diff --git a/src/config.rs b/src/config.rs index 82092e4..6142cfd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -343,20 +343,28 @@ impl FederationMiddleware { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { - #[tokio::test] - async fn test_url_is_local() -> Result<(), Error> { - let config = FederationConfig::builder() + use super::*; + + async fn config() -> FederationConfig { + FederationConfig::builder() .domain("example.com") .app_data(1) .build() .await - .unwrap(); - assert_eq!( - true, - config.is_local_url(&Url::parse("http://example.com")?) - ); - assert_eq!(false, config.is_local_url(&Url::parse("http://other.com")?)); + .unwrap() + } + #[tokio::test] + async fn test_url_is_local() -> Result<(), Error> { + let config = config().await; + assert!(config.is_local_url(&Url::parse("http://example.com")?)); + assert!(!config.is_local_url(&Url::parse("http://other.com")?)); Ok(()) } + #[tokio::test] + async fn test_get_domain() { + let config = config().await; + assert_eq!("example.com", config.domain()); + } }