aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream/actor.rs
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2024-01-14 10:20:11 +0100
committerHarald Eilertsen <haraldei@anduin.net>2024-01-14 10:20:11 +0100
commit45962918683290be0a0ed9091d23f86f20a6d33e (patch)
treef7ab332265153a6f5154a7f5e3408381dd553a44 /src/stream/actor.rs
parent04b1504e8715ee6acf498a4261775f3b9d6d6daa (diff)
downloadrust-zotapi-45962918683290be0a0ed9091d23f86f20a6d33e.tar.gz
rust-zotapi-45962918683290be0a0ed9091d23f86f20a6d33e.tar.bz2
rust-zotapi-45962918683290be0a0ed9091d23f86f20a6d33e.zip
Additional stream tag types and flags + optional fields.
Diffstat (limited to 'src/stream/actor.rs')
-rw-r--r--src/stream/actor.rs53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/stream/actor.rs b/src/stream/actor.rs
index 88090cf..4e2bbe4 100644
--- a/src/stream/actor.rs
+++ b/src/stream/actor.rs
@@ -13,8 +13,8 @@ use url::Url;
#[derive(Debug, Deserialize, PartialEq)]
pub struct Actor {
name: String,
- address: String,
- url: Url,
+ address: Option<String>,
+ url: Option<Url>,
id: String,
id_sig: String,
key: String,
@@ -44,8 +44,53 @@ mod test {
let actor: Actor = serde_json::from_str(&json).unwrap();
assert_eq!("Benjamin Franklin", actor.name);
- assert_eq!("ben@example.com", actor.address);
- assert_eq!("https://example.com/channel/ben", actor.url.to_string());
+ assert_eq!("ben@example.com", &actor.address.unwrap());
+ assert_eq!("https://example.com/channel/ben", actor.url.unwrap().to_string());
assert_eq!("rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA", actor.id);
}
+
+ #[test]
+ fn test_parsing_actor_without_address_from_json() {
+ let json = r#"
+ {
+ "name": "Benjamin Franklin",
+ "url": "https://example.com/channel/ben",
+ "network": "zot6",
+ "photo": {
+ "mimetype": "image/jpeg",
+ "src": "https://example.com/photo/profile/m/2"
+ },
+ "id": "rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA",
+ "id_sig": "sha256.ZD8uwYmUEG_d02Y...",
+ "key": "-----BEGIN PUBLIC KEY-----\n....\n-----END PUBLIC KEY-----\n"
+ }"#;
+
+ let actor: Actor = serde_json::from_str(&json).unwrap();
+
+ assert_eq!("Benjamin Franklin", actor.name);
+ assert_eq!(None, actor.address);
+ assert_eq!("https://example.com/channel/ben", actor.url.unwrap().to_string());
+ assert_eq!("rUpgk2qbvnWLoKIXOlZlwlqI5vk8C4NgudFNjbcmnOBjFSXU34TObkZEClaPSfKnpFZpg87tANtko7WGs7QRvA", actor.id);
+ }
+
+ #[test]
+ fn test_parsing_actor_without_url_from_json() {
+ let json = r#"
+ {
+ "name":"Diaspora User",
+ "address":"someone@diaspora.example.com",
+ "network":"diaspora",
+ "photo":{"mimetype":"image\/jpeg", "src":"https:\/\/example.com\/photo\/c992335849828915b5c963b985f68f46-5"},
+ "id":"349ab82134669a3b",
+ "id_sig":"",
+ "key":"-----BEGIN PUBLIC KEY-----\n\n-----END PUBLIC KEY-----\n"
+ }
+ "#;
+
+ let actor: Actor = serde_json::from_str(&json).unwrap();
+
+ assert_eq!("Diaspora User", actor.name);
+ assert_eq!("someone@diaspora.example.com", actor.address.unwrap());
+ assert_eq!(None, actor.url);
+ }
}