forked from alemi/upub
test(apb): make sure .addressed() works
This commit is contained in:
parent
a6015a32ed
commit
d8feeec26f
2 changed files with 32 additions and 1 deletions
|
@ -113,7 +113,7 @@ impl<T : super::Base> Node<T> {
|
||||||
Node::Empty => vec![],
|
Node::Empty => vec![],
|
||||||
Node::Link(uri) => vec![uri.href().to_string()],
|
Node::Link(uri) => vec![uri.href().to_string()],
|
||||||
Node::Object(x) => x.id().map_or(vec![], |x| vec![x.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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,3 +43,34 @@ impl<T: Object> Addressed for T {
|
||||||
// to
|
// 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(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue