diff --git a/src/data/actor.rs b/src/data/actor.rs index 6d2d65a..31cb927 100644 --- a/src/data/actor.rs +++ b/src/data/actor.rs @@ -57,13 +57,11 @@ impl ActorCache { } pub(crate) async fn add_connection(&self, actor: Actor) -> Result<(), MyError> { - log::debug!("Adding connection: {}", actor.id); self.db.add_connection(actor.id.clone()).await?; self.db.save_actor(actor).await } pub(crate) async fn remove_connection(&self, actor: &Actor) -> Result<(), MyError> { - log::debug!("Removing connection: {}", actor.id); self.db.remove_connection(actor.id.clone()).await } diff --git a/src/db.rs b/src/db.rs index 3ce0fce..2693ced 100644 --- a/src/db.rs +++ b/src/db.rs @@ -485,6 +485,7 @@ impl Db { } pub(crate) async fn remove_connection(&self, actor_id: Url) -> Result<(), MyError> { + log::debug!("Removing Connection: {}", actor_id); self.unblock(move |inner| { inner .connected_actor_ids @@ -496,6 +497,7 @@ impl Db { } pub(crate) async fn add_connection(&self, actor_id: Url) -> Result<(), MyError> { + log::debug!("Adding Connection: {}", actor_id); self.unblock(move |inner| { inner .connected_actor_ids @@ -648,6 +650,40 @@ mod tests { }) } + #[test] + fn disconnect_and_verify() { + run(|db| async move { + let example_actor: Url = "http://example.com/actor".parse().unwrap(); + let example_sub_actor: Url = "http://example.com/users/fake".parse().unwrap(); + db.add_connection(example_actor.clone()).await.unwrap(); + assert!(db.is_connected(example_sub_actor.clone()).await.unwrap()); + + db.remove_connection(example_actor).await.unwrap(); + assert!(!db.is_connected(example_sub_actor).await.unwrap()); + }) + } + + #[test] + fn connected_actor_in_connected_list() { + run(|db| async move { + let example_actor: Url = "http://example.com/actor".parse().unwrap(); + db.add_connection(example_actor.clone()).await.unwrap(); + + assert!(db.connected_ids().await.unwrap().contains(&example_actor)); + }) + } + + #[test] + fn disconnected_actor_not_in_connected_list() { + run(|db| async move { + let example_actor: Url = "http://example.com/actor".parse().unwrap(); + db.add_connection(example_actor.clone()).await.unwrap(); + db.remove_connection(example_actor.clone()).await.unwrap(); + + assert!(!db.connected_ids().await.unwrap().contains(&example_actor)); + }) + } + fn run(f: F) where F: Fn(Db) -> Fut,