diff --git a/apb/src/node.rs b/apb/src/node.rs index 0ff4eb65..7b8c9414 100644 --- a/apb/src/node.rs +++ b/apb/src/node.rs @@ -113,7 +113,7 @@ impl Node { Node::Empty => vec![], Node::Link(uri) => vec![uri.href().to_string()], Node::Object(x) => x.id().map_or(vec![], |x| vec![x.to_string()]), - Node::Array(x) => x.iter().filter_map(|x| x.id().ok()).map(|x| x.to_string()).collect() + Node::Array(x) => x.iter().filter_map(|x| Some(x.id().ok()?.to_string())).collect() } } diff --git a/apb/src/target.rs b/apb/src/target.rs index 7d414751..f130dd3c 100644 --- a/apb/src/target.rs +++ b/apb/src/target.rs @@ -43,3 +43,34 @@ impl Addressed for T { // to // } } + +#[cfg(test)] +mod test { + use super::Addressed; + + #[test] + #[cfg(feature = "unstructured")] + fn addressed_trait_finds_all_targets_on_json_objects() { + let obj = serde_json::json!({ + "id": "http://localhost:8080/obj/1", + "type": "Note", + "content": "hello world!", + "published": "2024-06-04T17:09:20+00:00", + "to": ["http://localhost:8080/usr/root/followers"], + "bto": ["https://localhost:8080/usr/secret"], + "cc": [crate::target::PUBLIC], + "bcc": [], + }); + + let addressed = obj.addressed(); + + assert_eq!( + addressed, + vec![ + "http://localhost:8080/usr/root/followers".to_string(), + "https://localhost:8080/usr/secret".to_string(), + crate::target::PUBLIC.to_string(), + ] + ); + } +}