WIP: Create apub_inbox
crate #8
2 changed files with 102 additions and 4 deletions
|
@ -25,6 +25,7 @@ pub trait StreamsObject {
|
||||||
pub trait StreamsLink {
|
pub trait StreamsLink {
|
||||||
fn streams_href(&self) -> Option<AResult<String>>;
|
fn streams_href(&self) -> Option<AResult<String>>;
|
||||||
|
|
||||||
|
// FIXME: This accepts any kind of string, and does not filter to HTML link relations
|
||||||
fn streams_rel(&self) -> impl Iterator<Item = AResult<String>>;
|
fn streams_rel(&self) -> impl Iterator<Item = AResult<String>>;
|
||||||
|
|
||||||
fn streams_media_type(&self) -> Option<AResult<MediaType>>;
|
fn streams_media_type(&self) -> Option<AResult<MediaType>>;
|
||||||
|
|
|
@ -1,11 +1,44 @@
|
||||||
|
use acrate_astreams::activitystreams::StreamsLink;
|
||||||
|
|
||||||
macro_rules! test_example {
|
macro_rules! test_example {
|
||||||
($modname:ident, $filename:literal) => {
|
($modname:ident, $filename:literal) => {
|
||||||
mod $modname {
|
mod $modname {
|
||||||
const DATA: &'static str = include_str!($filename);
|
use json_ld::syntax::Parse;
|
||||||
|
use json_ld::Expand;
|
||||||
|
|
||||||
#[test]
|
pub const DATA: &'static str = include_str!($filename);
|
||||||
fn test_example_exists() {
|
|
||||||
assert_ne!(DATA.len(), 0)
|
pub fn parse() -> json_ld::syntax::Value {
|
||||||
|
let (value, _codemap) = json_ld::syntax::Value::parse_str(DATA)
|
||||||
|
.expect("Failed to parse example");
|
||||||
|
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn document() -> json_ld::RemoteDocument {
|
||||||
|
let document = json_ld::RemoteDocument::new(
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
parse(),
|
||||||
|
);
|
||||||
|
|
||||||
|
document
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn expand() -> json_ld::ExpandedDocument {
|
||||||
|
let mut loader = json_ld::ReqwestLoader::new();
|
||||||
|
let doc = document();
|
||||||
|
let expanded = doc.expand(&mut loader)
|
||||||
|
.await
|
||||||
|
.expect("Failed to expand JSON-LD document");
|
||||||
|
|
||||||
|
expanded
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_expand() {
|
||||||
|
let doc = expand().await;
|
||||||
|
println!("{doc:#?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,3 +203,67 @@ test_example!(e156, "./activitystreams/examples/156.json");
|
||||||
test_example!(e157, "./activitystreams/examples/157.json");
|
test_example!(e157, "./activitystreams/examples/157.json");
|
||||||
test_example!(e158, "./activitystreams/examples/158.json");
|
test_example!(e158, "./activitystreams/examples/158.json");
|
||||||
test_example!(e159, "./activitystreams/examples/159.json");
|
test_example!(e159, "./activitystreams/examples/159.json");
|
||||||
|
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_link_href() {
|
||||||
|
let doc = e121::expand().await;
|
||||||
|
|
||||||
|
let node = doc.main_node()
|
||||||
|
.expect("Main node was not found");
|
||||||
|
|
||||||
|
let href = {
|
||||||
|
use acrate_astreams::activitystreams::StreamsLink;
|
||||||
|
|
||||||
|
node.streams_href()
|
||||||
|
.expect("Property `href` was not found")
|
||||||
|
.expect("Property `href` failed to process")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(href, "http://example.org/abc");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_link_rel() {
|
||||||
|
let doc = e131::expand().await;
|
||||||
|
|
||||||
|
let node = doc.main_node()
|
||||||
|
.expect("Main node was not found");
|
||||||
|
|
||||||
|
let mut rels = {
|
||||||
|
use acrate_astreams::activitystreams::StreamsLink;
|
||||||
|
|
||||||
|
node.streams_rel()
|
||||||
|
.map(|v| v
|
||||||
|
.expect("Property `rel` failed to process")
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let rel = rels.next()
|
||||||
|
.expect("Expected `rel` [0] to be present");
|
||||||
|
|
||||||
|
assert_eq!(rel, "canonical");
|
||||||
|
|
||||||
|
let rel = rels.next()
|
||||||
|
.expect("Expected `rel` [1] to be present");
|
||||||
|
|
||||||
|
assert_eq!(rel, "preview");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_link_media_type() {
|
||||||
|
let doc = e126::expand().await;
|
||||||
|
|
||||||
|
let node = doc.main_node()
|
||||||
|
.expect("Main node was not found");
|
||||||
|
|
||||||
|
let href = {
|
||||||
|
use acrate_astreams::activitystreams::StreamsLink;
|
||||||
|
|
||||||
|
node.streams_media_type()
|
||||||
|
.expect("Property `mediaType` was not found")
|
||||||
|
.expect("Property `mediaType` failed to process")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert_eq!(href, mediatype::media_type!(TEXT/HTML));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue